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) 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 java.time.temporal.*; 63 64 import static java.time.DayOfWeek.MONDAY; 65 import static java.time.DayOfWeek.TUESDAY; 66 import static java.time.Month.DECEMBER; 67 import static java.time.Month.JANUARY; 68 import static org.testng.Assert.assertEquals; 69 import static org.testng.Assert.assertFalse; 70 import static org.testng.Assert.assertNotNull; 71 import static org.testng.Assert.assertSame; 72 import static org.testng.Assert.assertTrue; 73 74 import java.time.DayOfWeek; 75 import java.time.LocalDate; 76 import java.time.Month; 77 78 import org.testng.annotations.DataProvider; 79 import org.testng.annotations.Test; 80 81 /** 82 * Test Adjusters. 83 */ 84 @Test 85 public class TCKDateTimeAdjusters { 86 87 //----------------------------------------------------------------------- 88 // firstDayOfMonth() 89 //----------------------------------------------------------------------- 90 @Test(groups={"tck"}) 91 public void factory_firstDayOfMonth() { 92 assertNotNull(Adjusters.firstDayOfMonth()); 93 } 94 95 @Test(groups={"tck"}) 96 public void test_firstDayOfMonth_nonLeap() { 97 for (Month month : Month.values()) { 98 for (int i = 1; i <= month.length(false); i++) { 99 LocalDate date = date(2007, month, i); 100 LocalDate test = (LocalDate) Adjusters.firstDayOfMonth().adjustInto(date); 101 assertEquals(test.getYear(), 2007); 102 assertEquals(test.getMonth(), month); 103 assertEquals(test.getDayOfMonth(), 1); 104 } 105 } 106 } 107 108 @Test(groups={"tck"}) 109 public void test_firstDayOfMonth_leap() { 110 for (Month month : Month.values()) { 111 for (int i = 1; i <= month.length(true); i++) { 112 LocalDate date = date(2008, month, i); 113 LocalDate test = (LocalDate) Adjusters.firstDayOfMonth().adjustInto(date); 114 assertEquals(test.getYear(), 2008); 115 assertEquals(test.getMonth(), month); 116 assertEquals(test.getDayOfMonth(), 1); 117 } 118 } 119 } 120 121 //----------------------------------------------------------------------- 122 // lastDayOfMonth() 123 //----------------------------------------------------------------------- 124 @Test(groups={"tck"}) 125 public void factory_lastDayOfMonth() { 126 assertNotNull(Adjusters.lastDayOfMonth()); 127 } 128 129 @Test(groups={"tck"}) 130 public void test_lastDayOfMonth_nonLeap() { 131 for (Month month : Month.values()) { 132 for (int i = 1; i <= month.length(false); i++) { 133 LocalDate date = date(2007, month, i); 134 LocalDate test = (LocalDate) Adjusters.lastDayOfMonth().adjustInto(date); 135 assertEquals(test.getYear(), 2007); 136 assertEquals(test.getMonth(), month); 137 assertEquals(test.getDayOfMonth(), month.length(false)); 138 } 139 } 140 } 141 142 @Test(groups={"tck"}) 143 public void test_lastDayOfMonth_leap() { 144 for (Month month : Month.values()) { 145 for (int i = 1; i <= month.length(true); i++) { 146 LocalDate date = date(2008, month, i); 147 LocalDate test = (LocalDate) Adjusters.lastDayOfMonth().adjustInto(date); 148 assertEquals(test.getYear(), 2008); 149 assertEquals(test.getMonth(), month); 150 assertEquals(test.getDayOfMonth(), month.length(true)); 151 } 152 } 153 } 154 155 //----------------------------------------------------------------------- 156 // firstDayOfNextMonth() 157 //----------------------------------------------------------------------- 158 @Test(groups={"tck"}) 159 public void factory_firstDayOfNextMonth() { 160 assertNotNull(Adjusters.firstDayOfNextMonth()); 161 } 162 163 @Test(groups={"tck"}) 164 public void test_firstDayOfNextMonth_nonLeap() { 165 for (Month month : Month.values()) { 166 for (int i = 1; i <= month.length(false); i++) { 167 LocalDate date = date(2007, month, i); 168 LocalDate test = (LocalDate) Adjusters.firstDayOfNextMonth().adjustInto(date); 169 assertEquals(test.getYear(), month == DECEMBER ? 2008 : 2007); 170 assertEquals(test.getMonth(), month.plus(1)); 171 assertEquals(test.getDayOfMonth(), 1); 172 } 173 } 174 } 175 176 @Test(groups={"tck"}) 177 public void test_firstDayOfNextMonth_leap() { 178 for (Month month : Month.values()) { 179 for (int i = 1; i <= month.length(true); i++) { 180 LocalDate date = date(2008, month, i); 181 LocalDate test = (LocalDate) Adjusters.firstDayOfNextMonth().adjustInto(date); 182 assertEquals(test.getYear(), month == DECEMBER ? 2009 : 2008); 183 assertEquals(test.getMonth(), month.plus(1)); 184 assertEquals(test.getDayOfMonth(), 1); 185 } 186 } 187 } 188 189 //----------------------------------------------------------------------- 190 // firstDayOfYear() 191 //----------------------------------------------------------------------- 192 @Test(groups={"tck"}) 193 public void factory_firstDayOfYear() { 194 assertNotNull(Adjusters.firstDayOfYear()); 195 } 196 197 @Test(groups={"tck"}) 198 public void test_firstDayOfYear_nonLeap() { 199 for (Month month : Month.values()) { 200 for (int i = 1; i <= month.length(false); i++) { 201 LocalDate date = date(2007, month, i); 202 LocalDate test = (LocalDate) Adjusters.firstDayOfYear().adjustInto(date); 203 assertEquals(test.getYear(), 2007); 204 assertEquals(test.getMonth(), Month.JANUARY); 205 assertEquals(test.getDayOfMonth(), 1); 206 } 207 } 208 } 209 210 @Test(groups={"tck"}) 211 public void test_firstDayOfYear_leap() { 212 for (Month month : Month.values()) { 213 for (int i = 1; i <= month.length(true); i++) { 214 LocalDate date = date(2008, month, i); 215 LocalDate test = (LocalDate) Adjusters.firstDayOfYear().adjustInto(date); 216 assertEquals(test.getYear(), 2008); 217 assertEquals(test.getMonth(), Month.JANUARY); 218 assertEquals(test.getDayOfMonth(), 1); 219 } 220 } 221 } 222 223 //----------------------------------------------------------------------- 224 // lastDayOfYear() 225 //----------------------------------------------------------------------- 226 @Test(groups={"tck"}) 227 public void factory_lastDayOfYear() { 228 assertNotNull(Adjusters.lastDayOfYear()); 229 } 230 231 @Test(groups={"tck"}) 232 public void test_lastDayOfYear_nonLeap() { 233 for (Month month : Month.values()) { 234 for (int i = 1; i <= month.length(false); i++) { 235 LocalDate date = date(2007, month, i); 236 LocalDate test = (LocalDate) Adjusters.lastDayOfYear().adjustInto(date); 237 assertEquals(test.getYear(), 2007); 238 assertEquals(test.getMonth(), Month.DECEMBER); 239 assertEquals(test.getDayOfMonth(), 31); 240 } 241 } 242 } 243 244 @Test(groups={"tck"}) 245 public void test_lastDayOfYear_leap() { 246 for (Month month : Month.values()) { 247 for (int i = 1; i <= month.length(true); i++) { 248 LocalDate date = date(2008, month, i); 249 LocalDate test = (LocalDate) Adjusters.lastDayOfYear().adjustInto(date); 250 assertEquals(test.getYear(), 2008); 251 assertEquals(test.getMonth(), Month.DECEMBER); 252 assertEquals(test.getDayOfMonth(), 31); 253 } 254 } 255 } 256 257 //----------------------------------------------------------------------- 258 // firstDayOfNextYear() 259 //----------------------------------------------------------------------- 260 @Test(groups={"tck"}) 261 public void factory_firstDayOfNextYear() { 262 assertNotNull(Adjusters.firstDayOfNextYear()); 263 } 264 265 @Test(groups={"tck"}) 266 public void test_firstDayOfNextYear_nonLeap() { 267 for (Month month : Month.values()) { 268 for (int i = 1; i <= month.length(false); i++) { 269 LocalDate date = date(2007, month, i); 270 LocalDate test = (LocalDate) Adjusters.firstDayOfNextYear().adjustInto(date); 271 assertEquals(test.getYear(), 2008); 272 assertEquals(test.getMonth(), JANUARY); 273 assertEquals(test.getDayOfMonth(), 1); 274 } 275 } 276 } 277 278 @Test(groups={"tck"}) 279 public void test_firstDayOfNextYear_leap() { 280 for (Month month : Month.values()) { 281 for (int i = 1; i <= month.length(true); i++) { 282 LocalDate date = date(2008, month, i); 283 LocalDate test = (LocalDate) Adjusters.firstDayOfNextYear().adjustInto(date); 284 assertEquals(test.getYear(), 2009); 285 assertEquals(test.getMonth(), JANUARY); 286 assertEquals(test.getDayOfMonth(), 1); 287 } 288 } 289 } 290 291 //----------------------------------------------------------------------- 292 // dayOfWeekInMonth() 293 //----------------------------------------------------------------------- 294 @Test(groups={"tck"}) 295 public void factory_dayOfWeekInMonth() { 296 assertNotNull(Adjusters.dayOfWeekInMonth(1, MONDAY)); 297 } 298 299 @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) 300 public void factory_dayOfWeekInMonth_nullDayOfWeek() { 301 Adjusters.dayOfWeekInMonth(1, null); 302 } 303 304 @DataProvider(name = "dayOfWeekInMonth_positive") 305 Object[][] data_dayOfWeekInMonth_positive() { 306 return new Object[][] { 307 {2011, 1, TUESDAY, date(2011, 1, 4)}, 308 {2011, 2, TUESDAY, date(2011, 2, 1)}, 309 {2011, 3, TUESDAY, date(2011, 3, 1)}, 310 {2011, 4, TUESDAY, date(2011, 4, 5)}, 311 {2011, 5, TUESDAY, date(2011, 5, 3)}, 312 {2011, 6, TUESDAY, date(2011, 6, 7)}, 313 {2011, 7, TUESDAY, date(2011, 7, 5)}, 314 {2011, 8, TUESDAY, date(2011, 8, 2)}, 315 {2011, 9, TUESDAY, date(2011, 9, 6)}, 316 {2011, 10, TUESDAY, date(2011, 10, 4)}, 317 {2011, 11, TUESDAY, date(2011, 11, 1)}, 318 {2011, 12, TUESDAY, date(2011, 12, 6)}, 319 }; 320 } 321 322 @Test(groups={"tck"}, dataProvider = "dayOfWeekInMonth_positive") 323 public void test_dayOfWeekInMonth_positive(int year, int month, DayOfWeek dow, LocalDate expected) { 324 for (int ordinal = 1; ordinal <= 5; ordinal++) { 325 for (int day = 1; day <= Month.of(month).length(false); day++) { 326 LocalDate date = date(year, month, day); 327 LocalDate test = (LocalDate) Adjusters.dayOfWeekInMonth(ordinal, dow).adjustInto(date); 328 assertEquals(test, expected.plusWeeks(ordinal - 1)); 329 } 330 } 331 } 332 333 @DataProvider(name = "dayOfWeekInMonth_zero") 334 Object[][] data_dayOfWeekInMonth_zero() { 335 return new Object[][] { 336 {2011, 1, TUESDAY, date(2010, 12, 28)}, 337 {2011, 2, TUESDAY, date(2011, 1, 25)}, 338 {2011, 3, TUESDAY, date(2011, 2, 22)}, 339 {2011, 4, TUESDAY, date(2011, 3, 29)}, 340 {2011, 5, TUESDAY, date(2011, 4, 26)}, 341 {2011, 6, TUESDAY, date(2011, 5, 31)}, 342 {2011, 7, TUESDAY, date(2011, 6, 28)}, 343 {2011, 8, TUESDAY, date(2011, 7, 26)}, 344 {2011, 9, TUESDAY, date(2011, 8, 30)}, 345 {2011, 10, TUESDAY, date(2011, 9, 27)}, 346 {2011, 11, TUESDAY, date(2011, 10, 25)}, 347 {2011, 12, TUESDAY, date(2011, 11, 29)}, 348 }; 349 } 350 351 @Test(groups={"tck"}, dataProvider = "dayOfWeekInMonth_zero") 352 public void test_dayOfWeekInMonth_zero(int year, int month, DayOfWeek dow, LocalDate expected) { 353 for (int day = 1; day <= Month.of(month).length(false); day++) { 354 LocalDate date = date(year, month, day); 355 LocalDate test = (LocalDate) Adjusters.dayOfWeekInMonth(0, dow).adjustInto(date); 356 assertEquals(test, expected); 357 } 358 } 359 360 @DataProvider(name = "dayOfWeekInMonth_negative") 361 Object[][] data_dayOfWeekInMonth_negative() { 362 return new Object[][] { 363 {2011, 1, TUESDAY, date(2011, 1, 25)}, 364 {2011, 2, TUESDAY, date(2011, 2, 22)}, 365 {2011, 3, TUESDAY, date(2011, 3, 29)}, 366 {2011, 4, TUESDAY, date(2011, 4, 26)}, 367 {2011, 5, TUESDAY, date(2011, 5, 31)}, 368 {2011, 6, TUESDAY, date(2011, 6, 28)}, 369 {2011, 7, TUESDAY, date(2011, 7, 26)}, 370 {2011, 8, TUESDAY, date(2011, 8, 30)}, 371 {2011, 9, TUESDAY, date(2011, 9, 27)}, 372 {2011, 10, TUESDAY, date(2011, 10, 25)}, 373 {2011, 11, TUESDAY, date(2011, 11, 29)}, 374 {2011, 12, TUESDAY, date(2011, 12, 27)}, 375 }; 376 } 377 378 @Test(groups={"tck"}, dataProvider = "dayOfWeekInMonth_negative") 379 public void test_dayOfWeekInMonth_negative(int year, int month, DayOfWeek dow, LocalDate expected) { 380 for (int ordinal = 0; ordinal < 5; ordinal++) { 381 for (int day = 1; day <= Month.of(month).length(false); day++) { 382 LocalDate date = date(year, month, day); 383 LocalDate test = (LocalDate) Adjusters.dayOfWeekInMonth(-1 - ordinal, dow).adjustInto(date); 384 assertEquals(test, expected.minusWeeks(ordinal)); 385 } 386 } 387 } 388 389 //----------------------------------------------------------------------- 390 // firstInMonth() 391 //----------------------------------------------------------------------- 392 @Test(groups={"tck"}) 393 public void factory_firstInMonth() { 394 assertNotNull(Adjusters.firstInMonth(MONDAY)); 395 } 396 397 @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) 398 public void factory_firstInMonth_nullDayOfWeek() { 399 Adjusters.firstInMonth(null); 400 } 401 402 @Test(groups={"tck"}, dataProvider = "dayOfWeekInMonth_positive") 403 public void test_firstInMonth(int year, int month, DayOfWeek dow, LocalDate expected) { 404 for (int day = 1; day <= Month.of(month).length(false); day++) { 405 LocalDate date = date(year, month, day); 406 LocalDate test = (LocalDate) Adjusters.firstInMonth(dow).adjustInto(date); 407 assertEquals(test, expected, "day-of-month=" + day); 408 } 409 } 410 411 //----------------------------------------------------------------------- 412 // lastInMonth() 413 //----------------------------------------------------------------------- 414 @Test(groups={"tck"}) 415 public void factory_lastInMonth() { 416 assertNotNull(Adjusters.lastInMonth(MONDAY)); 417 } 418 419 @Test(expectedExceptions=NullPointerException.class, groups={"tck"}) 420 public void factory_lastInMonth_nullDayOfWeek() { 421 Adjusters.lastInMonth(null); 422 } 423 424 @Test(groups={"tck"}, dataProvider = "dayOfWeekInMonth_negative") 425 public void test_lastInMonth(int year, int month, DayOfWeek dow, LocalDate expected) { 426 for (int day = 1; day <= Month.of(month).length(false); day++) { 427 LocalDate date = date(year, month, day); 428 LocalDate test = (LocalDate) Adjusters.lastInMonth(dow).adjustInto(date); 429 assertEquals(test, expected, "day-of-month=" + day); 430 } 431 } 432 433 //----------------------------------------------------------------------- 434 // next() 435 //----------------------------------------------------------------------- 436 @Test(groups={"tck"}) 437 public void factory_next() { 438 assertNotNull(Adjusters.next(MONDAY)); 439 } 440 441 @Test(expectedExceptions = NullPointerException.class, groups={"tck"}) 442 public void factory_next_nullDayOfWeek() { 443 Adjusters.next(null); 444 } 445 446 @Test(groups={"tck"}) 447 public void test_next() { 448 for (Month month : Month.values()) { 449 for (int i = 1; i <= month.length(false); i++) { 450 LocalDate date = date(2007, month, i); 451 452 for (DayOfWeek dow : DayOfWeek.values()) { 453 LocalDate test = (LocalDate) Adjusters.next(dow).adjustInto(date); 454 455 assertSame(test.getDayOfWeek(), dow, date + " " + test); 456 457 if (test.getYear() == 2007) { 458 int dayDiff = test.getDayOfYear() - date.getDayOfYear(); 459 assertTrue(dayDiff > 0 && dayDiff < 8); 460 } else { 461 assertSame(month, Month.DECEMBER); 462 assertTrue(date.getDayOfMonth() > 24); 463 assertEquals(test.getYear(), 2008); 464 assertSame(test.getMonth(), Month.JANUARY); 465 assertTrue(test.getDayOfMonth() < 8); 466 } 467 } 468 } 469 } 470 } 471 472 //----------------------------------------------------------------------- 473 // nextOrSame() 474 //----------------------------------------------------------------------- 475 @Test(groups={"tck"}) 476 public void factory_nextOrCurrent() { 477 assertNotNull(Adjusters.nextOrSame(MONDAY)); 478 } 479 480 @Test(expectedExceptions = NullPointerException.class, groups={"tck"}) 481 public void factory_nextOrCurrent_nullDayOfWeek() { 482 Adjusters.nextOrSame(null); 483 } 484 485 @Test(groups={"tck"}) 486 public void test_nextOrCurrent() { 487 for (Month month : Month.values()) { 488 for (int i = 1; i <= month.length(false); i++) { 489 LocalDate date = date(2007, month, i); 490 491 for (DayOfWeek dow : DayOfWeek.values()) { 492 LocalDate test = (LocalDate) Adjusters.nextOrSame(dow).adjustInto(date); 493 494 assertSame(test.getDayOfWeek(), dow); 495 496 if (test.getYear() == 2007) { 497 int dayDiff = test.getDayOfYear() - date.getDayOfYear(); 498 assertTrue(dayDiff < 8); 499 assertEquals(date.equals(test), date.getDayOfWeek() == dow); 500 } else { 501 assertFalse(date.getDayOfWeek() == dow); 502 assertSame(month, Month.DECEMBER); 503 assertTrue(date.getDayOfMonth() > 24); 504 assertEquals(test.getYear(), 2008); 505 assertSame(test.getMonth(), Month.JANUARY); 506 assertTrue(test.getDayOfMonth() < 8); 507 } 508 } 509 } 510 } 511 } 512 513 //----------------------------------------------------------------------- 514 // previous() 515 //----------------------------------------------------------------------- 516 @Test(groups={"tck"}) 517 public void factory_previous() { 518 assertNotNull(Adjusters.previous(MONDAY)); 519 } 520 521 @Test(expectedExceptions = NullPointerException.class, groups={"tck"}) 522 public void factory_previous_nullDayOfWeek() { 523 Adjusters.previous(null); 524 } 525 526 @Test(groups={"tck"}) 527 public void test_previous() { 528 for (Month month : Month.values()) { 529 for (int i = 1; i <= month.length(false); i++) { 530 LocalDate date = date(2007, month, i); 531 532 for (DayOfWeek dow : DayOfWeek.values()) { 533 LocalDate test = (LocalDate) Adjusters.previous(dow).adjustInto(date); 534 535 assertSame(test.getDayOfWeek(), dow, date + " " + test); 536 537 if (test.getYear() == 2007) { 538 int dayDiff = test.getDayOfYear() - date.getDayOfYear(); 539 assertTrue(dayDiff < 0 && dayDiff > -8, dayDiff + " " + test); 540 } else { 541 assertSame(month, Month.JANUARY); 542 assertTrue(date.getDayOfMonth() < 8); 543 assertEquals(test.getYear(), 2006); 544 assertSame(test.getMonth(), Month.DECEMBER); 545 assertTrue(test.getDayOfMonth() > 24); 546 } 547 } 548 } 549 } 550 } 551 552 //----------------------------------------------------------------------- 553 // previousOrSame() 554 //----------------------------------------------------------------------- 555 @Test(groups={"tck"}) 556 public void factory_previousOrCurrent() { 557 assertNotNull(Adjusters.previousOrSame(MONDAY)); 558 } 559 560 @Test(expectedExceptions = NullPointerException.class, groups={"tck"}) 561 public void factory_previousOrCurrent_nullDayOfWeek() { 562 Adjusters.previousOrSame(null); 563 } 564 565 @Test(groups={"tck"}) 566 public void test_previousOrCurrent() { 567 for (Month month : Month.values()) { 568 for (int i = 1; i <= month.length(false); i++) { 569 LocalDate date = date(2007, month, i); 570 571 for (DayOfWeek dow : DayOfWeek.values()) { 572 LocalDate test = (LocalDate) Adjusters.previousOrSame(dow).adjustInto(date); 573 574 assertSame(test.getDayOfWeek(), dow); 575 576 if (test.getYear() == 2007) { 577 int dayDiff = test.getDayOfYear() - date.getDayOfYear(); 578 assertTrue(dayDiff <= 0 && dayDiff > -7); 579 assertEquals(date.equals(test), date.getDayOfWeek() == dow); 580 } else { 581 assertFalse(date.getDayOfWeek() == dow); 582 assertSame(month, Month.JANUARY); 583 assertTrue(date.getDayOfMonth() < 7); 584 assertEquals(test.getYear(), 2006); 585 assertSame(test.getMonth(), Month.DECEMBER); 586 assertTrue(test.getDayOfMonth() > 25); 587 } 588 } 589 } 590 } 591 } 592 593 private LocalDate date(int year, Month month, int day) { 594 return LocalDate.of(year, month, day); 595 } 596 597 private LocalDate date(int year, int month, int day) { 598 return LocalDate.of(year, month, day); 599 } 600 601 }