1 /* 2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * This file is available under and governed by the GNU General Public 26 * License version 2 only, as published by the Free Software Foundation. 27 * However, the following notice accompanied the original version of this 28 * file: 29 * 30 * Copyright (c) 2010-2012, Stephen Colebourne & Michael Nascimento Santos 31 * 32 * All rights reserved. 33 * 34 * Redistribution and use in source and binary forms, with or without 35 * modification, are permitted provided that the following conditions are met: 36 * 37 * * Redistributions of source code must retain the above copyright notice, 38 * this list of conditions and the following disclaimer. 39 * 40 * * Redistributions in binary form must reproduce the above copyright notice, 41 * this list of conditions and the following disclaimer in the documentation 42 * and/or other materials provided with the distribution. 43 * 44 * * Neither the name of JSR-310 nor the names of its contributors 45 * may be used to endorse or promote products derived from this software 46 * without specific prior written permission. 47 * 48 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 49 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 50 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 51 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 52 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 53 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 54 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 55 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 56 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 57 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 58 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 59 */ 60 package tck.java.time.zone; 61 62 import static org.testng.Assert.assertEquals; 63 64 import java.time.DayOfWeek; 65 import java.time.LocalDateTime; 66 import java.time.LocalTime; 67 import java.time.Month; 68 import java.time.ZoneOffset; 69 import java.time.zone.ZoneOffsetTransition; 70 import java.time.zone.ZoneOffsetTransitionRule; 71 import java.time.zone.ZoneOffsetTransitionRule.TimeDefinition; 72 73 import org.testng.annotations.Test; 74 import tck.java.time.AbstractTCKTest; 75 76 /** 77 * Test ZoneOffsetTransitionRule. 78 */ 79 @Test 80 public class TCKZoneOffsetTransitionRule extends AbstractTCKTest { 81 82 private static final LocalTime TIME_0100 = LocalTime.of(1, 0); 83 private static final ZoneOffset OFFSET_0200 = ZoneOffset.ofHours(2); 84 private static final ZoneOffset OFFSET_0300 = ZoneOffset.ofHours(3); 85 86 //----------------------------------------------------------------------- 87 // factory 88 //----------------------------------------------------------------------- 89 @Test(expectedExceptions=NullPointerException.class) test_factory_nullMonth()90 public void test_factory_nullMonth() { 91 ZoneOffsetTransitionRule.of( 92 null, 20, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL, 93 OFFSET_0200, OFFSET_0200, OFFSET_0300); 94 } 95 96 @Test(expectedExceptions=NullPointerException.class) test_factory_nullTime()97 public void test_factory_nullTime() { 98 ZoneOffsetTransitionRule.of( 99 Month.MARCH, 20, DayOfWeek.SUNDAY, null, false, TimeDefinition.WALL, 100 OFFSET_0200, OFFSET_0200, OFFSET_0300); 101 } 102 103 @Test(expectedExceptions=NullPointerException.class) test_factory_nullTimeDefinition()104 public void test_factory_nullTimeDefinition() { 105 ZoneOffsetTransitionRule.of( 106 Month.MARCH, 20, DayOfWeek.SUNDAY, TIME_0100, false, null, 107 OFFSET_0200, OFFSET_0200, OFFSET_0300); 108 } 109 110 @Test(expectedExceptions=NullPointerException.class) test_factory_nullStandardOffset()111 public void test_factory_nullStandardOffset() { 112 ZoneOffsetTransitionRule.of( 113 Month.MARCH, 20, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL, 114 null, OFFSET_0200, OFFSET_0300); 115 } 116 117 @Test(expectedExceptions=NullPointerException.class) test_factory_nullOffsetBefore()118 public void test_factory_nullOffsetBefore() { 119 ZoneOffsetTransitionRule.of( 120 Month.MARCH, 20, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL, 121 OFFSET_0200, null, OFFSET_0300); 122 } 123 124 @Test(expectedExceptions=NullPointerException.class) test_factory_nullOffsetAfter()125 public void test_factory_nullOffsetAfter() { 126 ZoneOffsetTransitionRule.of( 127 Month.MARCH, 20, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL, 128 OFFSET_0200, OFFSET_0200, null); 129 } 130 131 @Test(expectedExceptions=IllegalArgumentException.class) test_factory_invalidDayOfMonthIndicator_tooSmall()132 public void test_factory_invalidDayOfMonthIndicator_tooSmall() { 133 ZoneOffsetTransitionRule.of( 134 Month.MARCH, -29, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL, 135 OFFSET_0200, OFFSET_0200, OFFSET_0300); 136 } 137 138 @Test(expectedExceptions=IllegalArgumentException.class) test_factory_invalidDayOfMonthIndicator_zero()139 public void test_factory_invalidDayOfMonthIndicator_zero() { 140 ZoneOffsetTransitionRule.of( 141 Month.MARCH, 0, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL, 142 OFFSET_0200, OFFSET_0200, OFFSET_0300); 143 } 144 145 @Test(expectedExceptions=IllegalArgumentException.class) test_factory_invalidDayOfMonthIndicator_tooLarge()146 public void test_factory_invalidDayOfMonthIndicator_tooLarge() { 147 ZoneOffsetTransitionRule.of( 148 Month.MARCH, 32, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL, 149 OFFSET_0200, OFFSET_0200, OFFSET_0300); 150 } 151 152 @Test(expectedExceptions=IllegalArgumentException.class) test_factory_invalidMidnightFlag()153 public void test_factory_invalidMidnightFlag() { 154 ZoneOffsetTransitionRule.of( 155 Month.MARCH, 20, DayOfWeek.SUNDAY, TIME_0100, true, TimeDefinition.WALL, 156 OFFSET_0200, OFFSET_0200, OFFSET_0300); 157 } 158 159 //----------------------------------------------------------------------- 160 // getters 161 //----------------------------------------------------------------------- 162 @Test test_getters_floatingWeek()163 public void test_getters_floatingWeek() throws Exception { 164 ZoneOffsetTransitionRule test = ZoneOffsetTransitionRule.of( 165 Month.MARCH, 20, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL, 166 OFFSET_0200, OFFSET_0200, OFFSET_0300); 167 assertEquals(test.getMonth(), Month.MARCH); 168 assertEquals(test.getDayOfMonthIndicator(), 20); 169 assertEquals(test.getDayOfWeek(), DayOfWeek.SUNDAY); 170 assertEquals(test.getLocalTime(), TIME_0100); 171 assertEquals(test.isMidnightEndOfDay(), false); 172 assertEquals(test.getTimeDefinition(), TimeDefinition.WALL); 173 assertEquals(test.getStandardOffset(), OFFSET_0200); 174 assertEquals(test.getOffsetBefore(), OFFSET_0200); 175 assertEquals(test.getOffsetAfter(), OFFSET_0300); 176 } 177 178 @Test test_getters_floatingWeekBackwards()179 public void test_getters_floatingWeekBackwards() throws Exception { 180 ZoneOffsetTransitionRule test = ZoneOffsetTransitionRule.of( 181 Month.MARCH, -1, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL, 182 OFFSET_0200, OFFSET_0200, OFFSET_0300); 183 assertEquals(test.getMonth(), Month.MARCH); 184 assertEquals(test.getDayOfMonthIndicator(), -1); 185 assertEquals(test.getDayOfWeek(), DayOfWeek.SUNDAY); 186 assertEquals(test.getLocalTime(), TIME_0100); 187 assertEquals(test.isMidnightEndOfDay(), false); 188 assertEquals(test.getTimeDefinition(), TimeDefinition.WALL); 189 assertEquals(test.getStandardOffset(), OFFSET_0200); 190 assertEquals(test.getOffsetBefore(), OFFSET_0200); 191 assertEquals(test.getOffsetAfter(), OFFSET_0300); 192 } 193 194 @Test test_getters_fixedDate()195 public void test_getters_fixedDate() throws Exception { 196 ZoneOffsetTransitionRule test = ZoneOffsetTransitionRule.of( 197 Month.MARCH, 20, null, TIME_0100, false, TimeDefinition.WALL, 198 OFFSET_0200, OFFSET_0200, OFFSET_0300); 199 assertEquals(test.getMonth(), Month.MARCH); 200 assertEquals(test.getDayOfMonthIndicator(), 20); 201 assertEquals(test.getDayOfWeek(), null); 202 assertEquals(test.getLocalTime(), TIME_0100); 203 assertEquals(test.isMidnightEndOfDay(), false); 204 assertEquals(test.getTimeDefinition(), TimeDefinition.WALL); 205 assertEquals(test.getStandardOffset(), OFFSET_0200); 206 assertEquals(test.getOffsetBefore(), OFFSET_0200); 207 assertEquals(test.getOffsetAfter(), OFFSET_0300); 208 } 209 210 211 //----------------------------------------------------------------------- 212 // createTransition() 213 //----------------------------------------------------------------------- 214 @Test test_createTransition_floatingWeek_gap_notEndOfDay()215 public void test_createTransition_floatingWeek_gap_notEndOfDay() { 216 ZoneOffsetTransitionRule test = ZoneOffsetTransitionRule.of( 217 Month.MARCH, 20, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL, 218 OFFSET_0200, OFFSET_0200, OFFSET_0300); 219 ZoneOffsetTransition trans = ZoneOffsetTransition.of( 220 LocalDateTime.of(2000, Month.MARCH, 26, 1, 0), OFFSET_0200, OFFSET_0300); 221 assertEquals(test.createTransition(2000), trans); 222 } 223 224 @Test test_createTransition_floatingWeek_overlap_endOfDay()225 public void test_createTransition_floatingWeek_overlap_endOfDay() { 226 ZoneOffsetTransitionRule test = ZoneOffsetTransitionRule.of( 227 Month.MARCH, 20, DayOfWeek.SUNDAY, LocalTime.MIDNIGHT, true, TimeDefinition.WALL, 228 OFFSET_0200, OFFSET_0300, OFFSET_0200); 229 ZoneOffsetTransition trans = ZoneOffsetTransition.of( 230 LocalDateTime.of(2000, Month.MARCH, 27, 0, 0), OFFSET_0300, OFFSET_0200); 231 assertEquals(test.createTransition(2000), trans); 232 } 233 234 @Test test_createTransition_floatingWeekBackwards_last()235 public void test_createTransition_floatingWeekBackwards_last() { 236 ZoneOffsetTransitionRule test = ZoneOffsetTransitionRule.of( 237 Month.MARCH, -1, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL, 238 OFFSET_0200, OFFSET_0200, OFFSET_0300); 239 ZoneOffsetTransition trans = ZoneOffsetTransition.of( 240 LocalDateTime.of(2000, Month.MARCH, 26, 1, 0), OFFSET_0200, OFFSET_0300); 241 assertEquals(test.createTransition(2000), trans); 242 } 243 244 @Test test_createTransition_floatingWeekBackwards_seventhLast()245 public void test_createTransition_floatingWeekBackwards_seventhLast() { 246 ZoneOffsetTransitionRule test = ZoneOffsetTransitionRule.of( 247 Month.MARCH, -7, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL, 248 OFFSET_0200, OFFSET_0200, OFFSET_0300); 249 ZoneOffsetTransition trans = ZoneOffsetTransition.of( 250 LocalDateTime.of(2000, Month.MARCH, 19, 1, 0), OFFSET_0200, OFFSET_0300); 251 assertEquals(test.createTransition(2000), trans); 252 } 253 254 @Test test_createTransition_floatingWeekBackwards_secondLast()255 public void test_createTransition_floatingWeekBackwards_secondLast() { 256 ZoneOffsetTransitionRule test = ZoneOffsetTransitionRule.of( 257 Month.MARCH, -2, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL, 258 OFFSET_0200, OFFSET_0200, OFFSET_0300); 259 ZoneOffsetTransition trans = ZoneOffsetTransition.of( 260 LocalDateTime.of(2000, Month.MARCH, 26, 1, 0), OFFSET_0200, OFFSET_0300); 261 assertEquals(test.createTransition(2000), trans); 262 } 263 264 @Test test_createTransition_fixedDate()265 public void test_createTransition_fixedDate() { 266 ZoneOffsetTransitionRule test = ZoneOffsetTransitionRule.of( 267 Month.MARCH, 20, null, TIME_0100, false, TimeDefinition.STANDARD, 268 OFFSET_0200, OFFSET_0200, OFFSET_0300); 269 ZoneOffsetTransition trans = ZoneOffsetTransition.of( 270 LocalDateTime.of(2000, Month.MARCH, 20, 1, 0), OFFSET_0200, OFFSET_0300); 271 assertEquals(test.createTransition(2000), trans); 272 } 273 274 //----------------------------------------------------------------------- 275 // equals() 276 //----------------------------------------------------------------------- 277 @Test test_equals_monthDifferent()278 public void test_equals_monthDifferent() { 279 ZoneOffsetTransitionRule a = ZoneOffsetTransitionRule.of( 280 Month.MARCH, 20, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL, 281 OFFSET_0200, OFFSET_0200, OFFSET_0300); 282 ZoneOffsetTransitionRule b = ZoneOffsetTransitionRule.of( 283 Month.APRIL, 20, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL, 284 OFFSET_0200, OFFSET_0200, OFFSET_0300); 285 assertEquals(a.equals(a), true); 286 assertEquals(a.equals(b), false); 287 assertEquals(b.equals(a), false); 288 assertEquals(b.equals(b), true); 289 } 290 291 @Test test_equals_dayOfMonthDifferent()292 public void test_equals_dayOfMonthDifferent() { 293 ZoneOffsetTransitionRule a = ZoneOffsetTransitionRule.of( 294 Month.MARCH, 20, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL, 295 OFFSET_0200, OFFSET_0200, OFFSET_0300); 296 ZoneOffsetTransitionRule b = ZoneOffsetTransitionRule.of( 297 Month.MARCH, 21, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL, 298 OFFSET_0200, OFFSET_0200, OFFSET_0300); 299 assertEquals(a.equals(a), true); 300 assertEquals(a.equals(b), false); 301 assertEquals(b.equals(a), false); 302 assertEquals(b.equals(b), true); 303 } 304 305 @Test test_equals_dayOfWeekDifferent()306 public void test_equals_dayOfWeekDifferent() { 307 ZoneOffsetTransitionRule a = ZoneOffsetTransitionRule.of( 308 Month.MARCH, 20, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL, 309 OFFSET_0200, OFFSET_0200, OFFSET_0300); 310 ZoneOffsetTransitionRule b = ZoneOffsetTransitionRule.of( 311 Month.MARCH, 20, DayOfWeek.SATURDAY, TIME_0100, false, TimeDefinition.WALL, 312 OFFSET_0200, OFFSET_0200, OFFSET_0300); 313 assertEquals(a.equals(a), true); 314 assertEquals(a.equals(b), false); 315 assertEquals(b.equals(a), false); 316 assertEquals(b.equals(b), true); 317 } 318 319 @Test test_equals_dayOfWeekDifferentNull()320 public void test_equals_dayOfWeekDifferentNull() { 321 ZoneOffsetTransitionRule a = ZoneOffsetTransitionRule.of( 322 Month.MARCH, 20, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL, 323 OFFSET_0200, OFFSET_0200, OFFSET_0300); 324 ZoneOffsetTransitionRule b = ZoneOffsetTransitionRule.of( 325 Month.MARCH, 20, null, TIME_0100, false, TimeDefinition.WALL, 326 OFFSET_0200, OFFSET_0200, OFFSET_0300); 327 assertEquals(a.equals(a), true); 328 assertEquals(a.equals(b), false); 329 assertEquals(b.equals(a), false); 330 assertEquals(b.equals(b), true); 331 } 332 333 @Test test_equals_localTimeDifferent()334 public void test_equals_localTimeDifferent() { 335 ZoneOffsetTransitionRule a = ZoneOffsetTransitionRule.of( 336 Month.MARCH, 20, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL, 337 OFFSET_0200, OFFSET_0200, OFFSET_0300); 338 ZoneOffsetTransitionRule b = ZoneOffsetTransitionRule.of( 339 Month.MARCH, 20, DayOfWeek.SUNDAY, LocalTime.MIDNIGHT, false, TimeDefinition.WALL, 340 OFFSET_0200, OFFSET_0200, OFFSET_0300); 341 assertEquals(a.equals(a), true); 342 assertEquals(a.equals(b), false); 343 assertEquals(b.equals(a), false); 344 assertEquals(b.equals(b), true); 345 } 346 347 @Test test_equals_endOfDayDifferent()348 public void test_equals_endOfDayDifferent() { 349 ZoneOffsetTransitionRule a = ZoneOffsetTransitionRule.of( 350 Month.MARCH, 20, DayOfWeek.SUNDAY, LocalTime.MIDNIGHT, false, TimeDefinition.WALL, 351 OFFSET_0200, OFFSET_0200, OFFSET_0300); 352 ZoneOffsetTransitionRule b = ZoneOffsetTransitionRule.of( 353 Month.MARCH, 20, DayOfWeek.SUNDAY, LocalTime.MIDNIGHT, true, TimeDefinition.WALL, 354 OFFSET_0200, OFFSET_0200, OFFSET_0300); 355 assertEquals(a.equals(a), true); 356 assertEquals(a.equals(b), false); 357 assertEquals(b.equals(a), false); 358 assertEquals(b.equals(b), true); 359 } 360 361 @Test test_equals_timeDefinitionDifferent()362 public void test_equals_timeDefinitionDifferent() { 363 ZoneOffsetTransitionRule a = ZoneOffsetTransitionRule.of( 364 Month.MARCH, 20, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL, 365 OFFSET_0200, OFFSET_0200, OFFSET_0300); 366 ZoneOffsetTransitionRule b = ZoneOffsetTransitionRule.of( 367 Month.MARCH, 20, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.STANDARD, 368 OFFSET_0200, OFFSET_0200, OFFSET_0300); 369 assertEquals(a.equals(a), true); 370 assertEquals(a.equals(b), false); 371 assertEquals(b.equals(a), false); 372 assertEquals(b.equals(b), true); 373 } 374 375 @Test test_equals_standardOffsetDifferent()376 public void test_equals_standardOffsetDifferent() { 377 ZoneOffsetTransitionRule a = ZoneOffsetTransitionRule.of( 378 Month.MARCH, 20, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL, 379 OFFSET_0200, OFFSET_0200, OFFSET_0300); 380 ZoneOffsetTransitionRule b = ZoneOffsetTransitionRule.of( 381 Month.MARCH, 20, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL, 382 OFFSET_0300, OFFSET_0200, OFFSET_0300); 383 assertEquals(a.equals(a), true); 384 assertEquals(a.equals(b), false); 385 assertEquals(b.equals(a), false); 386 assertEquals(b.equals(b), true); 387 } 388 389 @Test test_equals_offsetBeforeDifferent()390 public void test_equals_offsetBeforeDifferent() { 391 ZoneOffsetTransitionRule a = ZoneOffsetTransitionRule.of( 392 Month.MARCH, 20, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL, 393 OFFSET_0200, OFFSET_0200, OFFSET_0300); 394 ZoneOffsetTransitionRule b = ZoneOffsetTransitionRule.of( 395 Month.MARCH, 20, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL, 396 OFFSET_0200, OFFSET_0300, OFFSET_0300); 397 assertEquals(a.equals(a), true); 398 assertEquals(a.equals(b), false); 399 assertEquals(b.equals(a), false); 400 assertEquals(b.equals(b), true); 401 } 402 403 @Test test_equals_offsetAfterDifferent()404 public void test_equals_offsetAfterDifferent() { 405 ZoneOffsetTransitionRule a = ZoneOffsetTransitionRule.of( 406 Month.MARCH, 20, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL, 407 OFFSET_0200, OFFSET_0200, OFFSET_0300); 408 ZoneOffsetTransitionRule b = ZoneOffsetTransitionRule.of( 409 Month.MARCH, 20, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL, 410 OFFSET_0200, OFFSET_0200, OFFSET_0200); 411 assertEquals(a.equals(a), true); 412 assertEquals(a.equals(b), false); 413 assertEquals(b.equals(a), false); 414 assertEquals(b.equals(b), true); 415 } 416 417 @Test test_equals_string_false()418 public void test_equals_string_false() { 419 ZoneOffsetTransitionRule a = ZoneOffsetTransitionRule.of( 420 Month.MARCH, 20, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL, 421 OFFSET_0200, OFFSET_0200, OFFSET_0300); 422 assertEquals(a.equals("TZDB"), false); 423 } 424 425 @Test test_equals_null_false()426 public void test_equals_null_false() { 427 ZoneOffsetTransitionRule a = ZoneOffsetTransitionRule.of( 428 Month.MARCH, 20, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL, 429 OFFSET_0200, OFFSET_0200, OFFSET_0300); 430 assertEquals(a.equals(null), false); 431 } 432 433 //----------------------------------------------------------------------- 434 // hashCode() 435 //----------------------------------------------------------------------- 436 @Test test_hashCode_floatingWeek_gap_notEndOfDay()437 public void test_hashCode_floatingWeek_gap_notEndOfDay() { 438 ZoneOffsetTransitionRule a = ZoneOffsetTransitionRule.of( 439 Month.MARCH, 20, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL, 440 OFFSET_0200, OFFSET_0200, OFFSET_0300); 441 ZoneOffsetTransitionRule b = ZoneOffsetTransitionRule.of( 442 Month.MARCH, 20, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL, 443 OFFSET_0200, OFFSET_0200, OFFSET_0300); 444 assertEquals(a.hashCode(), b.hashCode()); 445 } 446 447 @Test test_hashCode_floatingWeek_overlap_endOfDay_nullDayOfWeek()448 public void test_hashCode_floatingWeek_overlap_endOfDay_nullDayOfWeek() { 449 ZoneOffsetTransitionRule a = ZoneOffsetTransitionRule.of( 450 Month.OCTOBER, 20, null, LocalTime.MIDNIGHT, true, TimeDefinition.WALL, 451 OFFSET_0200, OFFSET_0300, OFFSET_0200); 452 ZoneOffsetTransitionRule b = ZoneOffsetTransitionRule.of( 453 Month.OCTOBER, 20, null, LocalTime.MIDNIGHT, true, TimeDefinition.WALL, 454 OFFSET_0200, OFFSET_0300, OFFSET_0200); 455 assertEquals(a.hashCode(), b.hashCode()); 456 } 457 458 @Test test_hashCode_floatingWeekBackwards()459 public void test_hashCode_floatingWeekBackwards() { 460 ZoneOffsetTransitionRule a = ZoneOffsetTransitionRule.of( 461 Month.MARCH, -1, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL, 462 OFFSET_0200, OFFSET_0200, OFFSET_0300); 463 ZoneOffsetTransitionRule b = ZoneOffsetTransitionRule.of( 464 Month.MARCH, -1, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL, 465 OFFSET_0200, OFFSET_0200, OFFSET_0300); 466 assertEquals(a.hashCode(), b.hashCode()); 467 } 468 469 @Test test_hashCode_fixedDate()470 public void test_hashCode_fixedDate() { 471 ZoneOffsetTransitionRule a = ZoneOffsetTransitionRule.of( 472 Month.MARCH, 20, null, TIME_0100, false, TimeDefinition.STANDARD, 473 OFFSET_0200, OFFSET_0200, OFFSET_0300); 474 ZoneOffsetTransitionRule b = ZoneOffsetTransitionRule.of( 475 Month.MARCH, 20, null, TIME_0100, false, TimeDefinition.STANDARD, 476 OFFSET_0200, OFFSET_0200, OFFSET_0300); 477 assertEquals(a.hashCode(), b.hashCode()); 478 } 479 480 //----------------------------------------------------------------------- 481 // toString() 482 //----------------------------------------------------------------------- 483 @Test test_toString_floatingWeek_gap_notEndOfDay()484 public void test_toString_floatingWeek_gap_notEndOfDay() { 485 ZoneOffsetTransitionRule test = ZoneOffsetTransitionRule.of( 486 Month.MARCH, 20, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL, 487 OFFSET_0200, OFFSET_0200, OFFSET_0300); 488 assertEquals(test.toString(), "TransitionRule[Gap +02:00 to +03:00, SUNDAY on or after MARCH 20 at 01:00 WALL, standard offset +02:00]"); 489 } 490 491 @Test test_toString_floatingWeek_overlap_endOfDay()492 public void test_toString_floatingWeek_overlap_endOfDay() { 493 ZoneOffsetTransitionRule test = ZoneOffsetTransitionRule.of( 494 Month.OCTOBER, 20, DayOfWeek.SUNDAY, LocalTime.MIDNIGHT, true, TimeDefinition.WALL, 495 OFFSET_0200, OFFSET_0300, OFFSET_0200); 496 assertEquals(test.toString(), "TransitionRule[Overlap +03:00 to +02:00, SUNDAY on or after OCTOBER 20 at 24:00 WALL, standard offset +02:00]"); 497 } 498 499 @Test test_toString_floatingWeekBackwards_last()500 public void test_toString_floatingWeekBackwards_last() { 501 ZoneOffsetTransitionRule test = ZoneOffsetTransitionRule.of( 502 Month.MARCH, -1, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL, 503 OFFSET_0200, OFFSET_0200, OFFSET_0300); 504 assertEquals(test.toString(), "TransitionRule[Gap +02:00 to +03:00, SUNDAY on or before last day of MARCH at 01:00 WALL, standard offset +02:00]"); 505 } 506 507 @Test test_toString_floatingWeekBackwards_secondLast()508 public void test_toString_floatingWeekBackwards_secondLast() { 509 ZoneOffsetTransitionRule test = ZoneOffsetTransitionRule.of( 510 Month.MARCH, -2, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL, 511 OFFSET_0200, OFFSET_0200, OFFSET_0300); 512 assertEquals(test.toString(), "TransitionRule[Gap +02:00 to +03:00, SUNDAY on or before last day minus 1 of MARCH at 01:00 WALL, standard offset +02:00]"); 513 } 514 515 @Test test_toString_fixedDate()516 public void test_toString_fixedDate() { 517 ZoneOffsetTransitionRule test = ZoneOffsetTransitionRule.of( 518 Month.MARCH, 20, null, TIME_0100, false, TimeDefinition.STANDARD, 519 OFFSET_0200, OFFSET_0200, OFFSET_0300); 520 assertEquals(test.toString(), "TransitionRule[Gap +02:00 to +03:00, MARCH 20 at 01:00 STANDARD, standard offset +02:00]"); 521 } 522 523 } 524