1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 }