74 75 /** 76 * Test offset clock. 77 */ 78 @Test 79 public class TCKClock_Offset extends AbstractTCKTest { 80 81 private static final ZoneId MOSCOW = ZoneId.of("Europe/Moscow"); 82 private static final ZoneId PARIS = ZoneId.of("Europe/Paris"); 83 private static final Instant INSTANT = LocalDateTime.of(2008, 6, 30, 11, 30, 10, 500).atZone(ZoneOffset.ofHours(2)).toInstant(); 84 private static final Duration OFFSET = Duration.ofSeconds(2); 85 86 //----------------------------------------------------------------------- 87 public void test_isSerializable() throws IOException, ClassNotFoundException { 88 assertSerializable(Clock.offset(Clock.system(PARIS), OFFSET)); 89 } 90 91 //----------------------------------------------------------------------- 92 public void test_offset_ClockDuration() { 93 Clock test = Clock.offset(Clock.fixed(INSTANT, PARIS), OFFSET); 94 System.out.println(test.instant()); 95 System.out.println(INSTANT.plus(OFFSET)); 96 assertEquals(test.instant(), INSTANT.plus(OFFSET)); 97 assertEquals(test.getZone(), PARIS); 98 } 99 100 public void test_offset_ClockDuration_zeroDuration() { 101 Clock underlying = Clock.system(PARIS); 102 Clock test = Clock.offset(underlying, Duration.ZERO); 103 assertSame(test, underlying); // spec says same 104 } 105 106 @Test(expectedExceptions = NullPointerException.class) 107 public void test_offset_ClockDuration_nullClock() { 108 Clock.offset(null, Duration.ZERO); 109 } 110 111 @Test(expectedExceptions = NullPointerException.class) 112 public void test_offset_ClockDuration_nullDuration() { 113 Clock.offset(Clock.systemUTC(), null); 114 } 115 148 assertEquals(a.equals(d), false); 149 150 assertEquals(a.equals(null), false); 151 assertEquals(a.equals("other type"), false); 152 assertEquals(a.equals(Clock.systemUTC()), false); 153 } 154 155 public void test_hashCode() { 156 Clock a = Clock.offset(Clock.system(PARIS), OFFSET); 157 Clock b = Clock.offset(Clock.system(PARIS), OFFSET); 158 assertEquals(a.hashCode(), a.hashCode()); 159 assertEquals(a.hashCode(), b.hashCode()); 160 161 Clock c = Clock.offset(Clock.system(MOSCOW), OFFSET); 162 assertEquals(a.hashCode() == c.hashCode(), false); 163 164 Clock d = Clock.offset(Clock.system(PARIS), OFFSET.minusNanos(1)); 165 assertEquals(a.hashCode() == d.hashCode(), false); 166 } 167 168 //----------------------------------------------------------------------- 169 public void test_toString() { 170 // spec requires "full state" in toString() 171 Clock test = Clock.offset(Clock.system(PARIS), OFFSET); 172 assertEquals(test.toString().contains("Europe/Paris"), true); 173 assertEquals(test.toString().contains("PT2S"), true); 174 } 175 176 } | 74 75 /** 76 * Test offset clock. 77 */ 78 @Test 79 public class TCKClock_Offset extends AbstractTCKTest { 80 81 private static final ZoneId MOSCOW = ZoneId.of("Europe/Moscow"); 82 private static final ZoneId PARIS = ZoneId.of("Europe/Paris"); 83 private static final Instant INSTANT = LocalDateTime.of(2008, 6, 30, 11, 30, 10, 500).atZone(ZoneOffset.ofHours(2)).toInstant(); 84 private static final Duration OFFSET = Duration.ofSeconds(2); 85 86 //----------------------------------------------------------------------- 87 public void test_isSerializable() throws IOException, ClassNotFoundException { 88 assertSerializable(Clock.offset(Clock.system(PARIS), OFFSET)); 89 } 90 91 //----------------------------------------------------------------------- 92 public void test_offset_ClockDuration() { 93 Clock test = Clock.offset(Clock.fixed(INSTANT, PARIS), OFFSET); 94 //System.out.println(test.instant()); 95 //System.out.println(INSTANT.plus(OFFSET)); 96 assertEquals(test.instant(), INSTANT.plus(OFFSET)); 97 assertEquals(test.getZone(), PARIS); 98 } 99 100 public void test_offset_ClockDuration_zeroDuration() { 101 Clock underlying = Clock.system(PARIS); 102 Clock test = Clock.offset(underlying, Duration.ZERO); 103 assertSame(test, underlying); // spec says same 104 } 105 106 @Test(expectedExceptions = NullPointerException.class) 107 public void test_offset_ClockDuration_nullClock() { 108 Clock.offset(null, Duration.ZERO); 109 } 110 111 @Test(expectedExceptions = NullPointerException.class) 112 public void test_offset_ClockDuration_nullDuration() { 113 Clock.offset(Clock.systemUTC(), null); 114 } 115 148 assertEquals(a.equals(d), false); 149 150 assertEquals(a.equals(null), false); 151 assertEquals(a.equals("other type"), false); 152 assertEquals(a.equals(Clock.systemUTC()), false); 153 } 154 155 public void test_hashCode() { 156 Clock a = Clock.offset(Clock.system(PARIS), OFFSET); 157 Clock b = Clock.offset(Clock.system(PARIS), OFFSET); 158 assertEquals(a.hashCode(), a.hashCode()); 159 assertEquals(a.hashCode(), b.hashCode()); 160 161 Clock c = Clock.offset(Clock.system(MOSCOW), OFFSET); 162 assertEquals(a.hashCode() == c.hashCode(), false); 163 164 Clock d = Clock.offset(Clock.system(PARIS), OFFSET.minusNanos(1)); 165 assertEquals(a.hashCode() == d.hashCode(), false); 166 } 167 168 } |