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 9 * Copyright (c) 2007-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.temporal; 61 62 import static java.time.Month.DECEMBER; 63 import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH; 64 import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR; 65 import static java.time.temporal.ChronoField.ALIGNED_WEEK_OF_MONTH; 66 import static java.time.temporal.ChronoField.ALIGNED_WEEK_OF_YEAR; 67 import static java.time.temporal.ChronoField.DAY_OF_MONTH; 68 import static java.time.temporal.ChronoField.DAY_OF_WEEK; 69 import static java.time.temporal.ChronoField.DAY_OF_YEAR; 70 import static java.time.temporal.ChronoField.EPOCH_DAY; 71 import static java.time.temporal.ChronoField.EPOCH_MONTH; 72 import static java.time.temporal.ChronoField.ERA; 73 import static java.time.temporal.ChronoField.MONTH_OF_YEAR; 74 import static java.time.temporal.ChronoField.OFFSET_SECONDS; 75 import static java.time.temporal.ChronoField.YEAR; 76 import static java.time.temporal.ChronoField.YEAR_OF_ERA; 77 import static org.testng.Assert.assertEquals; 78 import static org.testng.Assert.assertNotNull; 79 80 import java.io.ByteArrayOutputStream; 81 import java.io.DataOutputStream; 82 import java.io.IOException; 83 import java.lang.reflect.Constructor; 84 import java.lang.reflect.InvocationTargetException; 85 import java.util.ArrayList; 86 import java.util.Arrays; 87 import java.util.List; 88 89 import java.time.Clock; 90 import java.time.DateTimeException; 91 import java.time.Instant; 92 import java.time.LocalDate; 93 import java.time.LocalDateTime; 94 import java.time.LocalTime; 95 import java.time.Month; 96 import java.time.Period; 97 import java.time.ZoneId; 98 import java.time.ZoneOffset; 99 import java.time.ZonedDateTime; 100 import java.time.format.DateTimeFormatter; 101 import java.time.format.DateTimeFormatters; 102 import java.time.format.DateTimeParseException; 103 import java.time.temporal.ChronoField; 104 import java.time.temporal.ChronoUnit; 105 import java.time.temporal.ISOChrono; 106 import java.time.temporal.JulianFields; 107 import java.time.temporal.OffsetDate; 108 import java.time.temporal.OffsetDateTime; 109 import java.time.temporal.Queries; 110 import java.time.temporal.Temporal; 111 import java.time.temporal.TemporalAccessor; 112 import java.time.temporal.TemporalAdder; 113 import java.time.temporal.TemporalAdjuster; 114 import java.time.temporal.TemporalField; 115 import java.time.temporal.TemporalSubtractor; 116 import java.time.temporal.Year; 117 118 import org.testng.annotations.BeforeMethod; 119 import org.testng.annotations.DataProvider; 120 import org.testng.annotations.Test; 121 import tck.java.time.AbstractDateTimeTest; 122 import test.java.time.MockSimplePeriod; 123 124 /** 125 * Test OffsetDate. 126 */ 127 @Test 128 public class TCKOffsetDate extends AbstractDateTimeTest { 129 private static final ZoneOffset OFFSET_PONE = ZoneOffset.ofHours(1); 130 private static final ZoneOffset OFFSET_PTWO = ZoneOffset.ofHours(2); 131 132 private OffsetDate TEST_2007_07_15_PONE; 133 134 @BeforeMethod(groups={"tck","implementation"}) 135 public void setUp() { 136 TEST_2007_07_15_PONE = OffsetDate.of(LocalDate.of(2007, 7, 15), OFFSET_PONE); 137 } 138 139 //----------------------------------------------------------------------- 140 @Override 141 protected List<TemporalAccessor> samples() { 142 TemporalAccessor[] array = {TEST_2007_07_15_PONE, OffsetDate.MIN, OffsetDate.MAX}; 143 return Arrays.asList(array); 144 } 145 146 @Override 147 protected List<TemporalField> validFields() { 148 TemporalField[] array = { 149 DAY_OF_WEEK, 150 ALIGNED_DAY_OF_WEEK_IN_MONTH, 151 ALIGNED_DAY_OF_WEEK_IN_YEAR, 152 DAY_OF_MONTH, 153 DAY_OF_YEAR, 154 EPOCH_DAY, 155 ALIGNED_WEEK_OF_MONTH, 156 ALIGNED_WEEK_OF_YEAR, 157 MONTH_OF_YEAR, 158 EPOCH_MONTH, 159 YEAR_OF_ERA, 160 YEAR, 161 ERA, 162 OFFSET_SECONDS, 163 JulianFields.JULIAN_DAY, 164 JulianFields.MODIFIED_JULIAN_DAY, 165 JulianFields.RATA_DIE, 166 }; 167 return Arrays.asList(array); 168 } 169 170 @Override 171 protected List<TemporalField> invalidFields() { 172 List<TemporalField> list = new ArrayList<>(Arrays.<TemporalField>asList(ChronoField.values())); 173 list.removeAll(validFields()); 174 return list; 175 } 176 177 //----------------------------------------------------------------------- 178 @Test 179 public void test_serialization() throws ClassNotFoundException, IOException { 180 assertSerializable(TEST_2007_07_15_PONE); 181 assertSerializable(OffsetDate.MIN); 182 assertSerializable(OffsetDate.MAX); 183 } 184 185 @Test 186 public void test_serialization_format() throws Exception { 187 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 188 try (DataOutputStream dos = new DataOutputStream(baos) ) { 189 dos.writeByte(1); 190 } 191 byte[] bytes = baos.toByteArray(); 192 ByteArrayOutputStream baosDate = new ByteArrayOutputStream(); 193 try (DataOutputStream dos = new DataOutputStream(baosDate) ) { 194 dos.writeByte(3); 195 dos.writeInt(2012); 196 dos.writeByte(9); 197 dos.writeByte(16); 198 } 199 byte[] bytesDate = baosDate.toByteArray(); 200 ByteArrayOutputStream baosOffset = new ByteArrayOutputStream(); 201 try (DataOutputStream dos = new DataOutputStream(baosOffset) ) { 202 dos.writeByte(8); 203 dos.writeByte(4); // quarter hours stored: 3600 / 900 204 } 205 byte[] bytesOffset = baosOffset.toByteArray(); 206 assertSerializedBySer(OffsetDate.of(LocalDate.of(2012, 9, 16), ZoneOffset.ofHours(1)), bytes, 207 bytesDate, bytesOffset); 208 } 209 210 //----------------------------------------------------------------------- 211 // constants 212 //----------------------------------------------------------------------- 213 @Test 214 public void constant_MIN() { 215 check(OffsetDate.MIN, Year.MIN_VALUE, 1, 1, ZoneOffset.MAX); 216 } 217 218 @Test 219 public void constant_MAX() { 220 check(OffsetDate.MAX, Year.MAX_VALUE, 12, 31, ZoneOffset.MIN); 221 } 222 223 //----------------------------------------------------------------------- 224 // now() 225 //----------------------------------------------------------------------- 226 @Test(groups={"tck"}) 227 public void now() { 228 OffsetDate expected = OffsetDate.now(Clock.systemDefaultZone()); 229 OffsetDate test = OffsetDate.now(); 230 for (int i = 0; i < 100; i++) { 231 if (expected.equals(test)) { 232 return; 233 } 234 expected = OffsetDate.now(Clock.systemDefaultZone()); 235 test = OffsetDate.now(); 236 } 237 assertEquals(test, expected); 238 } 239 240 @Test(groups={"tck"}) 241 public void now_Clock_allSecsInDay_utc() { 242 for (int i = 0; i < (2 * 24 * 60 * 60); i++) { 243 Instant instant = Instant.ofEpochSecond(i); 244 Clock clock = Clock.fixed(instant, ZoneOffset.UTC); 245 OffsetDate test = OffsetDate.now(clock); 246 check(test, 1970, 1, (i < 24 * 60 * 60 ? 1 : 2), ZoneOffset.UTC); 247 } 248 } 249 250 @Test(groups={"tck"}) 251 public void now_Clock_allSecsInDay_beforeEpoch() { 252 for (int i =-1; i >= -(2 * 24 * 60 * 60); i--) { 253 Instant instant = Instant.ofEpochSecond(i); 254 Clock clock = Clock.fixed(instant, ZoneOffset.UTC); 255 OffsetDate test = OffsetDate.now(clock); 256 check(test, 1969, 12, (i >= -24 * 60 * 60 ? 31 : 30), ZoneOffset.UTC); 257 } 258 } 259 260 @Test(groups={"tck"}) 261 public void now_Clock_offsets() { 262 Instant base = LocalDateTime.of(1970, 1, 1, 12, 0).toInstant(ZoneOffset.UTC); 263 for (int i = -9; i < 15; i++) { 264 ZoneOffset offset = ZoneOffset.ofHours(i); 265 Clock clock = Clock.fixed(base, offset); 266 OffsetDate test = OffsetDate.now(clock); 267 check(test, 1970, 1, (i >= 12 ? 2 : 1), offset); 268 } 269 } 270 271 @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) 272 public void now_Clock_nullZoneId() { 273 OffsetDate.now((ZoneId) null); 274 } 275 276 @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) 277 public void now_Clock_nullClock() { 278 OffsetDate.now((Clock) null); 279 } 280 281 //----------------------------------------------------------------------- 282 // factories 283 //----------------------------------------------------------------------- 284 private void check(OffsetDate test, int y, int mo, int d, ZoneOffset offset) { 285 assertEquals(test.getDate(), LocalDate.of(y, mo, d)); 286 assertEquals(test.getOffset(), offset); 287 288 assertEquals(test.getYear(), y); 289 assertEquals(test.getMonth().getValue(), mo); 290 assertEquals(test.getDayOfMonth(), d); 291 292 assertEquals(test, test); 293 assertEquals(test.hashCode(), test.hashCode()); 294 assertEquals(OffsetDate.of(LocalDate.of(y, mo, d), offset), test); 295 } 296 297 //----------------------------------------------------------------------- 298 @Test(groups={"tck"}) 299 public void factory_of_intMonthInt() { 300 OffsetDate test = OffsetDate.of(LocalDate.of(2007, Month.JULY, 15), OFFSET_PONE); 301 check(test, 2007, 7, 15, OFFSET_PONE); 302 } 303 304 //----------------------------------------------------------------------- 305 @Test(groups={"tck"}) 306 public void factory_of_ints() { 307 OffsetDate test = OffsetDate.of(LocalDate.of(2007, 7, 15), OFFSET_PONE); 308 check(test, 2007, 7, 15, OFFSET_PONE); 309 } 310 311 //----------------------------------------------------------------------- 312 @Test(groups={"tck"}) 313 public void factory_of_intsMonthOffset() { 314 assertEquals(TEST_2007_07_15_PONE, OffsetDate.of(LocalDate.of(2007, Month.JULY, 15), OFFSET_PONE)); 315 } 316 317 @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) 318 public void factory_of_intsMonthOffset_dayTooLow() { 319 OffsetDate.of(LocalDate.of(2007, Month.JANUARY, 0), OFFSET_PONE); 320 } 321 322 @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) 323 public void factory_of_intsMonthOffset_dayTooHigh() { 324 OffsetDate.of(LocalDate.of(2007, Month.JANUARY, 32), OFFSET_PONE); 325 } 326 327 @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) 328 public void factory_of_intsMonthOffset_nullMonth() { 329 OffsetDate.of(LocalDate.of(2007, null, 30), OFFSET_PONE); 330 } 331 332 @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) 333 public void factory_of_intsMonthOffset_yearTooLow() { 334 OffsetDate.of(LocalDate.of(Integer.MIN_VALUE, Month.JANUARY, 1), OFFSET_PONE); 335 } 336 337 @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) 338 public void factory_of_intsMonthOffset_nullOffset() { 339 OffsetDate.of(LocalDate.of(2007, Month.JANUARY, 30), null); 340 } 341 342 //----------------------------------------------------------------------- 343 @Test(groups={"tck"}) 344 public void factory_of_intsOffset() { 345 OffsetDate test = OffsetDate.of(LocalDate.of(2007, 7, 15), OFFSET_PONE); 346 check(test, 2007, 7, 15, OFFSET_PONE); 347 } 348 349 @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) 350 public void factory_of_ints_dayTooLow() { 351 OffsetDate.of(LocalDate.of(2007, 1, 0), OFFSET_PONE); 352 } 353 354 @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) 355 public void factory_of_ints_dayTooHigh() { 356 OffsetDate.of(LocalDate.of(2007, 1, 32), OFFSET_PONE); 357 } 358 359 @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) 360 public void factory_of_ints_monthTooLow() { 361 OffsetDate.of(LocalDate.of(2007, 0, 1), OFFSET_PONE); 362 } 363 364 @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) 365 public void factory_of_ints_monthTooHigh() { 366 OffsetDate.of(LocalDate.of(2007, 13, 1), OFFSET_PONE); 367 } 368 369 @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) 370 public void factory_of_ints_yearTooLow() { 371 OffsetDate.of(LocalDate.of(Integer.MIN_VALUE, 1, 1), OFFSET_PONE); 372 } 373 374 @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) 375 public void factory_of_ints_nullOffset() { 376 OffsetDate.of(LocalDate.of(2007, 1, 1), (ZoneOffset) null); 377 } 378 379 //----------------------------------------------------------------------- 380 @Test(groups={"tck"}) 381 public void factory_of_LocalDateZoneOffset() { 382 LocalDate localDate = LocalDate.of(2008, 6, 30); 383 OffsetDate test = OffsetDate.of(localDate, OFFSET_PONE); 384 check(test, 2008, 6, 30, OFFSET_PONE); 385 } 386 387 @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) 388 public void factory_of_LocalDateZoneOffset_nullDate() { 389 OffsetDate.of((LocalDate) null, OFFSET_PONE); 390 } 391 392 @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) 393 public void factory_of_LocalDateZoneOffset_nullOffset() { 394 LocalDate localDate = LocalDate.of(2008, 6, 30); 395 OffsetDate.of(localDate, (ZoneOffset) null); 396 } 397 398 //----------------------------------------------------------------------- 399 // from(TemporalAccessor) 400 //----------------------------------------------------------------------- 401 @Test(groups={"tck"}) 402 public void test_from_TemporalAccessor_OD() { 403 assertEquals(OffsetDate.from(TEST_2007_07_15_PONE), TEST_2007_07_15_PONE); 404 } 405 406 @Test(groups={"tck"}) 407 public void test_from_TemporalAccessor_ZDT() { 408 ZonedDateTime base = LocalDateTime.of(2007, 7, 15, 17, 30).atZone(OFFSET_PONE); 409 assertEquals(OffsetDate.from(base), TEST_2007_07_15_PONE); 410 } 411 412 @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) 413 public void test_from_TemporalAccessor_invalid_noDerive() { 414 OffsetDate.from(LocalTime.of(12, 30)); 415 } 416 417 @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) 418 public void test_from_TemporalAccessor_null() { 419 OffsetDate.from((TemporalAccessor) null); 420 } 421 422 //----------------------------------------------------------------------- 423 // parse() 424 //----------------------------------------------------------------------- 425 @Test(dataProvider="sampleToString", groups={"tck"}) 426 public void factory_parse_validText(int y, int m, int d, String offsetId, String parsable) { 427 OffsetDate t = OffsetDate.parse(parsable); 428 assertNotNull(t, parsable); 429 assertEquals(t.getYear(), y, parsable); 430 assertEquals(t.getMonth().getValue(), m, parsable); 431 assertEquals(t.getDayOfMonth(), d, parsable); 432 assertEquals(t.getOffset(), ZoneOffset.of(offsetId)); 433 } 434 435 @DataProvider(name="sampleBadParse") 436 Object[][] provider_sampleBadParse() { 437 return new Object[][]{ 438 {"2008/07/05"}, 439 {"10000-01-01"}, 440 {"2008-1-1"}, 441 {"2008--01"}, 442 {"ABCD-02-01"}, 443 {"2008-AB-01"}, 444 {"2008-02-AB"}, 445 {"-0000-02-01"}, 446 {"2008-02-01Y"}, 447 {"2008-02-01+19:00"}, 448 {"2008-02-01+01/00"}, 449 {"2008-02-01+1900"}, 450 {"2008-02-01+01:60"}, 451 {"2008-02-01+01:30:123"}, 452 {"2008-02-01"}, 453 {"2008-02-01+01:00[Europe/Paris]"}, 454 }; 455 } 456 457 @Test(dataProvider="sampleBadParse", expectedExceptions=DateTimeParseException.class, groups={"tck"}) 458 public void factory_parse_invalidText(String unparsable) { 459 OffsetDate.parse(unparsable); 460 } 461 462 @Test(expectedExceptions=DateTimeParseException.class, groups={"tck"}) 463 public void factory_parse_illegalValue() { 464 OffsetDate.parse("2008-06-32+01:00"); 465 } 466 467 @Test(expectedExceptions=DateTimeParseException.class, groups={"tck"}) 468 public void factory_parse_invalidValue() { 469 OffsetDate.parse("2008-06-31+01:00"); 470 } 471 472 @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) 473 public void factory_parse_nullText() { 474 OffsetDate.parse((String) null); 475 } 476 477 //----------------------------------------------------------------------- 478 // parse(DateTimeFormatter) 479 //----------------------------------------------------------------------- 480 @Test(groups={"tck"}) 481 public void factory_parse_formatter() { 482 DateTimeFormatter f = DateTimeFormatters.pattern("y M d XXX"); 483 OffsetDate test = OffsetDate.parse("2010 12 3 +01:00", f); 484 assertEquals(test, OffsetDate.of(LocalDate.of(2010, 12, 3), ZoneOffset.ofHours(1))); 485 } 486 487 @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) 488 public void factory_parse_formatter_nullText() { 489 DateTimeFormatter f = DateTimeFormatters.pattern("y M d"); 490 OffsetDate.parse((String) null, f); 491 } 492 493 @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) 494 public void factory_parse_formatter_nullFormatter() { 495 OffsetDate.parse("ANY", null); 496 } 497 498 //----------------------------------------------------------------------- 499 // constructor 500 //----------------------------------------------------------------------- 501 @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) 502 public void constructor_nullDate() throws Throwable { 503 Constructor<OffsetDate> con = OffsetDate.class.getDeclaredConstructor(LocalDate.class, ZoneOffset.class); 504 con.setAccessible(true); 505 try { 506 con.newInstance(null, OFFSET_PONE); 507 } catch (InvocationTargetException ex) { 508 throw ex.getCause(); 509 } 510 } 511 512 @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) 513 public void constructor_nullOffset() throws Throwable { 514 Constructor<OffsetDate> con = OffsetDate.class.getDeclaredConstructor(LocalDate.class, ZoneOffset.class); 515 con.setAccessible(true); 516 try { 517 con.newInstance(LocalDate.of(2008, 6, 30), null); 518 } catch (InvocationTargetException ex) { 519 throw ex.getCause(); 520 } 521 } 522 523 //----------------------------------------------------------------------- 524 // basics 525 //----------------------------------------------------------------------- 526 @DataProvider(name="sampleDates") 527 Object[][] provider_sampleDates() { 528 return new Object[][] { 529 {2008, 7, 5, OFFSET_PTWO}, 530 {2007, 7, 5, OFFSET_PONE}, 531 {2006, 7, 5, OFFSET_PTWO}, 532 {2005, 7, 5, OFFSET_PONE}, 533 {2004, 1, 1, OFFSET_PTWO}, 534 {-1, 1, 2, OFFSET_PONE}, 535 {999999, 11, 20, ZoneOffset.ofHoursMinutesSeconds(6, 9, 12)}, 536 }; 537 } 538 539 @Test(dataProvider="sampleDates", groups={"tck"}) 540 public void test_get_OffsetDate(int y, int m, int d, ZoneOffset offset) { 541 LocalDate localDate = LocalDate.of(y, m, d); 542 OffsetDate a = OffsetDate.of(localDate, offset); 543 544 assertEquals(a.getDate(), localDate); 545 assertEquals(a.getOffset(), offset); 546 assertEquals(a.toString(), localDate.toString() + offset.toString()); 547 assertEquals(a.getYear(), localDate.getYear()); 548 assertEquals(a.getMonth(), localDate.getMonth()); 549 assertEquals(a.getDayOfMonth(), localDate.getDayOfMonth()); 550 assertEquals(a.getDayOfYear(), localDate.getDayOfYear()); 551 assertEquals(a.getDayOfWeek(), localDate.getDayOfWeek()); 552 } 553 554 //----------------------------------------------------------------------- 555 // get(TemporalField) 556 //----------------------------------------------------------------------- 557 @Test 558 public void test_get_TemporalField() { 559 OffsetDate test = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); 560 assertEquals(test.get(ChronoField.YEAR), 2008); 561 assertEquals(test.get(ChronoField.MONTH_OF_YEAR), 6); 562 assertEquals(test.get(ChronoField.DAY_OF_MONTH), 30); 563 assertEquals(test.get(ChronoField.DAY_OF_WEEK), 1); 564 assertEquals(test.get(ChronoField.DAY_OF_YEAR), 182); 565 566 assertEquals(test.get(ChronoField.OFFSET_SECONDS), 3600); 567 } 568 569 @Test 570 public void test_getLong_TemporalField() { 571 OffsetDate test = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); 572 assertEquals(test.getLong(ChronoField.YEAR), 2008); 573 assertEquals(test.getLong(ChronoField.MONTH_OF_YEAR), 6); 574 assertEquals(test.getLong(ChronoField.DAY_OF_MONTH), 30); 575 assertEquals(test.getLong(ChronoField.DAY_OF_WEEK), 1); 576 assertEquals(test.getLong(ChronoField.DAY_OF_YEAR), 182); 577 578 assertEquals(test.getLong(ChronoField.OFFSET_SECONDS), 3600); 579 } 580 581 //----------------------------------------------------------------------- 582 // query(TemporalQuery) 583 //----------------------------------------------------------------------- 584 @Test 585 public void test_query_chrono() { 586 assertEquals(TEST_2007_07_15_PONE.query(Queries.chrono()), ISOChrono.INSTANCE); 587 assertEquals(Queries.chrono().queryFrom(TEST_2007_07_15_PONE), ISOChrono.INSTANCE); 588 } 589 590 @Test 591 public void test_query_zoneId() { 592 assertEquals(TEST_2007_07_15_PONE.query(Queries.zoneId()), null); 593 assertEquals(Queries.zoneId().queryFrom(TEST_2007_07_15_PONE), null); 594 } 595 596 @Test 597 public void test_query_precision() { 598 assertEquals(TEST_2007_07_15_PONE.query(Queries.precision()), ChronoUnit.DAYS); 599 assertEquals(Queries.precision().queryFrom(TEST_2007_07_15_PONE), ChronoUnit.DAYS); 600 } 601 602 @Test 603 public void test_query_offset() { 604 assertEquals(TEST_2007_07_15_PONE.query(Queries.offset()), OFFSET_PONE); 605 assertEquals(Queries.offset().queryFrom(TEST_2007_07_15_PONE), OFFSET_PONE); 606 } 607 608 @Test 609 public void test_query_zone() { 610 assertEquals(TEST_2007_07_15_PONE.query(Queries.zone()), OFFSET_PONE); 611 assertEquals(Queries.zone().queryFrom(TEST_2007_07_15_PONE), OFFSET_PONE); 612 } 613 614 @Test(expectedExceptions=NullPointerException.class) 615 public void test_query_null() { 616 TEST_2007_07_15_PONE.query(null); 617 } 618 619 //----------------------------------------------------------------------- 620 // withOffset() 621 //----------------------------------------------------------------------- 622 @Test(groups={"tck"}) 623 public void test_withOffset() { 624 OffsetDate base = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); 625 OffsetDate test = base.withOffset(OFFSET_PTWO); 626 assertEquals(test.getDate(), base.getDate()); 627 assertEquals(test.getOffset(), OFFSET_PTWO); 628 } 629 630 @Test(groups={"tck"}) 631 public void test_withOffset_noChange() { 632 OffsetDate base = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); 633 OffsetDate test = base.withOffset(OFFSET_PONE); 634 assertEquals(test, base); 635 } 636 637 @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) 638 public void test_withOffset_null() { 639 TEST_2007_07_15_PONE.withOffset(null); 640 } 641 642 //----------------------------------------------------------------------- 643 // with(WithAdjuster) 644 //----------------------------------------------------------------------- 645 @Test(groups={"tck"}) 646 public void test_with_adjustment() { 647 final OffsetDate sample = OffsetDate.of(LocalDate.of(2012, 3, 4), OFFSET_PONE); 648 TemporalAdjuster adjuster = new TemporalAdjuster() { 649 @Override 650 public Temporal adjustInto(Temporal dateTime) { 651 return sample; 652 } 653 }; 654 assertEquals(TEST_2007_07_15_PONE.with(adjuster), sample); 655 } 656 657 @Test(groups={"tck"}) 658 public void test_with_adjustment_LocalDate() { 659 OffsetDate test = TEST_2007_07_15_PONE.with(LocalDate.of(2008, 6, 30)); 660 assertEquals(test, OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE)); 661 } 662 663 @Test(groups={"tck"}) 664 public void test_with_adjustment_OffsetDate() { 665 OffsetDate test = TEST_2007_07_15_PONE.with(OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PTWO)); 666 assertEquals(test, OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PTWO)); 667 } 668 669 @Test(groups={"tck"}) 670 public void test_with_adjustment_ZoneOffset() { 671 OffsetDate test = TEST_2007_07_15_PONE.with(OFFSET_PTWO); 672 assertEquals(test, OffsetDate.of(LocalDate.of(2007, 7, 15), OFFSET_PTWO)); 673 } 674 675 @Test(groups={"tck"}) 676 public void test_with_adjustment_Month() { 677 OffsetDate test = TEST_2007_07_15_PONE.with(DECEMBER); 678 assertEquals(test, OffsetDate.of(LocalDate.of(2007, 12, 15), OFFSET_PONE)); 679 } 680 681 @Test(groups={"tck"}) 682 public void test_with_adjustment_offsetUnchanged() { 683 OffsetDate base = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); 684 OffsetDate test = base.with(Year.of(2008)); 685 assertEquals(test, base); 686 } 687 688 @Test(groups={"tck"}) 689 public void test_with_adjustment_noChange() { 690 LocalDate date = LocalDate.of(2008, 6, 30); 691 OffsetDate base = OffsetDate.of(date, OFFSET_PONE); 692 OffsetDate test = base.with(date); 693 assertEquals(test, base); 694 } 695 696 @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) 697 public void test_with_adjustment_null() { 698 TEST_2007_07_15_PONE.with((TemporalAdjuster) null); 699 } 700 701 //----------------------------------------------------------------------- 702 // with(TemporalField, long) 703 //----------------------------------------------------------------------- 704 @Test(groups={"tck"}) 705 public void test_with_TemporalField() { 706 OffsetDate test = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); 707 assertEquals(test.with(ChronoField.YEAR, 2009), OffsetDate.of(LocalDate.of(2009, 6, 30), OFFSET_PONE)); 708 assertEquals(test.with(ChronoField.MONTH_OF_YEAR, 7), OffsetDate.of(LocalDate.of(2008, 7, 30), OFFSET_PONE)); 709 assertEquals(test.with(ChronoField.DAY_OF_MONTH, 1), OffsetDate.of(LocalDate.of(2008, 6, 1), OFFSET_PONE)); 710 assertEquals(test.with(ChronoField.DAY_OF_WEEK, 2), OffsetDate.of(LocalDate.of(2008, 7, 1), OFFSET_PONE)); 711 assertEquals(test.with(ChronoField.DAY_OF_YEAR, 183), OffsetDate.of(LocalDate.of(2008, 7, 1), OFFSET_PONE)); 712 713 assertEquals(test.with(ChronoField.OFFSET_SECONDS, 7205), OffsetDate.of(LocalDate.of(2008, 6, 30), ZoneOffset.ofHoursMinutesSeconds(2, 0, 5))); 714 } 715 716 @Test(expectedExceptions=NullPointerException.class, groups={"tck"} ) 717 public void test_with_TemporalField_null() { 718 TEST_2007_07_15_PONE.with((TemporalField) null, 0); 719 } 720 721 @Test(expectedExceptions=DateTimeException.class, groups={"tck"} ) 722 public void test_with_TemporalField_invalidField() { 723 TEST_2007_07_15_PONE.with(ChronoField.AMPM_OF_DAY, 0); 724 } 725 726 //----------------------------------------------------------------------- 727 // withYear() 728 //----------------------------------------------------------------------- 729 @Test(groups={"tck"}) 730 public void test_withYear_int_normal() { 731 OffsetDate t = TEST_2007_07_15_PONE.withYear(2008); 732 assertEquals(t, OffsetDate.of(LocalDate.of(2008, 7, 15), OFFSET_PONE)); 733 } 734 735 @Test(groups={"tck"}) 736 public void test_withYear_int_noChange() { 737 OffsetDate t = TEST_2007_07_15_PONE.withYear(2007); 738 assertEquals(t, TEST_2007_07_15_PONE); 739 } 740 741 @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) 742 public void test_withYear_int_invalid() { 743 TEST_2007_07_15_PONE.withYear(Year.MIN_VALUE - 1); 744 } 745 746 @Test(groups={"tck"}) 747 public void test_withYear_int_adjustDay() { 748 OffsetDate t = OffsetDate.of(LocalDate.of(2008, 2, 29), OFFSET_PONE).withYear(2007); 749 OffsetDate expected = OffsetDate.of(LocalDate.of(2007, 2, 28), OFFSET_PONE); 750 assertEquals(t, expected); 751 } 752 753 //----------------------------------------------------------------------- 754 // withMonth() 755 //----------------------------------------------------------------------- 756 @Test(groups={"tck"}) 757 public void test_withMonth_int_normal() { 758 OffsetDate t = TEST_2007_07_15_PONE.withMonth(1); 759 assertEquals(t, OffsetDate.of(LocalDate.of(2007, 1, 15), OFFSET_PONE)); 760 } 761 762 @Test(groups={"tck"}) 763 public void test_withMonth_int_noChange() { 764 OffsetDate t = TEST_2007_07_15_PONE.withMonth(7); 765 assertEquals(t, TEST_2007_07_15_PONE); 766 } 767 768 @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) 769 public void test_withMonth_int_invalid() { 770 TEST_2007_07_15_PONE.withMonth(13); 771 } 772 773 @Test(groups={"tck"}) 774 public void test_withMonth_int_adjustDay() { 775 OffsetDate t = OffsetDate.of(LocalDate.of(2007, 12, 31), OFFSET_PONE).withMonth(11); 776 OffsetDate expected = OffsetDate.of(LocalDate.of(2007, 11, 30), OFFSET_PONE); 777 assertEquals(t, expected); 778 } 779 780 //----------------------------------------------------------------------- 781 // withDayOfMonth() 782 //----------------------------------------------------------------------- 783 @Test(groups={"tck"}) 784 public void test_withDayOfMonth_normal() { 785 OffsetDate t = TEST_2007_07_15_PONE.withDayOfMonth(1); 786 assertEquals(t, OffsetDate.of(LocalDate.of(2007, 7, 1), OFFSET_PONE)); 787 } 788 789 @Test(groups={"tck"}) 790 public void test_withDayOfMonth_noChange() { 791 OffsetDate t = TEST_2007_07_15_PONE.withDayOfMonth(15); 792 assertEquals(t, OffsetDate.of(LocalDate.of(2007, 7, 15), OFFSET_PONE)); 793 } 794 795 @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) 796 public void test_withDayOfMonth_invalidForMonth() { 797 OffsetDate.of(LocalDate.of(2007, 11, 30), OFFSET_PONE).withDayOfMonth(31); 798 } 799 800 @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) 801 public void test_withDayOfMonth_invalidAlways() { 802 OffsetDate.of(LocalDate.of(2007, 11, 30), OFFSET_PONE).withDayOfMonth(32); 803 } 804 805 //----------------------------------------------------------------------- 806 // withDayOfYear(int) 807 //----------------------------------------------------------------------- 808 @Test(groups={"tck"}) 809 public void test_withDayOfYear_normal() { 810 OffsetDate t = TEST_2007_07_15_PONE.withDayOfYear(33); 811 assertEquals(t, OffsetDate.of(LocalDate.of(2007, 2, 2), OFFSET_PONE)); 812 } 813 814 @Test(groups={"tck"}) 815 public void test_withDayOfYear_noChange() { 816 OffsetDate t = TEST_2007_07_15_PONE.withDayOfYear(31 + 28 + 31 + 30 + 31 + 30 + 15); 817 assertEquals(t, TEST_2007_07_15_PONE); 818 } 819 820 @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) 821 public void test_withDayOfYear_illegal() { 822 TEST_2007_07_15_PONE.withDayOfYear(367); 823 } 824 825 @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) 826 public void test_withDayOfYear_invalid() { 827 TEST_2007_07_15_PONE.withDayOfYear(366); 828 } 829 830 //----------------------------------------------------------------------- 831 // plus(PlusAdjuster) 832 //----------------------------------------------------------------------- 833 @Test(groups={"tck"}) 834 public void test_plus_PlusAdjuster() { 835 MockSimplePeriod period = MockSimplePeriod.of(7, ChronoUnit.MONTHS); 836 OffsetDate t = TEST_2007_07_15_PONE.plus(period); 837 assertEquals(t, OffsetDate.of(LocalDate.of(2008, 2, 15), OFFSET_PONE)); 838 } 839 840 @Test(groups={"tck"}) 841 public void test_plus_PlusAdjuster_noChange() { 842 MockSimplePeriod period = MockSimplePeriod.of(0, ChronoUnit.MONTHS); 843 OffsetDate t = TEST_2007_07_15_PONE.plus(period); 844 assertEquals(t, TEST_2007_07_15_PONE); 845 } 846 847 @Test(groups={"tck"}) 848 public void test_plus_PlusAdjuster_zero() { 849 OffsetDate t = TEST_2007_07_15_PONE.plus(Period.ZERO); 850 assertEquals(t, TEST_2007_07_15_PONE); 851 } 852 853 @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) 854 public void test_plus_PlusAdjuster_null() { 855 TEST_2007_07_15_PONE.plus((TemporalAdder) null); 856 } 857 858 //----------------------------------------------------------------------- 859 // plusYears() 860 //----------------------------------------------------------------------- 861 @Test(groups={"tck"}) 862 public void test_plusYears_long_normal() { 863 OffsetDate t = TEST_2007_07_15_PONE.plusYears(1); 864 assertEquals(t, OffsetDate.of(LocalDate.of(2008, 7, 15), OFFSET_PONE)); 865 } 866 867 @Test(groups={"tck"}) 868 public void test_plusYears_long_negative() { 869 OffsetDate t = TEST_2007_07_15_PONE.plusYears(-1); 870 assertEquals(t, OffsetDate.of(LocalDate.of(2006, 7, 15), OFFSET_PONE)); 871 } 872 873 @Test(groups={"tck"}) 874 public void test_plusYears_long_noChange() { 875 OffsetDate t = TEST_2007_07_15_PONE.plusYears(0); 876 assertEquals(t, TEST_2007_07_15_PONE); 877 } 878 879 @Test(groups={"tck"}) 880 public void test_plusYears_long_adjustDay() { 881 OffsetDate t = OffsetDate.of(LocalDate.of(2008, 2, 29), OFFSET_PONE).plusYears(1); 882 OffsetDate expected = OffsetDate.of(LocalDate.of(2009, 2, 28), OFFSET_PONE); 883 assertEquals(t, expected); 884 } 885 886 @Test(groups={"tck"}) 887 public void test_plusYears_long_big() { 888 long years = 20L + Year.MAX_VALUE; 889 OffsetDate test = OffsetDate.of(LocalDate.of(-40, 6, 1), OFFSET_PONE).plusYears(years); 890 assertEquals(test, OffsetDate.of(LocalDate.of((int) (-40L + years), 6, 1), OFFSET_PONE)); 891 } 892 893 @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) 894 public void test_plusYears_long_invalidTooLarge() { 895 OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 1, 1), OFFSET_PONE).plusYears(1); 896 } 897 898 @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) 899 public void test_plusYears_long_invalidTooLargeMaxAddMax() { 900 OffsetDate test = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE); 901 test.plusYears(Long.MAX_VALUE); 902 } 903 904 @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) 905 public void test_plusYears_long_invalidTooLargeMaxAddMin() { 906 OffsetDate test = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE); 907 test.plusYears(Long.MIN_VALUE); 908 } 909 910 @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) 911 public void test_plusYears_long_invalidTooSmall() { 912 OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).plusYears(-1); 913 } 914 915 //----------------------------------------------------------------------- 916 // plusMonths() 917 //----------------------------------------------------------------------- 918 @Test(groups={"tck"}) 919 public void test_plusMonths_long_normal() { 920 OffsetDate t = TEST_2007_07_15_PONE.plusMonths(1); 921 assertEquals(t, OffsetDate.of(LocalDate.of(2007, 8, 15), OFFSET_PONE)); 922 } 923 924 @Test(groups={"tck"}) 925 public void test_plusMonths_long_overYears() { 926 OffsetDate t = TEST_2007_07_15_PONE.plusMonths(25); 927 assertEquals(t, OffsetDate.of(LocalDate.of(2009, 8, 15), OFFSET_PONE)); 928 } 929 930 @Test(groups={"tck"}) 931 public void test_plusMonths_long_negative() { 932 OffsetDate t = TEST_2007_07_15_PONE.plusMonths(-1); 933 assertEquals(t, OffsetDate.of(LocalDate.of(2007, 6, 15), OFFSET_PONE)); 934 } 935 936 @Test(groups={"tck"}) 937 public void test_plusMonths_long_negativeAcrossYear() { 938 OffsetDate t = TEST_2007_07_15_PONE.plusMonths(-7); 939 assertEquals(t, OffsetDate.of(LocalDate.of(2006, 12, 15), OFFSET_PONE)); 940 } 941 942 @Test(groups={"tck"}) 943 public void test_plusMonths_long_negativeOverYears() { 944 OffsetDate t = TEST_2007_07_15_PONE.plusMonths(-31); 945 assertEquals(t, OffsetDate.of(LocalDate.of(2004, 12, 15), OFFSET_PONE)); 946 } 947 948 @Test(groups={"tck"}) 949 public void test_plusMonths_long_noChange() { 950 OffsetDate t = TEST_2007_07_15_PONE.plusMonths(0); 951 assertEquals(t, TEST_2007_07_15_PONE); 952 } 953 954 @Test(groups={"tck"}) 955 public void test_plusMonths_long_adjustDayFromLeapYear() { 956 OffsetDate t = OffsetDate.of(LocalDate.of(2008, 2, 29), OFFSET_PONE).plusMonths(12); 957 OffsetDate expected = OffsetDate.of(LocalDate.of(2009, 2, 28), OFFSET_PONE); 958 assertEquals(t, expected); 959 } 960 961 @Test(groups={"tck"}) 962 public void test_plusMonths_long_adjustDayFromMonthLength() { 963 OffsetDate t = OffsetDate.of(LocalDate.of(2007, 3, 31), OFFSET_PONE).plusMonths(1); 964 OffsetDate expected = OffsetDate.of(LocalDate.of(2007, 4, 30), OFFSET_PONE); 965 assertEquals(t, expected); 966 } 967 968 @Test(groups={"tck"}) 969 public void test_plusMonths_long_big() { 970 long months = 20L + Integer.MAX_VALUE; 971 OffsetDate test = OffsetDate.of(LocalDate.of(-40, 6, 1), OFFSET_PONE).plusMonths(months); 972 assertEquals(test, OffsetDate.of(LocalDate.of((int) (-40L + months / 12), 6 + (int) (months % 12), 1), OFFSET_PONE)); 973 } 974 975 @Test(expectedExceptions={DateTimeException.class}, groups={"tck"}) 976 public void test_plusMonths_long_invalidTooLarge() { 977 OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE).plusMonths(1); 978 } 979 980 @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) 981 public void test_plusMonths_long_invalidTooLargeMaxAddMax() { 982 OffsetDate test = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE); 983 test.plusMonths(Long.MAX_VALUE); 984 } 985 986 @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) 987 public void test_plusMonths_long_invalidTooLargeMaxAddMin() { 988 OffsetDate test = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE); 989 test.plusMonths(Long.MIN_VALUE); 990 } 991 992 @Test(expectedExceptions={DateTimeException.class}, groups={"tck"}) 993 public void test_plusMonths_long_invalidTooSmall() { 994 OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).plusMonths(-1); 995 } 996 997 //----------------------------------------------------------------------- 998 // plusWeeks() 999 //----------------------------------------------------------------------- 1000 @DataProvider(name="samplePlusWeeksSymmetry") 1001 Object[][] provider_samplePlusWeeksSymmetry() { 1002 return new Object[][] { 1003 {OffsetDate.of(LocalDate.of(-1, 1, 1), OFFSET_PONE)}, 1004 {OffsetDate.of(LocalDate.of(-1, 2, 28), OFFSET_PTWO)}, 1005 {OffsetDate.of(LocalDate.of(-1, 3, 1), OFFSET_PONE)}, 1006 {OffsetDate.of(LocalDate.of(-1, 12, 31), OFFSET_PTWO)}, 1007 {OffsetDate.of(LocalDate.of(0, 1, 1), OFFSET_PONE)}, 1008 {OffsetDate.of(LocalDate.of(0, 2, 28), OFFSET_PTWO)}, 1009 {OffsetDate.of(LocalDate.of(0, 2, 29), OFFSET_PTWO)}, 1010 {OffsetDate.of(LocalDate.of(0, 3, 1), OFFSET_PONE)}, 1011 {OffsetDate.of(LocalDate.of(0, 12, 31), OFFSET_PTWO)}, 1012 {OffsetDate.of(LocalDate.of(2007, 1, 1), OFFSET_PONE)}, 1013 {OffsetDate.of(LocalDate.of(2007, 2, 28), OFFSET_PTWO)}, 1014 {OffsetDate.of(LocalDate.of(2007, 3, 1), OFFSET_PONE)}, 1015 {OffsetDate.of(LocalDate.of(2007, 12, 31), OFFSET_PTWO)}, 1016 {OffsetDate.of(LocalDate.of(2008, 1, 1), OFFSET_PONE)}, 1017 {OffsetDate.of(LocalDate.of(2008, 2, 28), OFFSET_PTWO)}, 1018 {OffsetDate.of(LocalDate.of(2008, 2, 29), OFFSET_PTWO)}, 1019 {OffsetDate.of(LocalDate.of(2008, 3, 1), OFFSET_PONE)}, 1020 {OffsetDate.of(LocalDate.of(2008, 12, 31), OFFSET_PTWO)}, 1021 {OffsetDate.of(LocalDate.of(2099, 1, 1), OFFSET_PONE)}, 1022 {OffsetDate.of(LocalDate.of(2099, 2, 28), OFFSET_PTWO)}, 1023 {OffsetDate.of(LocalDate.of(2099, 3, 1), OFFSET_PONE)}, 1024 {OffsetDate.of(LocalDate.of(2099, 12, 31), OFFSET_PTWO)}, 1025 {OffsetDate.of(LocalDate.of(2100, 1, 1), OFFSET_PONE)}, 1026 {OffsetDate.of(LocalDate.of(2100, 2, 28), OFFSET_PTWO)}, 1027 {OffsetDate.of(LocalDate.of(2100, 3, 1), OFFSET_PONE)}, 1028 {OffsetDate.of(LocalDate.of(2100, 12, 31), OFFSET_PTWO)}, 1029 }; 1030 } 1031 1032 @Test(dataProvider="samplePlusWeeksSymmetry", groups={"tck"}) 1033 public void test_plusWeeks_symmetry(OffsetDate reference) { 1034 for (int weeks = 0; weeks < 365 * 8; weeks++) { 1035 OffsetDate t = reference.plusWeeks(weeks).plusWeeks(-weeks); 1036 assertEquals(t, reference); 1037 1038 t = reference.plusWeeks(-weeks).plusWeeks(weeks); 1039 assertEquals(t, reference); 1040 } 1041 } 1042 1043 @Test(groups={"tck"}) 1044 public void test_plusWeeks_normal() { 1045 OffsetDate t = TEST_2007_07_15_PONE.plusWeeks(1); 1046 assertEquals(t, OffsetDate.of(LocalDate.of(2007, 7, 22), OFFSET_PONE)); 1047 } 1048 1049 @Test(groups={"tck"}) 1050 public void test_plusWeeks_overMonths() { 1051 OffsetDate t = TEST_2007_07_15_PONE.plusWeeks(9); 1052 assertEquals(t, OffsetDate.of(LocalDate.of(2007, 9, 16), OFFSET_PONE)); 1053 } 1054 1055 @Test(groups={"tck"}) 1056 public void test_plusWeeks_overYears() { 1057 OffsetDate t = OffsetDate.of(LocalDate.of(2006, 7, 16), OFFSET_PONE).plusWeeks(52); 1058 assertEquals(t, TEST_2007_07_15_PONE); 1059 } 1060 1061 @Test(groups={"tck"}) 1062 public void test_plusWeeks_overLeapYears() { 1063 OffsetDate t = TEST_2007_07_15_PONE.plusYears(-1).plusWeeks(104); 1064 assertEquals(t, OffsetDate.of(LocalDate.of(2008, 7, 12), OFFSET_PONE)); 1065 } 1066 1067 @Test(groups={"tck"}) 1068 public void test_plusWeeks_negative() { 1069 OffsetDate t = TEST_2007_07_15_PONE.plusWeeks(-1); 1070 assertEquals(t, OffsetDate.of(LocalDate.of(2007, 7, 8), OFFSET_PONE)); 1071 } 1072 1073 @Test(groups={"tck"}) 1074 public void test_plusWeeks_negativeAcrossYear() { 1075 OffsetDate t = TEST_2007_07_15_PONE.plusWeeks(-28); 1076 assertEquals(t, OffsetDate.of(LocalDate.of(2006, 12, 31), OFFSET_PONE)); 1077 } 1078 1079 @Test(groups={"tck"}) 1080 public void test_plusWeeks_negativeOverYears() { 1081 OffsetDate t = TEST_2007_07_15_PONE.plusWeeks(-104); 1082 assertEquals(t, OffsetDate.of(LocalDate.of(2005, 7, 17), OFFSET_PONE)); 1083 } 1084 1085 @Test(groups={"tck"}) 1086 public void test_plusWeeks_noChange() { 1087 OffsetDate t = TEST_2007_07_15_PONE.plusWeeks(0); 1088 assertEquals(t, TEST_2007_07_15_PONE); 1089 } 1090 1091 @Test(groups={"tck"}) 1092 public void test_plusWeeks_maximum() { 1093 OffsetDate t = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 24), OFFSET_PONE).plusWeeks(1); 1094 OffsetDate expected = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 31), OFFSET_PONE); 1095 assertEquals(t, expected); 1096 } 1097 1098 @Test(groups={"tck"}) 1099 public void test_plusWeeks_minimum() { 1100 OffsetDate t = OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 8), OFFSET_PONE).plusWeeks(-1); 1101 OffsetDate expected = OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE); 1102 assertEquals(t, expected); 1103 } 1104 1105 @Test(expectedExceptions={DateTimeException.class}, groups={"tck"}) 1106 public void test_plusWeeks_invalidTooLarge() { 1107 OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 25), OFFSET_PONE).plusWeeks(1); 1108 } 1109 1110 @Test(expectedExceptions={DateTimeException.class}, groups={"tck"}) 1111 public void test_plusWeeks_invalidTooSmall() { 1112 OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 7), OFFSET_PONE).plusWeeks(-1); 1113 } 1114 1115 @Test(expectedExceptions={ArithmeticException.class}, groups={"tck"}) 1116 public void test_plusWeeks_invalidMaxMinusMax() { 1117 OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 25), OFFSET_PONE).plusWeeks(Long.MAX_VALUE); 1118 } 1119 1120 @Test(expectedExceptions={ArithmeticException.class}, groups={"tck"}) 1121 public void test_plusWeeks_invalidMaxMinusMin() { 1122 OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 25), OFFSET_PONE).plusWeeks(Long.MIN_VALUE); 1123 } 1124 1125 //----------------------------------------------------------------------- 1126 // plusDays() 1127 //----------------------------------------------------------------------- 1128 @DataProvider(name="samplePlusDaysSymmetry") 1129 Object[][] provider_samplePlusDaysSymmetry() { 1130 return new Object[][] { 1131 {OffsetDate.of(LocalDate.of(-1, 1, 1), OFFSET_PONE)}, 1132 {OffsetDate.of(LocalDate.of(-1, 2, 28), OFFSET_PTWO)}, 1133 {OffsetDate.of(LocalDate.of(-1, 3, 1), OFFSET_PONE)}, 1134 {OffsetDate.of(LocalDate.of(-1, 12, 31), OFFSET_PTWO)}, 1135 {OffsetDate.of(LocalDate.of(0, 1, 1), OFFSET_PONE)}, 1136 {OffsetDate.of(LocalDate.of(0, 2, 28), OFFSET_PTWO)}, 1137 {OffsetDate.of(LocalDate.of(0, 2, 29), OFFSET_PTWO)}, 1138 {OffsetDate.of(LocalDate.of(0, 3, 1), OFFSET_PONE)}, 1139 {OffsetDate.of(LocalDate.of(0, 12, 31), OFFSET_PTWO)}, 1140 {OffsetDate.of(LocalDate.of(2007, 1, 1), OFFSET_PONE)}, 1141 {OffsetDate.of(LocalDate.of(2007, 2, 28), OFFSET_PTWO)}, 1142 {OffsetDate.of(LocalDate.of(2007, 3, 1), OFFSET_PONE)}, 1143 {OffsetDate.of(LocalDate.of(2007, 12, 31), OFFSET_PTWO)}, 1144 {OffsetDate.of(LocalDate.of(2008, 1, 1), OFFSET_PONE)}, 1145 {OffsetDate.of(LocalDate.of(2008, 2, 28), OFFSET_PTWO)}, 1146 {OffsetDate.of(LocalDate.of(2008, 2, 29), OFFSET_PTWO)}, 1147 {OffsetDate.of(LocalDate.of(2008, 3, 1), OFFSET_PONE)}, 1148 {OffsetDate.of(LocalDate.of(2008, 12, 31), OFFSET_PTWO)}, 1149 {OffsetDate.of(LocalDate.of(2099, 1, 1), OFFSET_PONE)}, 1150 {OffsetDate.of(LocalDate.of(2099, 2, 28), OFFSET_PTWO)}, 1151 {OffsetDate.of(LocalDate.of(2099, 3, 1), OFFSET_PONE)}, 1152 {OffsetDate.of(LocalDate.of(2099, 12, 31), OFFSET_PTWO)}, 1153 {OffsetDate.of(LocalDate.of(2100, 1, 1), OFFSET_PONE)}, 1154 {OffsetDate.of(LocalDate.of(2100, 2, 28), OFFSET_PTWO)}, 1155 {OffsetDate.of(LocalDate.of(2100, 3, 1), OFFSET_PONE)}, 1156 {OffsetDate.of(LocalDate.of(2100, 12, 31), OFFSET_PTWO)}, 1157 }; 1158 } 1159 1160 @Test(dataProvider="samplePlusDaysSymmetry", groups={"tck"}) 1161 public void test_plusDays_symmetry(OffsetDate reference) { 1162 for (int days = 0; days < 365 * 8; days++) { 1163 OffsetDate t = reference.plusDays(days).plusDays(-days); 1164 assertEquals(t, reference); 1165 1166 t = reference.plusDays(-days).plusDays(days); 1167 assertEquals(t, reference); 1168 } 1169 } 1170 1171 @Test(groups={"tck"}) 1172 public void test_plusDays_normal() { 1173 OffsetDate t = TEST_2007_07_15_PONE.plusDays(1); 1174 assertEquals(t, OffsetDate.of(LocalDate.of(2007, 7, 16), OFFSET_PONE)); 1175 } 1176 1177 @Test(groups={"tck"}) 1178 public void test_plusDays_overMonths() { 1179 OffsetDate t = TEST_2007_07_15_PONE.plusDays(62); 1180 assertEquals(t, OffsetDate.of(LocalDate.of(2007, 9, 15), OFFSET_PONE)); 1181 } 1182 1183 @Test(groups={"tck"}) 1184 public void test_plusDays_overYears() { 1185 OffsetDate t = OffsetDate.of(LocalDate.of(2006, 7, 14), OFFSET_PONE).plusDays(366); 1186 assertEquals(t, TEST_2007_07_15_PONE); 1187 } 1188 1189 @Test(groups={"tck"}) 1190 public void test_plusDays_overLeapYears() { 1191 OffsetDate t = TEST_2007_07_15_PONE.plusYears(-1).plusDays(365 + 366); 1192 assertEquals(t, OffsetDate.of(LocalDate.of(2008, 7, 15), OFFSET_PONE)); 1193 } 1194 1195 @Test(groups={"tck"}) 1196 public void test_plusDays_negative() { 1197 OffsetDate t = TEST_2007_07_15_PONE.plusDays(-1); 1198 assertEquals(t, OffsetDate.of(LocalDate.of(2007, 7, 14), OFFSET_PONE)); 1199 } 1200 1201 @Test(groups={"tck"}) 1202 public void test_plusDays_negativeAcrossYear() { 1203 OffsetDate t = TEST_2007_07_15_PONE.plusDays(-196); 1204 assertEquals(t, OffsetDate.of(LocalDate.of(2006, 12, 31), OFFSET_PONE)); 1205 } 1206 1207 @Test(groups={"tck"}) 1208 public void test_plusDays_negativeOverYears() { 1209 OffsetDate t = TEST_2007_07_15_PONE.plusDays(-730); 1210 assertEquals(t, OffsetDate.of(LocalDate.of(2005, 7, 15), OFFSET_PONE)); 1211 } 1212 1213 @Test(groups={"tck"}) 1214 public void test_plusDays_noChange() { 1215 OffsetDate t = TEST_2007_07_15_PONE.plusDays(0); 1216 assertEquals(t, TEST_2007_07_15_PONE); 1217 } 1218 1219 @Test(groups={"tck"}) 1220 public void test_plusDays_maximum() { 1221 OffsetDate t = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 30), OFFSET_PONE).plusDays(1); 1222 OffsetDate expected = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 31), OFFSET_PONE); 1223 assertEquals(t, expected); 1224 } 1225 1226 @Test(groups={"tck"}) 1227 public void test_plusDays_minimum() { 1228 OffsetDate t = OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 2), OFFSET_PONE).plusDays(-1); 1229 OffsetDate expected = OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE); 1230 assertEquals(t, expected); 1231 } 1232 1233 @Test(expectedExceptions={DateTimeException.class}, groups={"tck"}) 1234 public void test_plusDays_invalidTooLarge() { 1235 OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 31), OFFSET_PONE).plusDays(1); 1236 } 1237 1238 @Test(expectedExceptions={DateTimeException.class}, groups={"tck"}) 1239 public void test_plusDays_invalidTooSmall() { 1240 OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).plusDays(-1); 1241 } 1242 1243 @Test(expectedExceptions=ArithmeticException.class, groups={"tck"}) 1244 public void test_plusDays_overflowTooLarge() { 1245 OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 31), OFFSET_PONE).plusDays(Long.MAX_VALUE); 1246 } 1247 1248 @Test(expectedExceptions=ArithmeticException.class, groups={"tck"}) 1249 public void test_plusDays_overflowTooSmall() { 1250 OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).plusDays(Long.MIN_VALUE); 1251 } 1252 1253 //----------------------------------------------------------------------- 1254 // minus(MinusAdjuster) 1255 //----------------------------------------------------------------------- 1256 @Test(groups={"tck"}) 1257 public void test_minus_MinusAdjuster() { 1258 MockSimplePeriod period = MockSimplePeriod.of(7, ChronoUnit.MONTHS); 1259 OffsetDate t = TEST_2007_07_15_PONE.minus(period); 1260 assertEquals(t, OffsetDate.of(LocalDate.of(2006, 12, 15), OFFSET_PONE)); 1261 } 1262 1263 @Test(groups={"tck"}) 1264 public void test_minus_MinusAdjuster_noChange() { 1265 MockSimplePeriod period = MockSimplePeriod.of(0, ChronoUnit.MONTHS); 1266 OffsetDate t = TEST_2007_07_15_PONE.minus(period); 1267 assertEquals(t, TEST_2007_07_15_PONE); 1268 } 1269 1270 @Test(groups={"tck"}) 1271 public void test_minus_MinusAdjuster_zero() { 1272 OffsetDate t = TEST_2007_07_15_PONE.minus(Period.ZERO); 1273 assertEquals(t, TEST_2007_07_15_PONE); 1274 } 1275 1276 @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) 1277 public void test_plus_MinusAdjuster_null() { 1278 TEST_2007_07_15_PONE.minus((TemporalSubtractor) null); 1279 } 1280 1281 //----------------------------------------------------------------------- 1282 // minusYears() 1283 //----------------------------------------------------------------------- 1284 @Test(groups={"tck"}) 1285 public void test_minusYears_long_normal() { 1286 OffsetDate t = TEST_2007_07_15_PONE.minusYears(1); 1287 assertEquals(t, OffsetDate.of(LocalDate.of(2006, 7, 15), OFFSET_PONE)); 1288 } 1289 1290 @Test(groups={"tck"}) 1291 public void test_minusYears_long_negative() { 1292 OffsetDate t = TEST_2007_07_15_PONE.minusYears(-1); 1293 assertEquals(t, OffsetDate.of(LocalDate.of(2008, 7, 15), OFFSET_PONE)); 1294 } 1295 1296 @Test(groups={"tck"}) 1297 public void test_minusYears_long_noChange() { 1298 OffsetDate t = TEST_2007_07_15_PONE.minusYears(0); 1299 assertEquals(t, TEST_2007_07_15_PONE); 1300 } 1301 1302 @Test(groups={"tck"}) 1303 public void test_minusYears_long_adjustDay() { 1304 OffsetDate t = OffsetDate.of(LocalDate.of(2008, 2, 29), OFFSET_PONE).minusYears(1); 1305 OffsetDate expected = OffsetDate.of(LocalDate.of(2007, 2, 28), OFFSET_PONE); 1306 assertEquals(t, expected); 1307 } 1308 1309 @Test(groups={"tck"}) 1310 public void test_minusYears_long_big() { 1311 long years = 20L + Year.MAX_VALUE; 1312 OffsetDate test = OffsetDate.of(LocalDate.of(40, 6, 1), OFFSET_PONE).minusYears(years); 1313 assertEquals(test, OffsetDate.of(LocalDate.of((int) (40L - years), 6, 1), OFFSET_PONE)); 1314 } 1315 1316 @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) 1317 public void test_minusYears_long_invalidTooLarge() { 1318 OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 1, 1), OFFSET_PONE).minusYears(-1); 1319 } 1320 1321 @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) 1322 public void test_minusYears_long_invalidTooLargeMaxAddMax() { 1323 OffsetDate test = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE); 1324 test.minusYears(Long.MAX_VALUE); 1325 } 1326 1327 @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) 1328 public void test_minusYears_long_invalidTooLargeMaxAddMin() { 1329 OffsetDate test = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE); 1330 test.minusYears(Long.MIN_VALUE); 1331 } 1332 1333 @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) 1334 public void test_minusYears_long_invalidTooSmall() { 1335 OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).minusYears(1); 1336 } 1337 1338 //----------------------------------------------------------------------- 1339 // minusMonths() 1340 //----------------------------------------------------------------------- 1341 @Test(groups={"tck"}) 1342 public void test_minusMonths_long_normal() { 1343 OffsetDate t = TEST_2007_07_15_PONE.minusMonths(1); 1344 assertEquals(t, OffsetDate.of(LocalDate.of(2007, 6, 15), OFFSET_PONE)); 1345 } 1346 1347 @Test(groups={"tck"}) 1348 public void test_minusMonths_long_overYears() { 1349 OffsetDate t = TEST_2007_07_15_PONE.minusMonths(25); 1350 assertEquals(t, OffsetDate.of(LocalDate.of(2005, 6, 15), OFFSET_PONE)); 1351 } 1352 1353 @Test(groups={"tck"}) 1354 public void test_minusMonths_long_negative() { 1355 OffsetDate t = TEST_2007_07_15_PONE.minusMonths(-1); 1356 assertEquals(t, OffsetDate.of(LocalDate.of(2007, 8, 15), OFFSET_PONE)); 1357 } 1358 1359 @Test(groups={"tck"}) 1360 public void test_minusMonths_long_negativeAcrossYear() { 1361 OffsetDate t = TEST_2007_07_15_PONE.minusMonths(-7); 1362 assertEquals(t, OffsetDate.of(LocalDate.of(2008, 2, 15), OFFSET_PONE)); 1363 } 1364 1365 @Test(groups={"tck"}) 1366 public void test_minusMonths_long_negativeOverYears() { 1367 OffsetDate t = TEST_2007_07_15_PONE.minusMonths(-31); 1368 assertEquals(t, OffsetDate.of(LocalDate.of(2010, 2, 15), OFFSET_PONE)); 1369 } 1370 1371 @Test(groups={"tck"}) 1372 public void test_minusMonths_long_noChange() { 1373 OffsetDate t = TEST_2007_07_15_PONE.minusMonths(0); 1374 assertEquals(t, TEST_2007_07_15_PONE); 1375 } 1376 1377 @Test(groups={"tck"}) 1378 public void test_minusMonths_long_adjustDayFromLeapYear() { 1379 OffsetDate t = OffsetDate.of(LocalDate.of(2008, 2, 29), OFFSET_PONE).minusMonths(12); 1380 OffsetDate expected = OffsetDate.of(LocalDate.of(2007, 2, 28), OFFSET_PONE); 1381 assertEquals(t, expected); 1382 } 1383 1384 @Test(groups={"tck"}) 1385 public void test_minusMonths_long_adjustDayFromMonthLength() { 1386 OffsetDate t = OffsetDate.of(LocalDate.of(2007, 3, 31), OFFSET_PONE).minusMonths(1); 1387 OffsetDate expected = OffsetDate.of(LocalDate.of(2007, 2, 28), OFFSET_PONE); 1388 assertEquals(t, expected); 1389 } 1390 1391 @Test(groups={"tck"}) 1392 public void test_minusMonths_long_big() { 1393 long months = 20L + Integer.MAX_VALUE; 1394 OffsetDate test = OffsetDate.of(LocalDate.of(40, 6, 1), OFFSET_PONE).minusMonths(months); 1395 assertEquals(test, OffsetDate.of(LocalDate.of((int) (40L - months / 12), 6 - (int) (months % 12), 1), OFFSET_PONE)); 1396 } 1397 1398 @Test(expectedExceptions={DateTimeException.class}, groups={"tck"}) 1399 public void test_minusMonths_long_invalidTooLarge() { 1400 OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE).minusMonths(-1); 1401 } 1402 1403 @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) 1404 public void test_minusMonths_long_invalidTooLargeMaxAddMax() { 1405 OffsetDate test = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE); 1406 test.minusMonths(Long.MAX_VALUE); 1407 } 1408 1409 @Test(expectedExceptions=DateTimeException.class, groups={"tck"}) 1410 public void test_minusMonths_long_invalidTooLargeMaxAddMin() { 1411 OffsetDate test = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE); 1412 test.minusMonths(Long.MIN_VALUE); 1413 } 1414 1415 @Test(expectedExceptions={DateTimeException.class}, groups={"tck"}) 1416 public void test_minusMonths_long_invalidTooSmall() { 1417 OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).minusMonths(1); 1418 } 1419 1420 //----------------------------------------------------------------------- 1421 // minusWeeks() 1422 //----------------------------------------------------------------------- 1423 @DataProvider(name="sampleMinusWeeksSymmetry") 1424 Object[][] provider_sampleMinusWeeksSymmetry() { 1425 return new Object[][] { 1426 {OffsetDate.of(LocalDate.of(-1, 1, 1), OFFSET_PONE)}, 1427 {OffsetDate.of(LocalDate.of(-1, 2, 28), OFFSET_PTWO)}, 1428 {OffsetDate.of(LocalDate.of(-1, 3, 1), OFFSET_PONE)}, 1429 {OffsetDate.of(LocalDate.of(-1, 12, 31), OFFSET_PTWO)}, 1430 {OffsetDate.of(LocalDate.of(0, 1, 1), OFFSET_PONE)}, 1431 {OffsetDate.of(LocalDate.of(0, 2, 28), OFFSET_PTWO)}, 1432 {OffsetDate.of(LocalDate.of(0, 2, 29), OFFSET_PTWO)}, 1433 {OffsetDate.of(LocalDate.of(0, 3, 1), OFFSET_PONE)}, 1434 {OffsetDate.of(LocalDate.of(0, 12, 31), OFFSET_PTWO)}, 1435 {OffsetDate.of(LocalDate.of(2007, 1, 1), OFFSET_PONE)}, 1436 {OffsetDate.of(LocalDate.of(2007, 2, 28), OFFSET_PTWO)}, 1437 {OffsetDate.of(LocalDate.of(2007, 3, 1), OFFSET_PONE)}, 1438 {OffsetDate.of(LocalDate.of(2007, 12, 31), OFFSET_PTWO)}, 1439 {OffsetDate.of(LocalDate.of(2008, 1, 1), OFFSET_PONE)}, 1440 {OffsetDate.of(LocalDate.of(2008, 2, 28), OFFSET_PTWO)}, 1441 {OffsetDate.of(LocalDate.of(2008, 2, 29), OFFSET_PTWO)}, 1442 {OffsetDate.of(LocalDate.of(2008, 3, 1), OFFSET_PONE)}, 1443 {OffsetDate.of(LocalDate.of(2008, 12, 31), OFFSET_PTWO)}, 1444 {OffsetDate.of(LocalDate.of(2099, 1, 1), OFFSET_PONE)}, 1445 {OffsetDate.of(LocalDate.of(2099, 2, 28), OFFSET_PTWO)}, 1446 {OffsetDate.of(LocalDate.of(2099, 3, 1), OFFSET_PONE)}, 1447 {OffsetDate.of(LocalDate.of(2099, 12, 31), OFFSET_PTWO)}, 1448 {OffsetDate.of(LocalDate.of(2100, 1, 1), OFFSET_PONE)}, 1449 {OffsetDate.of(LocalDate.of(2100, 2, 28), OFFSET_PTWO)}, 1450 {OffsetDate.of(LocalDate.of(2100, 3, 1), OFFSET_PONE)}, 1451 {OffsetDate.of(LocalDate.of(2100, 12, 31), OFFSET_PTWO)}, 1452 }; 1453 } 1454 1455 @Test(dataProvider="sampleMinusWeeksSymmetry", groups={"tck"}) 1456 public void test_minusWeeks_symmetry(OffsetDate reference) { 1457 for (int weeks = 0; weeks < 365 * 8; weeks++) { 1458 OffsetDate t = reference.minusWeeks(weeks).minusWeeks(-weeks); 1459 assertEquals(t, reference); 1460 1461 t = reference.minusWeeks(-weeks).minusWeeks(weeks); 1462 assertEquals(t, reference); 1463 } 1464 } 1465 1466 @Test(groups={"tck"}) 1467 public void test_minusWeeks_normal() { 1468 OffsetDate t = TEST_2007_07_15_PONE.minusWeeks(1); 1469 assertEquals(t, OffsetDate.of(LocalDate.of(2007, 7, 8), OFFSET_PONE)); 1470 } 1471 1472 @Test(groups={"tck"}) 1473 public void test_minusWeeks_overMonths() { 1474 OffsetDate t = TEST_2007_07_15_PONE.minusWeeks(9); 1475 assertEquals(t, OffsetDate.of(LocalDate.of(2007, 5, 13), OFFSET_PONE)); 1476 } 1477 1478 @Test(groups={"tck"}) 1479 public void test_minusWeeks_overYears() { 1480 OffsetDate t = OffsetDate.of(LocalDate.of(2008, 7, 13), OFFSET_PONE).minusWeeks(52); 1481 assertEquals(t, TEST_2007_07_15_PONE); 1482 } 1483 1484 @Test(groups={"tck"}) 1485 public void test_minusWeeks_overLeapYears() { 1486 OffsetDate t = TEST_2007_07_15_PONE.minusYears(-1).minusWeeks(104); 1487 assertEquals(t, OffsetDate.of(LocalDate.of(2006, 7, 18), OFFSET_PONE)); 1488 } 1489 1490 @Test(groups={"tck"}) 1491 public void test_minusWeeks_negative() { 1492 OffsetDate t = TEST_2007_07_15_PONE.minusWeeks(-1); 1493 assertEquals(t, OffsetDate.of(LocalDate.of(2007, 7, 22), OFFSET_PONE)); 1494 } 1495 1496 @Test(groups={"tck"}) 1497 public void test_minusWeeks_negativeAcrossYear() { 1498 OffsetDate t = TEST_2007_07_15_PONE.minusWeeks(-28); 1499 assertEquals(t, OffsetDate.of(LocalDate.of(2008, 1, 27), OFFSET_PONE)); 1500 } 1501 1502 @Test(groups={"tck"}) 1503 public void test_minusWeeks_negativeOverYears() { 1504 OffsetDate t = TEST_2007_07_15_PONE.minusWeeks(-104); 1505 assertEquals(t, OffsetDate.of(LocalDate.of(2009, 7, 12), OFFSET_PONE)); 1506 } 1507 1508 @Test(groups={"tck"}) 1509 public void test_minusWeeks_noChange() { 1510 OffsetDate t = TEST_2007_07_15_PONE.minusWeeks(0); 1511 assertEquals(t, TEST_2007_07_15_PONE); 1512 } 1513 1514 @Test(groups={"tck"}) 1515 public void test_minusWeeks_maximum() { 1516 OffsetDate t = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 24), OFFSET_PONE).minusWeeks(-1); 1517 OffsetDate expected = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 31), OFFSET_PONE); 1518 assertEquals(t, expected); 1519 } 1520 1521 @Test(groups={"tck"}) 1522 public void test_minusWeeks_minimum() { 1523 OffsetDate t = OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 8), OFFSET_PONE).minusWeeks(1); 1524 OffsetDate expected = OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE); 1525 assertEquals(t, expected); 1526 } 1527 1528 @Test(expectedExceptions={DateTimeException.class}, groups={"tck"}) 1529 public void test_minusWeeks_invalidTooLarge() { 1530 OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 25), OFFSET_PONE).minusWeeks(-1); 1531 } 1532 1533 @Test(expectedExceptions={DateTimeException.class}, groups={"tck"}) 1534 public void test_minusWeeks_invalidTooSmall() { 1535 OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 7), OFFSET_PONE).minusWeeks(1); 1536 } 1537 1538 @Test(expectedExceptions={ArithmeticException.class}, groups={"tck"}) 1539 public void test_minusWeeks_invalidMaxMinusMax() { 1540 OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 25), OFFSET_PONE).minusWeeks(Long.MAX_VALUE); 1541 } 1542 1543 @Test(expectedExceptions={ArithmeticException.class}, groups={"tck"}) 1544 public void test_minusWeeks_invalidMaxMinusMin() { 1545 OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 25), OFFSET_PONE).minusWeeks(Long.MIN_VALUE); 1546 } 1547 1548 //----------------------------------------------------------------------- 1549 // minusDays() 1550 //----------------------------------------------------------------------- 1551 @DataProvider(name="sampleMinusDaysSymmetry") 1552 Object[][] provider_sampleMinusDaysSymmetry() { 1553 return new Object[][] { 1554 {OffsetDate.of(LocalDate.of(-1, 1, 1), OFFSET_PONE)}, 1555 {OffsetDate.of(LocalDate.of(-1, 2, 28), OFFSET_PTWO)}, 1556 {OffsetDate.of(LocalDate.of(-1, 3, 1), OFFSET_PONE)}, 1557 {OffsetDate.of(LocalDate.of(-1, 12, 31), OFFSET_PTWO)}, 1558 {OffsetDate.of(LocalDate.of(0, 1, 1), OFFSET_PONE)}, 1559 {OffsetDate.of(LocalDate.of(0, 2, 28), OFFSET_PTWO)}, 1560 {OffsetDate.of(LocalDate.of(0, 2, 29), OFFSET_PTWO)}, 1561 {OffsetDate.of(LocalDate.of(0, 3, 1), OFFSET_PONE)}, 1562 {OffsetDate.of(LocalDate.of(0, 12, 31), OFFSET_PTWO)}, 1563 {OffsetDate.of(LocalDate.of(2007, 1, 1), OFFSET_PONE)}, 1564 {OffsetDate.of(LocalDate.of(2007, 2, 28), OFFSET_PTWO)}, 1565 {OffsetDate.of(LocalDate.of(2007, 3, 1), OFFSET_PONE)}, 1566 {OffsetDate.of(LocalDate.of(2007, 12, 31), OFFSET_PTWO)}, 1567 {OffsetDate.of(LocalDate.of(2008, 1, 1), OFFSET_PONE)}, 1568 {OffsetDate.of(LocalDate.of(2008, 2, 28), OFFSET_PTWO)}, 1569 {OffsetDate.of(LocalDate.of(2008, 2, 29), OFFSET_PTWO)}, 1570 {OffsetDate.of(LocalDate.of(2008, 3, 1), OFFSET_PONE)}, 1571 {OffsetDate.of(LocalDate.of(2008, 12, 31), OFFSET_PTWO)}, 1572 {OffsetDate.of(LocalDate.of(2099, 1, 1), OFFSET_PONE)}, 1573 {OffsetDate.of(LocalDate.of(2099, 2, 28), OFFSET_PTWO)}, 1574 {OffsetDate.of(LocalDate.of(2099, 3, 1), OFFSET_PONE)}, 1575 {OffsetDate.of(LocalDate.of(2099, 12, 31), OFFSET_PTWO)}, 1576 {OffsetDate.of(LocalDate.of(2100, 1, 1), OFFSET_PONE)}, 1577 {OffsetDate.of(LocalDate.of(2100, 2, 28), OFFSET_PTWO)}, 1578 {OffsetDate.of(LocalDate.of(2100, 3, 1), OFFSET_PONE)}, 1579 {OffsetDate.of(LocalDate.of(2100, 12, 31), OFFSET_PTWO)}, 1580 }; 1581 } 1582 1583 @Test(dataProvider="sampleMinusDaysSymmetry", groups={"tck"}) 1584 public void test_minusDays_symmetry(OffsetDate reference) { 1585 for (int days = 0; days < 365 * 8; days++) { 1586 OffsetDate t = reference.minusDays(days).minusDays(-days); 1587 assertEquals(t, reference); 1588 1589 t = reference.minusDays(-days).minusDays(days); 1590 assertEquals(t, reference); 1591 } 1592 } 1593 1594 @Test(groups={"tck"}) 1595 public void test_minusDays_normal() { 1596 OffsetDate t = TEST_2007_07_15_PONE.minusDays(1); 1597 assertEquals(t, OffsetDate.of(LocalDate.of(2007, 7, 14), OFFSET_PONE)); 1598 } 1599 1600 @Test(groups={"tck"}) 1601 public void test_minusDays_overMonths() { 1602 OffsetDate t = TEST_2007_07_15_PONE.minusDays(62); 1603 assertEquals(t, OffsetDate.of(LocalDate.of(2007, 5, 14), OFFSET_PONE)); 1604 } 1605 1606 @Test(groups={"tck"}) 1607 public void test_minusDays_overYears() { 1608 OffsetDate t = OffsetDate.of(LocalDate.of(2008, 7, 16), OFFSET_PONE).minusDays(367); 1609 assertEquals(t, TEST_2007_07_15_PONE); 1610 } 1611 1612 @Test(groups={"tck"}) 1613 public void test_minusDays_overLeapYears() { 1614 OffsetDate t = TEST_2007_07_15_PONE.plusYears(2).minusDays(365 + 366); 1615 assertEquals(t, TEST_2007_07_15_PONE); 1616 } 1617 1618 @Test(groups={"tck"}) 1619 public void test_minusDays_negative() { 1620 OffsetDate t = TEST_2007_07_15_PONE.minusDays(-1); 1621 assertEquals(t, OffsetDate.of(LocalDate.of(2007, 7, 16), OFFSET_PONE)); 1622 } 1623 1624 @Test(groups={"tck"}) 1625 public void test_minusDays_negativeAcrossYear() { 1626 OffsetDate t = TEST_2007_07_15_PONE.minusDays(-169); 1627 assertEquals(t, OffsetDate.of(LocalDate.of(2007, 12, 31), OFFSET_PONE)); 1628 } 1629 1630 @Test(groups={"tck"}) 1631 public void test_minusDays_negativeOverYears() { 1632 OffsetDate t = TEST_2007_07_15_PONE.minusDays(-731); 1633 assertEquals(t, OffsetDate.of(LocalDate.of(2009, 7, 15), OFFSET_PONE)); 1634 } 1635 1636 @Test(groups={"tck"}) 1637 public void test_minusDays_noChange() { 1638 OffsetDate t = TEST_2007_07_15_PONE.minusDays(0); 1639 assertEquals(t, TEST_2007_07_15_PONE); 1640 } 1641 1642 @Test(groups={"tck"}) 1643 public void test_minusDays_maximum() { 1644 OffsetDate t = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 30), OFFSET_PONE).minusDays(-1); 1645 OffsetDate expected = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 31), OFFSET_PONE); 1646 assertEquals(t, expected); 1647 } 1648 1649 @Test(groups={"tck"}) 1650 public void test_minusDays_minimum() { 1651 OffsetDate t = OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 2), OFFSET_PONE).minusDays(1); 1652 OffsetDate expected = OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE); 1653 assertEquals(t, expected); 1654 } 1655 1656 @Test(expectedExceptions={DateTimeException.class}, groups={"tck"}) 1657 public void test_minusDays_invalidTooLarge() { 1658 OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 31), OFFSET_PONE).minusDays(-1); 1659 } 1660 1661 @Test(expectedExceptions={DateTimeException.class}, groups={"tck"}) 1662 public void test_minusDays_invalidTooSmall() { 1663 OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).minusDays(1); 1664 } 1665 1666 @Test(expectedExceptions=ArithmeticException.class, groups={"tck"}) 1667 public void test_minusDays_overflowTooLarge() { 1668 OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 31), OFFSET_PONE).minusDays(Long.MIN_VALUE); 1669 } 1670 1671 @Test(expectedExceptions=ArithmeticException.class, groups={"tck"}) 1672 public void test_minusDays_overflowTooSmall() { 1673 OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).minusDays(Long.MAX_VALUE); 1674 } 1675 1676 //----------------------------------------------------------------------- 1677 // atTime() 1678 //----------------------------------------------------------------------- 1679 @Test(groups={"tck"}) 1680 public void test_atTime_Local() { 1681 OffsetDate t = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PTWO); 1682 assertEquals(t.atTime(LocalTime.of(11, 30)), 1683 OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30), OFFSET_PTWO)); 1684 } 1685 1686 @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) 1687 public void test_atTime_Local_nullLocalTime() { 1688 OffsetDate t = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PTWO); 1689 t.atTime((LocalTime) null); 1690 } 1691 1692 //----------------------------------------------------------------------- 1693 // getDate() 1694 //----------------------------------------------------------------------- 1695 @Test(dataProvider="sampleDates", groups={"tck"}) 1696 public void test_getDate(int year, int month, int day, ZoneOffset offset) { 1697 LocalDate t = LocalDate.of(year, month, day); 1698 assertEquals(OffsetDate.of(LocalDate.of(year, month, day), offset).getDate(), t); 1699 } 1700 1701 //----------------------------------------------------------------------- 1702 // compareTo() 1703 //----------------------------------------------------------------------- 1704 @Test(groups={"tck"}) 1705 public void test_compareTo_date() { 1706 OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 29), OFFSET_PONE); 1707 OffsetDate b = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); // a is before b due to date 1708 assertEquals(a.compareTo(b) < 0, true); 1709 assertEquals(b.compareTo(a) > 0, true); 1710 assertEquals(a.compareTo(a) == 0, true); 1711 assertEquals(b.compareTo(b) == 0, true); 1712 assertEquals(a.atTime(LocalTime.MIDNIGHT).toInstant().compareTo(b.atTime(LocalTime.MIDNIGHT).toInstant()) < 0, true); 1713 } 1714 1715 @Test(groups={"tck"}) 1716 public void test_compareTo_offset() { 1717 OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PTWO); 1718 OffsetDate b = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); // a is before b due to offset 1719 assertEquals(a.compareTo(b) < 0, true); 1720 assertEquals(b.compareTo(a) > 0, true); 1721 assertEquals(a.compareTo(a) == 0, true); 1722 assertEquals(b.compareTo(b) == 0, true); 1723 assertEquals(a.atTime(LocalTime.MIDNIGHT).toInstant().compareTo(b.atTime(LocalTime.MIDNIGHT).toInstant()) < 0, true); 1724 } 1725 1726 @Test(groups={"tck"}) 1727 public void test_compareTo_both() { 1728 OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 29), OFFSET_PTWO); 1729 OffsetDate b = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); // a is before b on instant scale 1730 assertEquals(a.compareTo(b) < 0, true); 1731 assertEquals(b.compareTo(a) > 0, true); 1732 assertEquals(a.compareTo(a) == 0, true); 1733 assertEquals(b.compareTo(b) == 0, true); 1734 assertEquals(a.atTime(LocalTime.MIDNIGHT).toInstant().compareTo(b.atTime(LocalTime.MIDNIGHT).toInstant()) < 0, true); 1735 } 1736 1737 @Test(groups={"tck"}) 1738 public void test_compareTo_24hourDifference() { 1739 OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 29), ZoneOffset.ofHours(-12)); 1740 OffsetDate b = OffsetDate.of(LocalDate.of(2008, 6, 30), ZoneOffset.ofHours(12)); // a is before b despite being same time-line time 1741 assertEquals(a.compareTo(b) < 0, true); 1742 assertEquals(b.compareTo(a) > 0, true); 1743 assertEquals(a.compareTo(a) == 0, true); 1744 assertEquals(b.compareTo(b) == 0, true); 1745 assertEquals(a.atTime(LocalTime.MIDNIGHT).toInstant().compareTo(b.atTime(LocalTime.MIDNIGHT).toInstant()) == 0, true); 1746 } 1747 1748 @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) 1749 public void test_compareTo_null() { 1750 OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); 1751 a.compareTo(null); 1752 } 1753 1754 @Test(expectedExceptions=ClassCastException.class, groups={"tck"}) 1755 @SuppressWarnings({"unchecked", "rawtypes"}) 1756 public void compareToNonOffsetDate() { 1757 Comparable c = TEST_2007_07_15_PONE; 1758 c.compareTo(new Object()); 1759 } 1760 1761 //----------------------------------------------------------------------- 1762 // isAfter() / isBefore() / isEqual() 1763 //----------------------------------------------------------------------- 1764 @Test(groups={"tck"}) 1765 public void test_isBeforeIsAfterIsEqual1() { 1766 OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 29), OFFSET_PONE); 1767 OffsetDate b = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); // a is before b due to time 1768 assertEquals(a.isBefore(b), true); 1769 assertEquals(a.isEqual(b), false); 1770 assertEquals(a.isAfter(b), false); 1771 1772 assertEquals(b.isBefore(a), false); 1773 assertEquals(b.isEqual(a), false); 1774 assertEquals(b.isAfter(a), true); 1775 1776 assertEquals(a.isBefore(a), false); 1777 assertEquals(b.isBefore(b), false); 1778 1779 assertEquals(a.isEqual(a), true); 1780 assertEquals(b.isEqual(b), true); 1781 1782 assertEquals(a.isAfter(a), false); 1783 assertEquals(b.isAfter(b), false); 1784 } 1785 1786 @Test(groups={"tck"}) 1787 public void test_isBeforeIsAfterIsEqual2() { 1788 OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PTWO); 1789 OffsetDate b = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); // a is before b due to offset 1790 assertEquals(a.isBefore(b), true); 1791 assertEquals(a.isEqual(b), false); 1792 assertEquals(a.isAfter(b), false); 1793 1794 assertEquals(b.isBefore(a), false); 1795 assertEquals(b.isEqual(a), false); 1796 assertEquals(b.isAfter(a), true); 1797 1798 assertEquals(a.isBefore(a), false); 1799 assertEquals(b.isBefore(b), false); 1800 1801 assertEquals(a.isEqual(a), true); 1802 assertEquals(b.isEqual(b), true); 1803 1804 assertEquals(a.isAfter(a), false); 1805 assertEquals(b.isAfter(b), false); 1806 } 1807 1808 @Test(groups={"tck"}) 1809 public void test_isBeforeIsAfterIsEqual_instantComparison() { 1810 OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 30), ZoneOffset.ofHours(12)); 1811 OffsetDate b = OffsetDate.of(LocalDate.of(2008, 6, 29), ZoneOffset.ofHours(-12)); // a is same instant as b 1812 assertEquals(a.isBefore(b), false); 1813 assertEquals(a.isEqual(b), true); 1814 assertEquals(a.isAfter(b), false); 1815 1816 assertEquals(b.isBefore(a), false); 1817 assertEquals(b.isEqual(a), true); 1818 assertEquals(b.isAfter(a), false); 1819 1820 assertEquals(a.isBefore(a), false); 1821 assertEquals(b.isBefore(b), false); 1822 1823 assertEquals(a.isEqual(a), true); 1824 assertEquals(b.isEqual(b), true); 1825 1826 assertEquals(a.isAfter(a), false); 1827 assertEquals(b.isAfter(b), false); 1828 } 1829 1830 @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) 1831 public void test_isBefore_null() { 1832 OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); 1833 a.isBefore(null); 1834 } 1835 1836 @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) 1837 public void test_isAfter_null() { 1838 OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); 1839 a.isAfter(null); 1840 } 1841 1842 @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) 1843 public void test_isEqual_null() { 1844 OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); 1845 a.isEqual(null); 1846 } 1847 1848 //----------------------------------------------------------------------- 1849 // equals() / hashCode() 1850 //----------------------------------------------------------------------- 1851 @Test(dataProvider="sampleDates", groups={"tck"}) 1852 public void test_equals_true(int y, int m, int d, ZoneOffset offset) { 1853 OffsetDate a = OffsetDate.of(LocalDate.of(y, m, d), offset); 1854 OffsetDate b = OffsetDate.of(LocalDate.of(y, m, d), offset); 1855 assertEquals(a.equals(b), true); 1856 assertEquals(a.hashCode() == b.hashCode(), true); 1857 } 1858 @Test(dataProvider="sampleDates", groups={"tck"}) 1859 public void test_equals_false_year_differs(int y, int m, int d, ZoneOffset offset) { 1860 OffsetDate a = OffsetDate.of(LocalDate.of(y, m, d), offset); 1861 OffsetDate b = OffsetDate.of(LocalDate.of(y + 1, m, d), offset); 1862 assertEquals(a.equals(b), false); 1863 } 1864 1865 @Test(dataProvider="sampleDates", groups={"tck"}) 1866 public void test_equals_false_month_differs(int y, int m, int d, ZoneOffset offset) { 1867 OffsetDate a = OffsetDate.of(LocalDate.of(y, m, d), offset); 1868 OffsetDate b = OffsetDate.of(LocalDate.of(y, m + 1, d), offset); 1869 assertEquals(a.equals(b), false); 1870 } 1871 1872 @Test(dataProvider="sampleDates", groups={"tck"}) 1873 public void test_equals_false_day_differs(int y, int m, int d, ZoneOffset offset) { 1874 OffsetDate a = OffsetDate.of(LocalDate.of(y, m, d), offset); 1875 OffsetDate b = OffsetDate.of(LocalDate.of(y, m, d + 1), offset); 1876 assertEquals(a.equals(b), false); 1877 } 1878 1879 @Test(dataProvider="sampleDates", groups={"tck"}) 1880 public void test_equals_false_offset_differs(int y, int m, int d, ZoneOffset ignored) { 1881 OffsetDate a = OffsetDate.of(LocalDate.of(y, m, d), OFFSET_PONE); 1882 OffsetDate b = OffsetDate.of(LocalDate.of(y, m, d), OFFSET_PTWO); 1883 assertEquals(a.equals(b), false); 1884 } 1885 1886 @Test(groups={"tck"}) 1887 public void test_equals_itself_true() { 1888 assertEquals(TEST_2007_07_15_PONE.equals(TEST_2007_07_15_PONE), true); 1889 } 1890 1891 @Test(groups={"tck"}) 1892 public void test_equals_string_false() { 1893 assertEquals(TEST_2007_07_15_PONE.equals("2007-07-15"), false); 1894 } 1895 1896 //----------------------------------------------------------------------- 1897 // toString() 1898 //----------------------------------------------------------------------- 1899 @DataProvider(name="sampleToString") 1900 Object[][] provider_sampleToString() { 1901 return new Object[][] { 1902 {2008, 7, 5, "Z", "2008-07-05Z"}, 1903 {2008, 7, 5, "+00", "2008-07-05Z"}, 1904 {2008, 7, 5, "+0000", "2008-07-05Z"}, 1905 {2008, 7, 5, "+00:00", "2008-07-05Z"}, 1906 {2008, 7, 5, "+000000", "2008-07-05Z"}, 1907 {2008, 7, 5, "+00:00:00", "2008-07-05Z"}, 1908 {2008, 7, 5, "-00", "2008-07-05Z"}, 1909 {2008, 7, 5, "-0000", "2008-07-05Z"}, 1910 {2008, 7, 5, "-00:00", "2008-07-05Z"}, 1911 {2008, 7, 5, "-000000", "2008-07-05Z"}, 1912 {2008, 7, 5, "-00:00:00", "2008-07-05Z"}, 1913 {2008, 7, 5, "+01", "2008-07-05+01:00"}, 1914 {2008, 7, 5, "+0100", "2008-07-05+01:00"}, 1915 {2008, 7, 5, "+01:00", "2008-07-05+01:00"}, 1916 {2008, 7, 5, "+010000", "2008-07-05+01:00"}, 1917 {2008, 7, 5, "+01:00:00", "2008-07-05+01:00"}, 1918 {2008, 7, 5, "+0130", "2008-07-05+01:30"}, 1919 {2008, 7, 5, "+01:30", "2008-07-05+01:30"}, 1920 {2008, 7, 5, "+013000", "2008-07-05+01:30"}, 1921 {2008, 7, 5, "+01:30:00", "2008-07-05+01:30"}, 1922 {2008, 7, 5, "+013040", "2008-07-05+01:30:40"}, 1923 {2008, 7, 5, "+01:30:40", "2008-07-05+01:30:40"}, 1924 }; 1925 } 1926 1927 @Test(dataProvider="sampleToString", groups={"tck"}) 1928 public void test_toString(int y, int m, int d, String offsetId, String expected) { 1929 OffsetDate t = OffsetDate.of(LocalDate.of(y, m, d), ZoneOffset.of(offsetId)); 1930 String str = t.toString(); 1931 assertEquals(str, expected); 1932 } 1933 1934 //----------------------------------------------------------------------- 1935 // toString(DateTimeFormatter) 1936 //----------------------------------------------------------------------- 1937 @Test(groups={"tck"}) 1938 public void test_toString_formatter() { 1939 DateTimeFormatter f = DateTimeFormatters.pattern("y M d"); 1940 String t = OffsetDate.of(LocalDate.of(2010, 12, 3), OFFSET_PONE).toString(f); 1941 assertEquals(t, "2010 12 3"); 1942 } 1943 1944 @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) 1945 public void test_toString_formatter_null() { 1946 OffsetDate.of(LocalDate.of(2010, 12, 3), OFFSET_PONE).toString(null); 1947 } 1948 1949 }