View Javadoc
1   /*
2    * Copyright (C) 2014 Sven von Pluto - javanarior (a) gmail dot com
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package de.javanarior.vo.types;
17  
18  import static org.testng.Assert.assertEquals;
19  import static org.testng.Assert.assertFalse;
20  import static org.testng.Assert.assertNotNull;
21  import static org.testng.Assert.assertTrue;
22  import static org.testng.Assert.fail;
23  
24  import org.joda.time.LocalDateTime;
25  import org.testng.annotations.Test;
26  
27  import de.javanarior.vo.types.helper.JodaLocalDateTimeValue;
28  import de.javanarior.vo.types.helper.OtherJodaLocalDateTimeValue;
29  
30  @Test
31  public class JodaLocalDateTimeWrapperTest {
32  
33      private static final LocalDateTime ONE_VALUE = new LocalDateTime("2014-10-20T12:13:14");
34      private static final JodaLocalDateTimeValue ONE = new JodaLocalDateTimeValue(new LocalDateTime(
35                      "2014-10-20T12:13:14"));
36      private static final JodaLocalDateTimeValue TWO = new JodaLocalDateTimeValue(new LocalDateTime(
37                      "2014-10-20T14:13:12"));
38      private static final JodaLocalDateTimeValue ANOTHER_ONE = new JodaLocalDateTimeValue(new LocalDateTime(
39                      "2014-10-20T12:13:14"));
40      private static final OtherJodaLocalDateTimeValue OTHER_TYPE_ONE = new OtherJodaLocalDateTimeValue(
41                      new LocalDateTime("2014-10-20T12:13:14"));
42  
43      public void testJodaDateTimeWrapperNullArgument() {
44          try {
45              new JodaLocalDateTimeValue(null);
46              fail("Null should not be allowed as value.");
47          } catch (IllegalArgumentException exception) {
48              assertNotNull(exception.getMessage());
49              assertFalse(exception.getMessage().isEmpty());
50          }
51      }
52  
53      public void testEqualsForDifferentTypes() {
54          assertFalse(ONE.equals(OTHER_TYPE_ONE));
55          assertFalse(OTHER_TYPE_ONE.equals(ONE));
56      }
57  
58      public void testAsString() {
59          assertEquals(ONE.asString(), ONE_VALUE.toString());
60          assertEquals(ONE_VALUE.toString(), ONE.asString());
61      }
62  
63      public void testCompareTo() {
64          assertEquals(ONE.compareTo(ANOTHER_ONE), 0);
65          assertTrue(ONE.compareTo(TWO) < 0);
66          assertTrue(TWO.compareTo(ONE) > 0);
67      }
68  
69      public void testGetValue() {
70          assertEquals(ONE.getValue(), ONE_VALUE);
71      }
72  
73  }