View Javadoc
1   /*
2    * Copyright (C) 2015 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 java.nio.file.attribute.FileTime;
25  
26  import org.joda.time.DateTime;
27  import org.testng.annotations.Test;
28  
29  import de.javanarior.vo.types.helper.FileTimeValue;
30  import de.javanarior.vo.types.helper.OtherFileTimeValue;
31  
32  @Test
33  public class FileTimeWrapperTest {
34  
35      private static final FileTime ONE_VALUE = FileTime.fromMillis(new DateTime("2014-10-20").getMillis());
36      private static final FileTimeValue ONE = new FileTimeValue(FileTime.fromMillis(
37                      new DateTime("2014-10-20").getMillis()));
38      private static final FileTimeValue TWO = new FileTimeValue(FileTime.fromMillis(
39                      new DateTime("2014-10-21").getMillis()));
40      private static final FileTimeValue ANOTHER_ONE = new FileTimeValue(FileTime.fromMillis(
41                      new DateTime("2014-10-20").getMillis()));
42      private static final OtherFileTimeValue OTHER_TYPE_ONE = new OtherFileTimeValue(FileTime.fromMillis(
43                      new DateTime("2014-10-20").getMillis()));
44  
45      public void testJodaDateTimeWrapperNullArgument() {
46          try {
47              new FileTimeValue(null);
48              fail("Null should not be allowed as value.");
49          } catch (IllegalArgumentException exception) {
50              assertNotNull(exception.getMessage());
51              assertFalse(exception.getMessage().isEmpty());
52          }
53      }
54  
55      public void testEqualsForDifferentTypes() {
56          assertFalse(ONE.equals(OTHER_TYPE_ONE));
57          assertFalse(OTHER_TYPE_ONE.equals(ONE));
58      }
59  
60      public void testAsString() {
61          assertEquals(ONE.asString(), ONE_VALUE.toString());
62          assertEquals(ONE_VALUE.toString(), ONE.asString());
63      }
64  
65      public void testCompareTo() {
66          assertEquals(ONE.compareTo(ANOTHER_ONE), 0);
67          assertTrue(ONE.compareTo(TWO) < 0);
68          assertTrue(TWO.compareTo(ONE) > 0);
69      }
70  
71      public void testGetValue() {
72          assertEquals(ONE.getValue(), ONE_VALUE);
73      }
74  
75  }