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.LocalDate;
25  import org.testng.annotations.Test;
26  
27  import de.javanarior.vo.types.helper.JodaLocalDateValue;
28  import de.javanarior.vo.types.helper.OtherJodaLocalDateValue;
29  
30  @Test
31  public class JodaLocalDateWrapperTest {
32  
33      private static final LocalDate ONE_VALUE = new LocalDate("2014-10-20");
34      private static final JodaLocalDateValue ONE = new JodaLocalDateValue(new LocalDate("2014-10-20"));
35      private static final JodaLocalDateValue TWO = new JodaLocalDateValue(new LocalDate("2014-10-21"));
36      private static final JodaLocalDateValue ANOTHER_ONE = new JodaLocalDateValue(new LocalDate("2014-10-20"));
37      private static final OtherJodaLocalDateValue OTHER_TYPE_ONE = new OtherJodaLocalDateValue(new LocalDate("2014-10-20"));
38  
39      public void testJodaDateTimeWrapperNullArgument() {
40          try {
41              new JodaLocalDateValue(null);
42              fail("Null should not be allowed as value.");
43          } catch (IllegalArgumentException exception) {
44              assertNotNull(exception.getMessage());
45              assertFalse(exception.getMessage().isEmpty());
46          }
47      }
48  
49      public void testEqualsForDifferentTypes() {
50          assertFalse(ONE.equals(OTHER_TYPE_ONE));
51          assertFalse(OTHER_TYPE_ONE.equals(ONE));
52      }
53  
54      public void testAsString() {
55          assertEquals(ONE.asString(), ONE_VALUE.toString());
56          assertEquals(ONE_VALUE.toString(), ONE.asString());
57      }
58  
59      public void testCompareTo() {
60          assertEquals(ONE.compareTo(ANOTHER_ONE), 0);
61          assertTrue(ONE.compareTo(TWO) < 0);
62          assertTrue(TWO.compareTo(ONE) > 0);
63      }
64  
65      public void testGetValue() {
66          assertEquals(ONE.getValue(), ONE_VALUE);
67      }
68  
69  }