test/java/time/test/java/time/TestPeriod.java

Print this page




  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 test.java.time;
  61 
  62 import static java.time.temporal.ChronoUnit.DAYS;
  63 import static java.time.temporal.ChronoUnit.HALF_DAYS;
  64 import static java.time.temporal.ChronoUnit.HOURS;
  65 import static java.time.temporal.ChronoUnit.MICROS;
  66 import static java.time.temporal.ChronoUnit.MILLIS;
  67 import static java.time.temporal.ChronoUnit.MINUTES;
  68 import static java.time.temporal.ChronoUnit.MONTHS;
  69 import static java.time.temporal.ChronoUnit.NANOS;
  70 import static java.time.temporal.ChronoUnit.SECONDS;
  71 import static java.time.temporal.ChronoUnit.YEARS;
  72 import static org.testng.Assert.assertEquals;
  73 import static org.testng.Assert.assertSame;
  74 import static org.testng.Assert.assertTrue;
  75 
  76 import java.io.ByteArrayInputStream;
  77 import java.io.ByteArrayOutputStream;
  78 import java.io.ObjectInputStream;
  79 import java.io.ObjectOutputStream;
  80 import java.io.Serializable;
  81 
  82 import java.time.DateTimeException;
  83 import java.time.Duration;
  84 import java.time.LocalDate;
  85 import java.time.LocalTime;
  86 import java.time.Month;
  87 import java.time.Period;
  88 import java.time.temporal.YearMonth;
  89 
  90 import org.testng.annotations.DataProvider;
  91 import org.testng.annotations.Test;
  92 
  93 /**
  94  * Test.
  95  */
  96 @Test
  97 public class TestPeriod extends AbstractTest {
  98 
  99     //-----------------------------------------------------------------------
 100     // basics
 101     //-----------------------------------------------------------------------
 102     public void test_interfaces() {
 103         assertTrue(Serializable.class.isAssignableFrom(Period.class));
 104     }
 105 
 106     @DataProvider(name="serialization")
 107     Object[][] data_serialization() {
 108         return new Object[][] {
 109             {Period.ZERO},
 110             {Period.of(0, DAYS)},
 111             {Period.of(1, DAYS)},
 112             {Period.of(1, 2, 3, 4, 5, 6)},
 113         };
 114     }
 115 
 116     @Test(dataProvider="serialization")
 117     public void test_serialization(Period period) throws Exception {
 118         ByteArrayOutputStream baos = new ByteArrayOutputStream();
 119         ObjectOutputStream oos = new ObjectOutputStream(baos);
 120         oos.writeObject(period);
 121         oos.close();
 122 
 123         ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(
 124                 baos.toByteArray()));
 125         if (period.isZero()) {
 126             assertSame(ois.readObject(), period);
 127         } else {
 128             assertEquals(ois.readObject(), period);
 129         }
 130     }
 131 
 132     @Test
 133     public void test_immutable() {
 134         assertImmutable(Period.class);
 135     }
 136 
 137     //-----------------------------------------------------------------------
 138     // factories
 139     //-----------------------------------------------------------------------
 140     public void factory_zeroSingleton() {
 141         assertSame(Period.ZERO, Period.ZERO);
 142         assertSame(Period.of(0, 0, 0, 0, 0, 0), Period.ZERO);
 143         assertSame(Period.of(0, 0, 0, 0, 0, 0, 0), Period.ZERO);
 144         assertSame(Period.ofDate(0, 0, 0), Period.ZERO);
 145         assertSame(Period.ofTime(0, 0, 0), Period.ZERO);
 146         assertSame(Period.ofTime(0, 0, 0, 0), Period.ZERO);
 147         assertSame(Period.of(0, YEARS), Period.ZERO);
 148         assertSame(Period.of(0, MONTHS), Period.ZERO);
 149         assertSame(Period.of(0, DAYS), Period.ZERO);
 150         assertSame(Period.of(0, HOURS), Period.ZERO);
 151         assertSame(Period.of(0, MINUTES), Period.ZERO);
 152         assertSame(Period.of(0, SECONDS), Period.ZERO);
 153         assertSame(Period.of(0, NANOS), Period.ZERO);
 154     }
 155 
 156     //-----------------------------------------------------------------------
 157     // of(PeriodProvider)
 158     //-----------------------------------------------------------------------
 159     public void factory_of_ints() {
 160         assertPeriod(Period.of(1, 2, 3, 4, 5, 6), 1, 2, 3, 4, 5, 6, 0);
 161         assertPeriod(Period.of(0, 2, 3, 4, 5, 6), 0, 2, 3, 4, 5, 6, 0);
 162         assertPeriod(Period.of(1, 0, 0, 0, 0, 0), 1, 0, 0, 0, 0, 0, 0);
 163         assertPeriod(Period.of(0, 0, 0, 0, 0, 0), 0, 0, 0, 0, 0, 0, 0);
 164         assertPeriod(Period.of(-1, -2, -3, -4, -5, -6), -1, -2, -3, -4, -5, -6, 0);
 165     }
 166 
 167     //-----------------------------------------------------------------------
 168     // ofDate
 169     //-----------------------------------------------------------------------
 170     public void factory_ofDate_ints() {
 171         assertPeriod(Period.ofDate(1, 2, 3), 1, 2, 3, 0, 0, 0, 0);
 172         assertPeriod(Period.ofDate(0, 2, 3), 0, 2, 3, 0, 0, 0, 0);
 173         assertPeriod(Period.ofDate(1, 0, 0), 1, 0, 0, 0, 0, 0, 0);
 174         assertPeriod(Period.ofDate(0, 0, 0), 0, 0, 0, 0, 0, 0, 0);
 175         assertPeriod(Period.ofDate(-1, -2, -3), -1, -2, -3, 0, 0, 0, 0);
 176     }
 177 
 178     //-----------------------------------------------------------------------
 179     // ofTime
 180     //-----------------------------------------------------------------------
 181     public void factory_ofTime_3ints() {
 182         assertPeriod(Period.ofTime(1, 2, 3), 0, 0, 0, 1, 2, 3, 0);
 183         assertPeriod(Period.ofTime(0, 2, 3), 0, 0, 0, 0, 2, 3, 0);
 184         assertPeriod(Period.ofTime(1, 0, 0), 0, 0, 0, 1, 0, 0, 0);
 185         assertPeriod(Period.ofTime(0, 0, 0), 0, 0, 0, 0, 0, 0, 0);
 186         assertPeriod(Period.ofTime(-1, -2, -3), 0, 0, 0, -1, -2, -3, 0);
 187     }
 188 
 189     public void factory_ofTime_4ints() {
 190         assertPeriod(Period.ofTime(1, 2, 3, 4), 0, 0, 0, 1, 2, 3, 4);
 191         assertPeriod(Period.ofTime(0, 2, 3, 4), 0, 0, 0, 0, 2, 3, 4);
 192         assertPeriod(Period.ofTime(1, 0, 0, 0), 0, 0, 0, 1, 0, 0, 0);
 193         assertPeriod(Period.ofTime(0, 0, 0, 0), 0, 0, 0, 0, 0, 0, 0);
 194         assertPeriod(Period.ofTime(-1, -2, -3, -4), 0, 0, 0, -1, -2, -3, -4);
 195     }
 196 
 197     //-----------------------------------------------------------------------
 198     // of one field
 199     //-----------------------------------------------------------------------
 200     public void test_factory_of_intPeriodUnit() {
 201         assertEquals(Period.of(1, YEARS), Period.of(1, YEARS));
 202         assertEquals(Period.of(2, MONTHS), Period.of(2, MONTHS));
 203         assertEquals(Period.of(3, DAYS), Period.of(3, DAYS));
 204 
 205         assertEquals(Period.of(1, HALF_DAYS), Period.of(12, HOURS));
 206         assertEquals(Period.of(Integer.MAX_VALUE / (3600 * 8), HOURS), Period.of(Integer.MAX_VALUE / (3600 * 8), HOURS));
 207         assertEquals(Period.of(-1, MINUTES), Period.of(-1, MINUTES));
 208         assertEquals(Period.of(-2, SECONDS), Period.of(-2, SECONDS));
 209         assertEquals(Period.of(Integer.MIN_VALUE, NANOS), Period.of(Integer.MIN_VALUE, NANOS));
 210         assertEquals(Period.of(2, MILLIS), Period.of(2000000, NANOS));
 211         assertEquals(Period.of(2, MICROS), Period.of(2000, NANOS));
 212     }
 213 
 214     @Test(expectedExceptions=NullPointerException.class)
 215     public void test_factory_of_intPeriodUnit_null() {
 216         Period.of(1, null);
 217     }
 218 
 219     //-----------------------------------------------------------------------
 220     public void factory_years() {
 221         assertPeriod(Period.of(1, YEARS), 1, 0, 0, 0, 0, 0, 0);
 222         assertPeriod(Period.of(0, YEARS), 0, 0, 0, 0, 0, 0, 0);
 223         assertPeriod(Period.of(-1, YEARS), -1, 0, 0, 0, 0, 0, 0);
 224         assertPeriod(Period.of(Integer.MAX_VALUE, YEARS), Integer.MAX_VALUE, 0, 0, 0, 0, 0, 0);
 225         assertPeriod(Period.of(Integer.MIN_VALUE, YEARS), Integer.MIN_VALUE, 0, 0, 0, 0, 0, 0);
 226     }
 227 
 228     public void factory_months() {
 229         assertPeriod(Period.of(1, MONTHS), 0, 1, 0, 0, 0, 0, 0);
 230         assertPeriod(Period.of(0, MONTHS), 0, 0, 0, 0, 0, 0, 0);
 231         assertPeriod(Period.of(-1, MONTHS), 0, -1, 0, 0, 0, 0, 0);
 232         assertPeriod(Period.of(Integer.MAX_VALUE, MONTHS), 0, Integer.MAX_VALUE, 0, 0, 0, 0, 0);
 233         assertPeriod(Period.of(Integer.MIN_VALUE, MONTHS), 0, Integer.MIN_VALUE, 0, 0, 0, 0, 0);
 234     }
 235 
 236     public void factory_days() {
 237         assertPeriod(Period.of(1, DAYS), 0, 0, 1, 0, 0, 0, 0);
 238         assertPeriod(Period.of(0, DAYS), 0, 0, 0, 0, 0, 0, 0);
 239         assertPeriod(Period.of(-1, DAYS), 0, 0, -1, 0, 0, 0, 0);
 240         assertPeriod(Period.of(Integer.MAX_VALUE, DAYS), 0, 0, Integer.MAX_VALUE, 0, 0, 0, 0);
 241         assertPeriod(Period.of(Integer.MIN_VALUE, DAYS), 0, 0, Integer.MIN_VALUE, 0, 0, 0, 0);
 242     }
 243 
 244     public void factory_hours() {
 245         assertPeriod(Period.of(1, HOURS), 0, 0, 0, 1, 0, 0, 0);
 246         assertPeriod(Period.of(0, HOURS), 0, 0, 0, 0, 0, 0, 0);
 247         assertPeriod(Period.of(-1, HOURS), 0, 0, 0, -1, 0, 0, 0);
 248         assertPeriod(Period.of(Integer.MAX_VALUE / (3600 * 8), HOURS), 0, 0, 0, Integer.MAX_VALUE / (3600 * 8), 0, 0, 0);
 249         assertPeriod(Period.of(Integer.MIN_VALUE / (3600 * 8), HOURS), 0, 0, 0, Integer.MIN_VALUE / (3600 * 8), 0, 0, 0);
 250     }
 251 
 252     public void factory_minutes() {
 253         assertPeriod(Period.of(1, MINUTES), 0, 0, 0, 0, 1, 0, 0);
 254         assertPeriod(Period.of(0, MINUTES), 0, 0, 0, 0, 0, 0, 0);
 255         assertPeriod(Period.of(-1, MINUTES), 0, 0, 0, 0, -1, 0, 0);
 256         int val = Integer.MAX_VALUE / (60 * 8);
 257         assertPeriod(Period.of(val, MINUTES), 0, 0, 0,
 258                         (int) (val / 60L),
 259                         (int) (val % 60),
 260                         0, 0);
 261         val = Integer.MIN_VALUE / (60 * 8);
 262         assertPeriod(Period.of(val, MINUTES), 0, 0, 0,
 263                         (int) (val / 60L),
 264                         (int) (val % 60),
 265                         0, 0);
 266     }
 267 
 268     public void factory_seconds() {
 269         assertPeriod(Period.of(1, SECONDS), 0, 0, 0, 0, 0, 1, 0);
 270         assertPeriod(Period.of(0, SECONDS), 0, 0, 0, 0, 0, 0, 0);
 271         assertPeriod(Period.of(-1, SECONDS), 0, 0, 0, 0, 0, -1, 0);
 272         assertPeriod(Period.of(Integer.MAX_VALUE, SECONDS), 0, 0, 0,
 273                         (int) (Integer.MAX_VALUE / 3600L),
 274                         (int) ((Integer.MAX_VALUE / 60L) % 60),
 275                         (int) (Integer.MAX_VALUE % 60),
 276                         0);
 277         assertPeriod(Period.of(Integer.MIN_VALUE, SECONDS), 0, 0, 0,
 278                         (int) (Integer.MIN_VALUE / 3600L),
 279                         (int) ((Integer.MIN_VALUE / 60L) % 60),
 280                         (int) (Integer.MIN_VALUE % 60),
 281                         0);
 282     }
 283 
 284     public void factory_nanos() {
 285         assertPeriod(Period.of(1, NANOS), 0, 0, 0, 0, 0, 0, 1);
 286         assertPeriod(Period.of(0, NANOS), 0, 0, 0, 0, 0, 0, 0);
 287         assertPeriod(Period.of(-1, NANOS), 0, 0, 0, 0, 0, 0, -1);
 288         assertPeriod(Period.of(Long.MAX_VALUE, NANOS), 0, 0, 0,
 289                         (int) (Long.MAX_VALUE / 3600_000_000_000L),
 290                         (int) ((Long.MAX_VALUE / 60_000_000_000L) % 60),
 291                         (int) ((Long.MAX_VALUE / 1_000_000_000L) % 60),
 292                         Long.MAX_VALUE % 1_000_000_000L);
 293         assertPeriod(Period.of(Long.MIN_VALUE, NANOS), 0, 0, 0,
 294                         (int) (Long.MIN_VALUE / 3600_000_000_000L),
 295                         (int) ((Long.MIN_VALUE / 60_000_000_000L) % 60),
 296                         (int) ((Long.MIN_VALUE / 1_000_000_000L) % 60),
 297                         Long.MIN_VALUE % 1_000_000_000L);
 298     }
 299 
 300     //-----------------------------------------------------------------------
 301     // of(Duration)
 302     //-----------------------------------------------------------------------
 303     public void factory_duration() {
 304         assertPeriod(Period.of(Duration.ofSeconds(2, 3)), 0, 0, 0, 0, 0, 2, 3);
 305         assertPeriod(Period.of(Duration.ofSeconds(59, 3)), 0, 0, 0, 0, 0, 59, 3);
 306         assertPeriod(Period.of(Duration.ofSeconds(60, 3)), 0, 0, 0, 0, 1, 0, 3);
 307         assertPeriod(Period.of(Duration.ofSeconds(61, 3)), 0, 0, 0, 0, 1, 1, 3);
 308         assertPeriod(Period.of(Duration.ofSeconds(3599, 3)), 0, 0, 0, 0, 59, 59, 3);
 309         assertPeriod(Period.of(Duration.ofSeconds(3600, 3)), 0, 0, 0, 1, 0, 0, 3);
 310     }
 311 
 312     public void factory_duration_negative() {
 313         assertPeriod(Period.of(Duration.ofSeconds(-2, 3)), 0, 0, 0, 0, 0, -1, -999999997);
 314         assertPeriod(Period.of(Duration.ofSeconds(-59, 3)), 0, 0, 0, 0, 0, -58, -999999997);
 315         assertPeriod(Period.of(Duration.ofSeconds(-60, 3)), 0, 0, 0, 0, 0, -59, -999999997);
 316         assertPeriod(Period.of(Duration.ofSeconds(-60, -3)), 0, 0, 0, 0, -1, 0, -3);
 317 
 318         assertPeriod(Period.of(Duration.ofSeconds(2, -3)), 0, 0, 0, 0, 0, 1, 999999997);
 319     }
 320 
 321     public void factory_duration_big() {
 322         Duration dur = Duration.ofSeconds(Integer.MAX_VALUE, 3);
 323         long secs = Integer.MAX_VALUE;
 324         assertPeriod(Period.of(dur), 0, 0, 0, (int) (secs / 3600), (int) ((secs % 3600) / 60), (int) (secs % 60), 3);
 325     }
 326 
 327     @Test(expectedExceptions=NullPointerException.class)
 328     public void factory_duration_null() {
 329         Period.of((Duration) null);
 330     }
 331 
 332     //-----------------------------------------------------------------------
 333     // between
 334     //-----------------------------------------------------------------------
 335     @DataProvider(name="betweenDates")
 336     Object[][] data_betweenDates() {
 337         return new Object[][] {
 338             {2010, 1, 1, 2010, 1, 1,  0, 0, 0},
 339             {2010, 1, 1, 2010, 1, 2,  0, 0, 1},
 340             {2010, 1, 1, 2010, 2, 1,  0, 1, 0},
 341             {2010, 1, 1, 2010, 2, 2,  0, 1, 1},
 342             {2010, 1, 1, 2011, 1, 1,  1, 0, 0},
 343 
 344             {2010, 6, 12, 2010, 1, 1,  0, -5, -11},
 345             {2010, 6, 12, 2010, 1, 2,  0, -5, -10},
 346             {2010, 6, 12, 2010, 2, 1,  0, -4, -11},
 347             {2010, 6, 12, 2010, 9, 24,  0, 3, 12},
 348 
 349             {2010, 6, 12, 2009, 1, 1,  -1, -5, -11},
 350             {2010, 6, 12, 2009, 1, 2,  -1, -5, -10},
 351             {2010, 6, 12, 2009, 2, 1,  -1, -4, -11},
 352             {2010, 6, 12, 2009, 9, 24,  0, -9, 12},
 353 
 354             {2010, 6, 12, 2008, 1, 1,  -2, -5, -11},
 355             {2010, 6, 12, 2008, 1, 2,  -2, -5, -10},
 356             {2010, 6, 12, 2008, 2, 1,  -2, -4, -11},
 357             {2010, 6, 12, 2008, 9, 24,  -1, -9, 12},
 358         };
 359     }
 360 
 361     @Test(dataProvider="betweenDates")
 362     public void factory_between_LocalDate(int y1, int m1, int d1, int y2, int m2, int d2, int ye, int me, int de) {
 363         LocalDate start = LocalDate.of(y1, m1, d1);
 364         LocalDate end = LocalDate.of(y2, m2, d2);
 365         Period test = Period.between(start, end);
 366         assertPeriod(test, ye, me, de, 0, 0, 0, 0);
 367         //assertEquals(start.plus(test), end);
 368     }
 369 
 370     @DataProvider(name="betweenTimes")
 371     Object[][] data_betweenTimes() {
 372         return new Object[][] {
 373             {12, 30, 40, 12, 30, 45,  0, 0, 5},
 374             {12, 30, 40, 12, 35, 40,  0, 5, 0},
 375             {12, 30, 40, 13, 30, 40,  1, 0, 0},
 376 
 377             {12, 30, 40, 12, 30, 35,  0, 0, -5},
 378             {12, 30, 40, 12, 25, 40,  0, -5, 0},
 379             {12, 30, 40, 11, 30, 40,  -1, 0, 0},
 380         };
 381     }
 382 
 383     @Test(dataProvider="betweenTimes")
 384     public void factory_between_LocalTime(int h1, int m1, int s1, int h2, int m2, int s2, int he, int me, int se) {
 385         LocalTime start = LocalTime.of(h1, m1, s1);
 386         LocalTime end = LocalTime.of(h2, m2, s2);
 387         Period test = Period.between(start, end);
 388         assertPeriod(test, 0, 0, 0, he, me, se, 0);
 389         //assertEquals(start.plus(test), end);
 390     }
 391 
 392     public void factory_between_YearMonth() {
 393         assertPeriod(Period.between(YearMonth.of(2012, 6), YearMonth.of(2013, 7)), 1, 1, 0, 0, 0, 0, 0);
 394         assertPeriod(Period.between(YearMonth.of(2012, 6), YearMonth.of(2013, 3)), 0, 9, 0, 0, 0, 0, 0);
 395         assertPeriod(Period.between(YearMonth.of(2012, 6), YearMonth.of(2011, 7)), 0, -11, 0, 0, 0, 0, 0);
 396     }
 397 
 398     public void factory_between_Month() {
 399         assertPeriod(Period.between(Month.FEBRUARY, Month.MAY), 0, 3, 0, 0, 0, 0, 0);
 400         assertPeriod(Period.between(Month.NOVEMBER, Month.MAY), 0, -6, 0, 0, 0, 0, 0);
 401     }
 402 
 403     //-----------------------------------------------------------------------
 404     // betweenISO
 405     //-----------------------------------------------------------------------
 406     @DataProvider(name="betweenISO")
 407     Object[][] data_betweenISO() {
 408         return new Object[][] {
 409             {2010, 1, 1, 2010, 1, 1, 0, 0, 0},
 410             {2010, 1, 1, 2010, 1, 2, 0, 0, 1},
 411             {2010, 1, 1, 2010, 1, 31, 0, 0, 30},
 412             {2010, 1, 1, 2010, 2, 1, 0, 1, 0},
 413             {2010, 1, 1, 2010, 2, 28, 0, 1, 27},
 414             {2010, 1, 1, 2010, 3, 1, 0, 2, 0},
 415             {2010, 1, 1, 2010, 12, 31, 0, 11, 30},
 416             {2010, 1, 1, 2011, 1, 1, 1, 0, 0},
 417             {2010, 1, 1, 2011, 12, 31, 1, 11, 30},
 418             {2010, 1, 1, 2012, 1, 1, 2, 0, 0},
 419 
 420             {2010, 1, 10, 2010, 1, 1, 0, 0, -9},
 421             {2010, 1, 10, 2010, 1, 2, 0, 0, -8},
 422             {2010, 1, 10, 2010, 1, 9, 0, 0, -1},
 423             {2010, 1, 10, 2010, 1, 10, 0, 0, 0},
 424             {2010, 1, 10, 2010, 1, 11, 0, 0, 1},
 425             {2010, 1, 10, 2010, 1, 31, 0, 0, 21},
 426             {2010, 1, 10, 2010, 2, 1, 0, 0, 22},
 427             {2010, 1, 10, 2010, 2, 9, 0, 0, 30},
 428             {2010, 1, 10, 2010, 2, 10, 0, 1, 0},
 429             {2010, 1, 10, 2010, 2, 28, 0, 1, 18},
 430             {2010, 1, 10, 2010, 3, 1, 0, 1, 19},
 431             {2010, 1, 10, 2010, 3, 9, 0, 1, 27},
 432             {2010, 1, 10, 2010, 3, 10, 0, 2, 0},
 433             {2010, 1, 10, 2010, 12, 31, 0, 11, 21},
 434             {2010, 1, 10, 2011, 1, 1, 0, 11, 22},
 435             {2010, 1, 10, 2011, 1, 9, 0, 11, 30},
 436             {2010, 1, 10, 2011, 1, 10, 1, 0, 0},
 437 
 438             {2010, 3, 30, 2011, 5, 1, 1, 1, 1},
 439             {2010, 4, 30, 2011, 5, 1, 1, 0, 1},
 440 
 441             {2010, 2, 28, 2012, 2, 27, 1, 11, 30},
 442             {2010, 2, 28, 2012, 2, 28, 2, 0, 0},
 443             {2010, 2, 28, 2012, 2, 29, 2, 0, 1},
 444 
 445             {2012, 2, 28, 2014, 2, 27, 1, 11, 30},
 446             {2012, 2, 28, 2014, 2, 28, 2, 0, 0},
 447             {2012, 2, 28, 2014, 3, 1, 2, 0, 1},
 448 
 449             {2012, 2, 29, 2014, 2, 28, 1, 11, 30},
 450             {2012, 2, 29, 2014, 3, 1, 2, 0, 1},
 451             {2012, 2, 29, 2014, 3, 2, 2, 0, 2},
 452 
 453             {2012, 2, 29, 2016, 2, 28, 3, 11, 30},
 454             {2012, 2, 29, 2016, 2, 29, 4, 0, 0},
 455             {2012, 2, 29, 2016, 3, 1, 4, 0, 1},
 456 
 457             {2010, 1, 1, 2009, 12, 31, 0, 0, -1},
 458             {2010, 1, 1, 2009, 12, 30, 0, 0, -2},
 459             {2010, 1, 1, 2009, 12, 2, 0, 0, -30},
 460             {2010, 1, 1, 2009, 12, 1, 0, -1, 0},
 461             {2010, 1, 1, 2009, 11, 30, 0, -1, -1},
 462             {2010, 1, 1, 2009, 11, 2, 0, -1, -29},
 463             {2010, 1, 1, 2009, 11, 1, 0, -2, 0},
 464             {2010, 1, 1, 2009, 1, 2, 0, -11, -30},
 465             {2010, 1, 1, 2009, 1, 1, -1, 0, 0},
 466 
 467             {2010, 1, 15, 2010, 1, 15, 0, 0, 0},
 468             {2010, 1, 15, 2010, 1, 14, 0, 0, -1},
 469             {2010, 1, 15, 2010, 1, 1, 0, 0, -14},
 470             {2010, 1, 15, 2009, 12, 31, 0, 0, -15},
 471             {2010, 1, 15, 2009, 12, 16, 0, 0, -30},
 472             {2010, 1, 15, 2009, 12, 15, 0, -1, 0},
 473             {2010, 1, 15, 2009, 12, 14, 0, -1, -1},
 474 
 475             {2010, 2, 28, 2009, 3, 1, 0, -11, -27},
 476             {2010, 2, 28, 2009, 2, 28, -1, 0, 0},
 477             {2010, 2, 28, 2009, 2, 27, -1, 0, -1},
 478 
 479             {2010, 2, 28, 2008, 2, 29, -1, -11, -28},
 480             {2010, 2, 28, 2008, 2, 28, -2, 0, 0},
 481             {2010, 2, 28, 2008, 2, 27, -2, 0, -1},
 482 
 483             {2012, 2, 29, 2009, 3, 1, -2, -11, -28},
 484             {2012, 2, 29, 2009, 2, 28, -3, 0, -1},
 485             {2012, 2, 29, 2009, 2, 27, -3, 0, -2},
 486 
 487             {2012, 2, 29, 2008, 3, 1, -3, -11, -28},
 488             {2012, 2, 29, 2008, 2, 29, -4, 0, 0},
 489             {2012, 2, 29, 2008, 2, 28, -4, 0, -1},
 490         };
 491     }
 492 
 493     @Test(dataProvider="betweenISO")
 494     public void factory_betweenISO_LocalDate(int y1, int m1, int d1, int y2, int m2, int d2, int ye, int me, int de) {
 495         LocalDate start = LocalDate.of(y1, m1, d1);
 496         LocalDate end = LocalDate.of(y2, m2, d2);
 497         Period test = Period.betweenISO(start, end);
 498         assertPeriod(test, ye, me, de, 0, 0, 0, 0);
 499         //assertEquals(start.plus(test), end);
 500     }
 501 
 502     @Test(expectedExceptions=NullPointerException.class)
 503     public void factory_betweenISO_LocalDate_nullFirst() {
 504         Period.betweenISO((LocalDate) null, LocalDate.of(2010, 1, 1));
 505     }
 506 
 507     @Test(expectedExceptions=NullPointerException.class)
 508     public void factory_betweenISO_LocalDate_nullSecond() {
 509         Period.betweenISO(LocalDate.of(2010, 1, 1), (LocalDate) null);
 510     }
 511 
 512     //-------------------------------------------------------------------------
 513     @Test(expectedExceptions=NullPointerException.class)
 514     public void factory_betweenISO_LocalTime_nullFirst() {
 515         Period.betweenISO((LocalTime) null, LocalTime.of(12, 30));
 516     }
 517 
 518     @Test(expectedExceptions=NullPointerException.class)
 519     public void factory_betweenISO_LocalTime_nullSecond() {
 520         Period.betweenISO(LocalTime.of(12, 30), (LocalTime) null);
 521     }
 522 
 523     //-----------------------------------------------------------------------
 524     // parse()
 525     //-----------------------------------------------------------------------
 526     @Test(dataProvider="toStringAndParse")
 527     public void test_parse(Period test, String expected) {
 528         assertEquals(test, Period.parse(expected));
 529     }
 530 
 531     @Test(expectedExceptions=NullPointerException.class)
 532     public void test_parse_nullText() {
 533         Period.parse((String) null);
 534     }
 535 
 536     //-----------------------------------------------------------------------
 537     // isZero()
 538     //-----------------------------------------------------------------------
 539     public void test_isZero() {
 540         assertEquals(Period.of(1, 2, 3, 4, 5, 6, 7).isZero(), false);
 541         assertEquals(Period.of(1, 2, 3, 0, 0, 0, 0).isZero(), false);
 542         assertEquals(Period.of(0, 0, 0, 4, 5, 6, 7).isZero(), false);
 543         assertEquals(Period.of(1, 0, 0, 0, 0, 0, 0).isZero(), false);
 544         assertEquals(Period.of(0, 2, 0, 0, 0, 0, 0).isZero(), false);
 545         assertEquals(Period.of(0, 0, 3, 0, 0, 0, 0).isZero(), false);
 546         assertEquals(Period.of(0, 0, 0, 4, 0, 0, 0).isZero(), false);
 547         assertEquals(Period.of(0, 0, 0, 0, 5, 0, 0).isZero(), false);
 548         assertEquals(Period.of(0, 0, 0, 0, 0, 6, 0).isZero(), false);
 549         assertEquals(Period.of(0, 0, 0, 0, 0, 0, 7).isZero(), false);
 550         assertEquals(Period.of(0, 0, 0, 0, 0, 0).isZero(), true);
 551     }
 552 
 553     //-----------------------------------------------------------------------
 554     // isPositive()
 555     //-----------------------------------------------------------------------
 556     public void test_isPositive() {
 557         assertEquals(Period.of(1, 2, 3, 4, 5, 6, 7).isPositive(), true);
 558         assertEquals(Period.of(1, 2, 3, 0, 0, 0, 0).isPositive(), true);
 559         assertEquals(Period.of(0, 0, 0, 4, 5, 6, 7).isPositive(), true);
 560         assertEquals(Period.of(1, 0, 0, 0, 0, 0, 0).isPositive(), true);
 561         assertEquals(Period.of(0, 2, 0, 0, 0, 0, 0).isPositive(), true);
 562         assertEquals(Period.of(0, 0, 3, 0, 0, 0, 0).isPositive(), true);
 563         assertEquals(Period.of(0, 0, 0, 4, 0, 0, 0).isPositive(), true);
 564         assertEquals(Period.of(0, 0, 0, 0, 5, 0, 0).isPositive(), true);
 565         assertEquals(Period.of(0, 0, 0, 0, 0, 6, 0).isPositive(), true);
 566         assertEquals(Period.of(0, 0, 0, 0, 0, 0, 7).isPositive(), true);
 567         assertEquals(Period.of(-1, -2, -3, -4, -5, -6, -7).isPositive(), false);
 568         assertEquals(Period.of(-1, -2, 3, 4, -5, -6, -7).isPositive(), false);
 569         assertEquals(Period.of(-1, 0, 0, 0, 0, 0, 0).isPositive(), false);
 570         assertEquals(Period.of(0, -2, 0, 0, 0, 0, 0).isPositive(), false);
 571         assertEquals(Period.of(0, 0, -3, 0, 0, 0, 0).isPositive(), false);
 572         assertEquals(Period.of(0, 0, 0, -4, 0, 0, 0).isPositive(), false);
 573         assertEquals(Period.of(0, 0, 0, 0, -5, 0, 0).isPositive(), false);
 574         assertEquals(Period.of(0, 0, 0, 0, 0, -6, 0).isPositive(), false);
 575         assertEquals(Period.of(0, 0, 0, 0, 0, 0, -7).isPositive(), false);
 576         assertEquals(Period.of(0, 0, 0, 0, 0, 0).isPositive(), false);
 577     }
 578 
 579     //-----------------------------------------------------------------------
 580     // withYears()
 581     //-----------------------------------------------------------------------
 582     public void test_withYears() {
 583         Period test = Period.of(1, 2, 3, 4, 5, 6, 7);
 584         assertPeriod(test.withYears(10), 10, 2, 3, 4, 5, 6, 7);
 585     }
 586 
 587     public void test_withYears_noChange() {
 588         Period test = Period.of(1, 2, 3, 4, 5, 6, 7);
 589         assertSame(test.withYears(1), test);
 590     }
 591 
 592     public void test_withYears_toZero() {
 593         Period test = Period.of(1, YEARS);
 594         assertSame(test.withYears(0), Period.ZERO);
 595     }
 596 
 597     //-----------------------------------------------------------------------
 598     // withMonths()
 599     //-----------------------------------------------------------------------
 600     public void test_withMonths() {
 601         Period test = Period.of(1, 2, 3, 4, 5, 6, 7);
 602         assertPeriod(test.withMonths(10), 1, 10, 3, 4, 5, 6, 7);
 603     }
 604 
 605     public void test_withMonths_noChange() {
 606         Period test = Period.of(1, 2, 3, 4, 5, 6, 7);
 607         assertSame(test.withMonths(2), test);
 608     }
 609 
 610     public void test_withMonths_toZero() {
 611         Period test = Period.of(1, MONTHS);
 612         assertSame(test.withMonths(0), Period.ZERO);
 613     }
 614 
 615     //-----------------------------------------------------------------------
 616     // withDays()
 617     //-----------------------------------------------------------------------
 618     public void test_withDays() {
 619         Period test = Period.of(1, 2, 3, 4, 5, 6, 7);
 620         assertPeriod(test.withDays(10), 1, 2, 10, 4, 5, 6, 7);
 621     }
 622 
 623     public void test_withDays_noChange() {
 624         Period test = Period.of(1, 2, 3, 4, 5, 6, 7);
 625         assertSame(test.withDays(3), test);
 626     }
 627 
 628     public void test_withDays_toZero() {
 629         Period test = Period.of(1, DAYS);
 630         assertSame(test.withDays(0), Period.ZERO);
 631     }
 632 
 633     //-----------------------------------------------------------------------
 634     // withTimeNanos()
 635     //-----------------------------------------------------------------------
 636     public void test_withNanos() {
 637         Period test = Period.of(1, 2, 3, 4, 5, 6, 7);
 638         assertPeriod(test.withTimeNanos(10), 1, 2, 3, 0, 0, 0, 10);
 639     }
 640 
 641     public void test_withNanos_noChange() {
 642         Period test = Period.of(1, 2, 3, 4, 5, 6, 7);
 643         assertSame(test.withTimeNanos(((4 * 60 + 5) * 60 + 6) * 1_000_000_000L + 7), test);
 644     }
 645 
 646     public void test_withNanos_toZero() {
 647         Period test = Period.of(1, NANOS);
 648         assertSame(test.withTimeNanos(0), Period.ZERO);
 649     }
 650 
 651 
 652 
 653     //-----------------------------------------------------------------------
 654     // plusYears()
 655     //-----------------------------------------------------------------------
 656     public void test_plusYears() {
 657         Period test = Period.of(1, 2, 3, 4, 5, 6, 7);
 658         assertPeriod(test.plus(10, YEARS), 11, 2, 3, 4, 5, 6, 7);
 659         assertPeriod(test.plus(Period.of(10, YEARS)), 11, 2, 3, 4, 5, 6, 7);
 660     }
 661 
 662     public void test_plusYears_noChange() {
 663         Period test = Period.of(1, 2, 3, 4, 5, 6, 7);
 664         assertSame(test.plus(0, YEARS), test);
 665         assertPeriod(test.plus(Period.of(0, YEARS)), 1, 2, 3, 4, 5, 6, 7);
 666     }
 667 
 668     public void test_plusYears_toZero() {
 669         Period test = Period.of(-1, YEARS);
 670         assertSame(test.plus(1, YEARS), Period.ZERO);
 671         assertSame(test.plus(Period.of(1, YEARS)), Period.ZERO);
 672     }
 673 
 674     @Test(expectedExceptions=ArithmeticException.class)
 675     public void test_plusYears_overflowTooBig() {
 676         Period test = Period.of(Integer.MAX_VALUE, YEARS);
 677         test.plus(1, YEARS);
 678     }
 679 
 680     @Test(expectedExceptions=ArithmeticException.class)
 681     public void test_plusYears_overflowTooSmall() {
 682         Period test = Period.of(Integer.MIN_VALUE, YEARS);
 683         test.plus(-1, YEARS);
 684     }
 685 
 686     //-----------------------------------------------------------------------
 687     // plusMonths()
 688     //-----------------------------------------------------------------------
 689     public void test_plusMonths() {
 690         Period test = Period.of(1, 2, 3, 4, 5, 6, 7);
 691         assertPeriod(test.plus(10, MONTHS), 1, 12, 3, 4, 5, 6, 7);
 692         assertPeriod(test.plus(Period.of(10, MONTHS)), 1, 12, 3, 4, 5, 6, 7);
 693     }
 694 
 695     public void test_plusMonths_noChange() {
 696         Period test = Period.of(1, 2, 3, 4, 5, 6, 7);
 697         assertSame(test.plus(0, MONTHS), test);
 698         assertEquals(test.plus(Period.of(0, MONTHS)), test);
 699     }
 700 
 701     public void test_plusMonths_toZero() {
 702         Period test = Period.of(-1, MONTHS);
 703         assertSame(test.plus(1, MONTHS), Period.ZERO);
 704         assertSame(test.plus(Period.of(1, MONTHS)), Period.ZERO);
 705     }
 706 
 707     @Test(expectedExceptions=ArithmeticException.class)
 708     public void test_plusMonths_overflowTooBig() {
 709         Period test = Period.of(Integer.MAX_VALUE, MONTHS);
 710         test.plus(1, MONTHS);
 711     }
 712 
 713     @Test(expectedExceptions=ArithmeticException.class)
 714     public void test_plusMonths_overflowTooSmall() {
 715         Period test = Period.of(Integer.MIN_VALUE, MONTHS);
 716         test.plus(-1, MONTHS);
 717     }
 718 
 719     //-----------------------------------------------------------------------
 720     // plusDays()
 721     //-----------------------------------------------------------------------
 722     public void test_plusDays() {
 723         Period test = Period.of(1, 2, 3, 4, 5, 6, 7);
 724         assertPeriod(test.plus(10, DAYS), 1, 2, 13, 4, 5, 6, 7);
 725     }
 726 
 727     public void test_plusDays_noChange() {
 728         Period test = Period.of(1, 2, 3, 4, 5, 6, 7);
 729         assertSame(test.plus(0, DAYS), test);
 730     }
 731 
 732     public void test_plusDays_toZero() {
 733         Period test = Period.of(-1, DAYS);
 734         assertSame(test.plus(1, DAYS), Period.ZERO);
 735     }
 736 
 737     @Test(expectedExceptions=ArithmeticException.class)
 738     public void test_plusDays_overflowTooBig() {
 739         Period test = Period.of(Integer.MAX_VALUE, DAYS);
 740         test.plus(1, DAYS);
 741     }
 742 
 743     @Test(expectedExceptions=ArithmeticException.class)
 744     public void test_plusDays_overflowTooSmall() {
 745         Period test = Period.of(Integer.MIN_VALUE, DAYS);
 746         test.plus(-1, DAYS);
 747     }
 748 
 749     //-----------------------------------------------------------------------
 750     // plusHours()
 751     //-----------------------------------------------------------------------
 752     public void test_plusHours() {
 753         Period test = Period.of(1, 2, 3, 4, 5, 6, 7);
 754         assertPeriod(test.plus(10, HOURS), 1, 2, 3, 14, 5, 6, 7);
 755     }
 756 
 757     public void test_plusHours_noChange() {
 758         Period test = Period.of(1, 2, 3, 4, 5, 6, 7);
 759         assertSame(test.plus(0, HOURS), test);
 760     }
 761 
 762     public void test_plusHours_toZero() {
 763         Period test = Period.of(-1, HOURS);
 764         assertSame(test.plus(1, HOURS), Period.ZERO);
 765     }
 766 
 767     @Test(expectedExceptions=ArithmeticException.class)
 768     public void test_plusHours_overflowTooBig() {
 769         Period test = Period.of(Integer.MAX_VALUE, HOURS);
 770         test.plus(1, HOURS);
 771     }
 772 
 773     @Test(expectedExceptions=ArithmeticException.class)
 774     public void test_plusHours_overflowTooSmall() {
 775         Period test = Period.of(Integer.MIN_VALUE, HOURS);
 776         test.plus(-1, HOURS);
 777     }
 778 
 779     //-----------------------------------------------------------------------
 780     // plusMinutes()
 781     //-----------------------------------------------------------------------
 782     public void test_plusMinutes() {
 783         Period test = Period.of(1, 2, 3, 4, 5, 6, 7);
 784         assertPeriod(test.plus(10, MINUTES), 1, 2, 3, 4, 15, 6, 7);
 785     }
 786 
 787     public void test_plusMinutes_noChange() {
 788         Period test = Period.of(1, 2, 3, 4, 5, 6, 7);
 789         assertSame(test.plus(0, MINUTES), test);
 790     }
 791 
 792     public void test_plusMinutes_toZero() {
 793         Period test = Period.of(-1, MINUTES);
 794         assertSame(test.plus(1, MINUTES), Period.ZERO);
 795     }
 796 
 797     //-----------------------------------------------------------------------
 798     // plusSeconds()
 799     //-----------------------------------------------------------------------
 800     public void test_plusSeconds() {
 801         Period test = Period.of(1, 2, 3, 4, 5, 6, 7);
 802         assertPeriod(test.plus(10, SECONDS), 1, 2, 3, 4, 5, 16, 7);
 803     }
 804 
 805     public void test_plusSeconds_noChange() {
 806         Period test = Period.of(1, 2, 3, 4, 5, 6, 7);
 807         assertSame(test.plus(0, SECONDS), test);
 808     }
 809 
 810     public void test_plusSeconds_toZero() {
 811         Period test = Period.of(-1, SECONDS);
 812         assertSame(test.plus(1, SECONDS), Period.ZERO);
 813     }
 814 
 815     //-----------------------------------------------------------------------
 816     // plusNanos()
 817     //-----------------------------------------------------------------------
 818     public void test_plusNanos() {
 819         Period test = Period.of(1, 2, 3, 4, 5, 6, 7);
 820         assertPeriod(test.plus(10, NANOS), 1, 2, 3, 4, 5, 6, 17);
 821     }
 822 
 823     public void test_plusNanos_noChange() {
 824         Period test = Period.of(1, 2, 3, 4, 5, 6, 7);
 825         assertSame(test.plus(0, NANOS), test);
 826     }
 827 
 828     public void test_plusNanos_toZero() {
 829         Period test = Period.of(-1, NANOS);
 830         assertSame(test.plus(1, NANOS), Period.ZERO);
 831     }
 832 
 833     @Test(expectedExceptions=ArithmeticException.class)
 834     public void test_plusNanos_overflowTooBig() {
 835         Period test = Period.of(Long.MAX_VALUE, NANOS);
 836         test.plus(1, NANOS);
 837     }
 838 
 839     @Test(expectedExceptions=ArithmeticException.class)
 840     public void test_plusNanos_overflowTooSmall() {
 841         Period test = Period.of(Long.MIN_VALUE, NANOS);
 842         test.plus(-1, NANOS);
 843     }
 844 
 845     //-----------------------------------------------------------------------
 846     // minusYears()
 847     //-----------------------------------------------------------------------
 848     public void test_minusYears() {
 849         Period test = Period.of(1, 2, 3, 4, 5, 6, 7);
 850         assertPeriod(test.minus(10, YEARS), -9, 2, 3, 4, 5, 6, 7);
 851     }
 852 
 853     public void test_minusYears_noChange() {
 854         Period test = Period.of(1, 2, 3, 4, 5, 6, 7);
 855         assertSame(test.minus(0, YEARS), test);
 856     }
 857 
 858     public void test_minusYears_toZero() {
 859         Period test = Period.of(1, YEARS);
 860         assertSame(test.minus(1, YEARS), Period.ZERO);
 861     }
 862 
 863     @Test(expectedExceptions=ArithmeticException.class)
 864     public void test_minusYears_overflowTooBig() {
 865         Period test = Period.of(Integer.MAX_VALUE, YEARS);
 866         test.minus(-1, YEARS);
 867     }
 868 
 869     @Test(expectedExceptions=ArithmeticException.class)
 870     public void test_minusYears_overflowTooSmall() {
 871         Period test = Period.of(Integer.MIN_VALUE, YEARS);
 872         test.minus(1, YEARS);
 873     }
 874 
 875     //-----------------------------------------------------------------------
 876     // minusMonths()
 877     //-----------------------------------------------------------------------
 878     public void test_minusMonths() {
 879         Period test = Period.of(1, 2, 3, 4, 5, 6, 7);
 880         assertPeriod(test.minus(10, MONTHS), 1, -8, 3, 4, 5, 6, 7);
 881     }
 882 
 883     public void test_minusMonths_noChange() {
 884         Period test = Period.of(1, 2, 3, 4, 5, 6, 7);
 885         assertSame(test.minus(0, MONTHS), test);
 886     }
 887 
 888     public void test_minusMonths_toZero() {
 889         Period test = Period.of(1, MONTHS);
 890         assertSame(test.minus(1, MONTHS), Period.ZERO);
 891     }
 892 
 893     @Test(expectedExceptions=ArithmeticException.class)
 894     public void test_minusMonths_overflowTooBig() {
 895         Period test = Period.of(Integer.MAX_VALUE, MONTHS);
 896         test.minus(-1, MONTHS);
 897     }
 898 
 899     @Test(expectedExceptions=ArithmeticException.class)
 900     public void test_minusMonths_overflowTooSmall() {
 901         Period test = Period.of(Integer.MIN_VALUE, MONTHS);
 902         test.minus(1, MONTHS);
 903     }
 904 
 905     //-----------------------------------------------------------------------
 906     // minusDays()
 907     //-----------------------------------------------------------------------
 908     public void test_minusDays() {
 909         Period test = Period.of(1, 2, 3, 4, 5, 6, 7);
 910         assertPeriod(test.minus(10, DAYS), 1, 2, -7, 4, 5, 6, 7);
 911     }
 912 
 913     public void test_minusDays_noChange() {
 914         Period test = Period.of(1, 2, 3, 4, 5, 6, 7);
 915         assertSame(test.minus(0, DAYS), test);
 916     }
 917 
 918     public void test_minusDays_toZero() {
 919         Period test = Period.of(1, DAYS);
 920         assertSame(test.minus(1, DAYS), Period.ZERO);
 921     }
 922 
 923     @Test(expectedExceptions=ArithmeticException.class)
 924     public void test_minusDays_overflowTooBig() {
 925         Period test = Period.of(Integer.MAX_VALUE, DAYS);
 926         test.minus(-1, DAYS);
 927     }
 928 
 929     @Test(expectedExceptions=ArithmeticException.class)
 930     public void test_minusDays_overflowTooSmall() {
 931         Period test = Period.of(Integer.MIN_VALUE, DAYS);
 932         test.minus(1, DAYS);
 933     }
 934 
 935     //-----------------------------------------------------------------------
 936     // minusHours()
 937     //-----------------------------------------------------------------------
 938     public void test_minusHours() {
 939         Period test = Period.of(1, 2, 3, 4, 5, 6, 7);
 940         assertPeriod(test.minus(10, HOURS), 1, 2, 3, -5, -54, -53, -999999993);
 941         assertEquals(test.minus(10, HOURS).plus(10, HOURS), test);
 942     }
 943 
 944     public void test_minusHours_noChange() {
 945         Period test = Period.of(1, 2, 3, 4, 5, 6, 7);
 946         assertSame(test.minus(0, HOURS), test);
 947     }
 948 
 949     public void test_minusHours_toZero() {
 950         Period test = Period.of(1, HOURS);
 951         assertSame(test.minus(1, HOURS), Period.ZERO);
 952     }
 953 
 954     @Test(expectedExceptions=ArithmeticException.class)
 955     public void test_minusHours_overflowTooBig() {
 956         Period test = Period.of(Integer.MAX_VALUE, HOURS);
 957         test.minus(-1, HOURS);
 958     }
 959 
 960     @Test(expectedExceptions=ArithmeticException.class)
 961     public void test_minusHours_overflowTooSmall() {
 962         Period test = Period.of(Integer.MIN_VALUE, HOURS);
 963         test.minus(1, HOURS);
 964     }
 965 
 966     //-----------------------------------------------------------------------
 967     // minusMinutes()
 968     //-----------------------------------------------------------------------
 969     public void test_minusMinutes() {
 970         Period test = Period.of(1, 2, 3, 4, 5, 6, 7);
 971         assertPeriod(test.minus(10, MINUTES), 1, 2, 3, 3, 55, 6, 7);
 972         assertEquals(test.minus(10, MINUTES).plus(10, MINUTES), test);
 973     }
 974 
 975     public void test_minusMinutes_noChange() {
 976         Period test = Period.of(1, 2, 3, 4, 5, 6, 7);
 977         assertSame(test.minus(0, MINUTES), test);
 978     }
 979 
 980     public void test_minusMinutes_toZero() {
 981         Period test = Period.of(1, MINUTES);
 982         assertSame(test.minus(1, MINUTES), Period.ZERO);
 983     }
 984 
 985     //-----------------------------------------------------------------------
 986     // minusSeconds()
 987     //-----------------------------------------------------------------------
 988     public void test_minusSeconds() {
 989         Period test = Period.of(1, 2, 3, 4, 5, 6, 7);
 990         assertPeriod(test.minus(10, SECONDS), 1, 2, 3, 4, 4, 56, 7);
 991         assertEquals(test.minus(10, SECONDS).plus(10, SECONDS), test);
 992     }
 993 
 994     public void test_minusSeconds_noChange() {
 995         Period test = Period.of(1, 2, 3, 4, 5, 6, 7);
 996         assertSame(test.minus(0, SECONDS), test);
 997     }
 998 
 999     public void test_minusSeconds_toZero() {
1000         Period test = Period.of(1, SECONDS);
1001         assertSame(test.minus(1, SECONDS), Period.ZERO);
1002     }
1003 
1004     //-----------------------------------------------------------------------
1005     // minusNanos()
1006     //-----------------------------------------------------------------------
1007     public void test_minusNanos() {
1008         Period test = Period.of(1, 2, 3, 4, 5, 6, 7);
1009         assertPeriod(test.minus(10, NANOS), 1, 2, 3, 4, 5, 5, 999999997);
1010     }
1011 
1012     public void test_minusNanos_noChange() {
1013         Period test = Period.of(1, 2, 3, 4, 5, 6, 7);
1014         assertSame(test.minus(0, NANOS), test);
1015     }
1016 
1017     public void test_minusNanos_toZero() {
1018         Period test = Period.of(1, NANOS);
1019         assertSame(test.minus(1, NANOS), Period.ZERO);
1020     }
1021 
1022     @Test(expectedExceptions=ArithmeticException.class)
1023     public void test_minusNanos_overflowTooBig() {
1024         Period test = Period.of(Long.MAX_VALUE, NANOS);
1025         test.minus(-1, NANOS);
1026     }
1027 
1028     @Test(expectedExceptions=ArithmeticException.class)
1029     public void test_minusNanos_overflowTooSmall() {
1030         Period test = Period.of(Long.MIN_VALUE, NANOS);
1031         test.minus(1, NANOS);
1032     }
1033 
1034     //-----------------------------------------------------------------------
1035     // multipliedBy()
1036     //-----------------------------------------------------------------------
1037     public void test_multipliedBy() {
1038         Period test = Period.of(1, 2, 3, 4, 5, 6, 7);
1039         assertPeriod(test.multipliedBy(2), 2, 4, 6, 8, 10, 12, 14);
1040         assertPeriod(test.multipliedBy(-3), -3, -6, -9, -12, -15, -18, -21);
1041     }
1042 
1043     public void test_multipliedBy_zeroBase() {
1044         assertSame(Period.ZERO.multipliedBy(2), Period.ZERO);
1045     }
1046 
1047     public void test_multipliedBy_zero() {
1048         Period test = Period.of(1, 2, 3, 4, 5, 6, 7);
1049         assertSame(test.multipliedBy(0), Period.ZERO);
1050     }
1051 
1052     public void test_multipliedBy_one() {
1053         Period test = Period.of(1, 2, 3, 4, 5, 6, 7);
1054         assertSame(test.multipliedBy(1), test);
1055     }
1056 
1057     @Test(expectedExceptions=ArithmeticException.class)
1058     public void test_multipliedBy_overflowTooBig() {
1059         Period test = Period.of(Integer.MAX_VALUE / 2 + 1, YEARS);
1060         test.multipliedBy(2);
1061     }
1062 
1063     @Test(expectedExceptions=ArithmeticException.class)
1064     public void test_multipliedBy_overflowTooSmall() {
1065         Period test = Period.of(Integer.MIN_VALUE / 2 - 1, YEARS);
1066         test.multipliedBy(2);
1067     }
1068 
1069     //-----------------------------------------------------------------------
1070     // negated()
1071     //-----------------------------------------------------------------------
1072     public void test_negated() {
1073         Period test = Period.of(1, 2, 3, 4, 5, 6, 7);
1074         assertPeriod(test.negated(), -1, -2, -3, -4, -5, -6, -7);
1075     }
1076 
1077     public void test_negated_zero() {
1078         assertSame(Period.ZERO.negated(), Period.ZERO);
1079     }
1080 
1081     public void test_negated_max() {
1082         assertPeriod(Period.of(Integer.MAX_VALUE, YEARS).negated(), -Integer.MAX_VALUE, 0, 0, 0, 0, 0, 0);
1083     }
1084 
1085     @Test(expectedExceptions=ArithmeticException.class)
1086     public void test_negated_overflow() {
1087         Period.of(Integer.MIN_VALUE, YEARS).negated();
1088     }
1089 
1090     //-----------------------------------------------------------------------
1091     // normalizedHoursToDays()
1092     //-----------------------------------------------------------------------
1093     @DataProvider(name="normalizedHoursToDays")
1094     Object[][] data_normalizedHoursToDays() {
1095         return new Object[][] {
1096             {0, 0,  0, 0},
1097             {1, 0,  1, 0},
1098             {-1, 0,  -1, 0},
1099 
1100             {1, 1,  1, 1},
1101             {1, 23,  1, 23},
1102             {1, 24,  2, 0},
1103             {1, 25,  2, 1},
1104 
1105             {1, -1,  0, 23},
1106             {1, -23,  0, 1},
1107             {1, -24,  0, 0},
1108             {1, -25,  0, -1},
1109             {1, -47,  0, -23},
1110             {1, -48,  -1, 0},
1111             {1, -49,  -1, -1},
1112 
1113             {-1, 1,  0, -23},
1114             {-1, 23,  0, -1},
1115             {-1, 24,  0, 0},
1116             {-1, 25,  0, 1},
1117             {-1, 47,  0, 23},
1118             {-1, 48,  1, 0},
1119             {-1, 49,  1, 1},
1120 
1121             {-1, -1,  -1, -1},
1122             {-1, -23,  -1, -23},
1123             {-1, -24,  -2, 0},
1124             {-1, -25,  -2, -1},
1125         };
1126     }
1127 
1128     @Test(dataProvider="normalizedHoursToDays")
1129     public void test_normalizedHoursToDays(int inputDays, int inputHours, int expectedDays, int expectedHours) {
1130         assertPeriod(Period.of(0, 0, inputDays, inputHours, 0, 0, 0).normalizedHoursToDays(), 0, 0, expectedDays, expectedHours, 0, 0, 0);
1131     }
1132 
1133     @Test(dataProvider="normalizedHoursToDays")
1134     public void test_normalizedHoursToDays_yearsMonthsUnaffected(int inputDays, int inputHours, int expectedDays, int expectedHours) {
1135         assertPeriod(Period.of(12, 6, inputDays, inputHours, 0, 0, 0).normalizedHoursToDays(), 12, 6, expectedDays, expectedHours, 0, 0, 0);
1136     }
1137 
1138     @Test(expectedExceptions=ArithmeticException.class)
1139     public void test_normalizedHoursToDays_min() {
1140         Period base = Period.of(0, 0, Integer.MIN_VALUE, -24, 0, 0, 0);
1141         base.normalizedHoursToDays();
1142     }
1143 
1144     @Test(expectedExceptions=ArithmeticException.class)
1145     public void test_normalizedHoursToDays_max() {
1146         Period base = Period.of(0, 0, Integer.MAX_VALUE, 24, 0, 0, 0);
1147         base.normalizedHoursToDays();
1148     }
1149 
1150     //-----------------------------------------------------------------------
1151     // normalizedDaysToHours()
1152     //-----------------------------------------------------------------------
1153     @DataProvider(name="normalizedDaysToHours")
1154     Object[][] data_normalizedDaysToHours() {
1155         return new Object[][] {
1156             {0, 0, 0,  0, 0},
1157 
1158             {1, 0, 0,  24, 0},
1159             {1, 1, 0,  25, 0},
1160             {1, 23, 0,  47, 0},
1161             {1, 24, 0,  48, 0},
1162             {1, 25, 0,  49, 0},
1163             {2, 23, 0,  71, 0},
1164             {2, 24, 0,  72, 0},
1165             {2, 25, 0,  73, 0},
1166 
1167             {1, 0, 0,  24, 0},
1168             {1, -1, 0,  23, 0},
1169             {1, -23, 0,  1, 0},
1170             {1, -24, 0,  0, 0},
1171             {1, -25, 0,  -1, 0},
1172             {2, -23, 0,  25, 0},
1173             {2, -24, 0,  24, 0},
1174             {2, -25, 0,  23, 0},
1175 
1176             {-1, 0, 0,  -24, 0},
1177             {-1, 1, 0,  -23, 0},
1178             {-1, 23, 0,  -1, 0},
1179             {-1, 24, 0,  0, 0},
1180             {-1, 25, 0,  1, 0},
1181             {-2, 23, 0,  -25, 0},
1182             {-2, 24, 0,  -24, 0},
1183             {-2, 25, 0,  -23, 0},
1184 
1185             {-1, 0, 0,  -24, 0},
1186             {-1, -1, 0,  -25, 0},
1187             {-1, -23, 0,  -47, 0},
1188             {-1, -24, 0,  -48, 0},
1189             {-1, -25, 0,  -49, 0},
1190 
1191             // minutes
1192             {1, -1, -1,  22, 59},
1193             {1, -23, -1,  0, 59},
1194             {1, -24, -1,  0, -1},
1195             {1, -25, -1,  -1, -1},
1196             {-1, 1, 1,  -22, -59},
1197             {-1, 23, 1,  0, -59},
1198             {-1, 24, 1,  0, 1},
1199             {-1, 25, 1,  1, 1},
1200         };
1201     }
1202 
1203     @Test(dataProvider="normalizedDaysToHours")
1204     public void test_normalizedDaysToHours(int inputDays, int inputHours, int inputMinutes, int expectedHours, int expectedMinutes) {
1205         assertPeriod(Period.of(0, 0, inputDays, inputHours, inputMinutes, 0).normalizedDaysToHours(), 0, 0, 0, expectedHours, expectedMinutes, 0, 0);
1206     }
1207 
1208     @Test(dataProvider="normalizedDaysToHours")
1209     public void test_normalizedDaysToHours_yearsMonthsUnaffected(int inputDays, int inputHours, int inputMinutes, int expectedHours, int expectedMinutes) {
1210         assertPeriod(Period.of(12, 6, inputDays, inputHours, inputMinutes, 0).normalizedDaysToHours(), 12, 6, 0, expectedHours, expectedMinutes, 0, 0);
1211     }
1212 
1213     @Test(expectedExceptions=ArithmeticException.class)
1214     public void test_normalizedDaysToHours_min() {
1215         Period base = Period.of(0, 0, -1_000, -10_000_000, 0, 0, 0);
1216         base.normalizedDaysToHours();
1217     }
1218 
1219     @Test(expectedExceptions=ArithmeticException.class)
1220     public void test_normalizedDaysToHours_max() {
1221         Period base = Period.of(0, 0, 1_000, 10_000_000, 0, 0, 0);
1222         base.normalizedDaysToHours();
1223     }
1224 
1225     //-----------------------------------------------------------------------
1226     // normalizedMonthsISO()
1227     //-----------------------------------------------------------------------
1228     @DataProvider(name="normalizedMonthsISO")
1229     Object[][] data_normalizedMonthsISO() {
1230         return new Object[][] {
1231             {0, 0,  0, 0},
1232             {1, 0,  1, 0},
1233             {-1, 0,  -1, 0},
1234 
1235             {1, 1,  1, 1},
1236             {1, 2,  1, 2},
1237             {1, 11,  1, 11},
1238             {1, 12,  2, 0},
1239             {1, 13,  2, 1},
1240             {1, 23,  2, 11},
1241             {1, 24,  3, 0},
1242             {1, 25,  3, 1},
1243 
1244             {1, -1,  0, 11},
1245             {1, -2,  0, 10},
1246             {1, -11,  0, 1},
1247             {1, -12,  0, 0},
1248             {1, -13,  0, -1},
1249             {1, -23,  0, -11},
1250             {1, -24,  -1, 0},
1251             {1, -25,  -1, -1},
1252             {1, -35,  -1, -11},
1253             {1, -36,  -2, 0},
1254             {1, -37,  -2, -1},
1255 
1256             {-1, 1,  0, -11},
1257             {-1, 11,  0, -1},
1258             {-1, 12,  0, 0},
1259             {-1, 13,  0, 1},
1260             {-1, 23,  0, 11},
1261             {-1, 24,  1, 0},
1262             {-1, 25,  1, 1},
1263 
1264             {-1, -1,  -1, -1},
1265             {-1, -11,  -1, -11},
1266             {-1, -12,  -2, 0},
1267             {-1, -13,  -2, -1},
1268         };
1269     }
1270 
1271     @Test(dataProvider="normalizedMonthsISO")
1272     public void test_normalizedMonthsISO(int inputYears, int inputMonths, int expectedYears, int expectedMonths) {
1273         assertPeriod(Period.ofDate(inputYears, inputMonths, 0).normalizedMonthsISO(), expectedYears, expectedMonths, 0, 0, 0, 0, 0);
1274     }
1275 
1276     @Test(dataProvider="normalizedMonthsISO")
1277     public void test_normalizedMonthsISO_daysTimeUnaffected(int inputYears, int inputMonths, int expectedYears, int expectedMonths) {
1278         assertPeriod(Period.of(inputYears, inputMonths, 5, 12, 30, 0, 0).normalizedMonthsISO(), expectedYears, expectedMonths, 5, 12, 30, 0, 0);
1279     }
1280 
1281     @Test(expectedExceptions=ArithmeticException.class)
1282     public void test_normalizedMonthsISO_min() {
1283         Period base = Period.ofDate(Integer.MIN_VALUE, -12, 0);
1284         base.normalizedMonthsISO();
1285     }
1286 
1287     @Test(expectedExceptions=ArithmeticException.class)
1288     public void test_normalizedMonthsISO_max() {
1289         Period base = Period.ofDate(Integer.MAX_VALUE, 12, 0);
1290         base.normalizedMonthsISO();
1291     }
1292 
1293     //-----------------------------------------------------------------------
1294     // addTo()
1295     //-----------------------------------------------------------------------
1296     @DataProvider(name="addTo")
1297     Object[][] data_addTo() {
1298         return new Object[][] {
1299             {pymd(0, 0, 0),  date(2012, 6, 30), date(2012, 6, 30)},
1300 
1301             {pymd(1, 0, 0),  date(2012, 6, 10), date(2013, 6, 10)},
1302             {pymd(0, 1, 0),  date(2012, 6, 10), date(2012, 7, 10)},
1303             {pymd(0, 0, 1),  date(2012, 6, 10), date(2012, 6, 11)},
1304 
1305             {pymd(-1, 0, 0),  date(2012, 6, 10), date(2011, 6, 10)},
1306             {pymd(0, -1, 0),  date(2012, 6, 10), date(2012, 5, 10)},
1307             {pymd(0, 0, -1),  date(2012, 6, 10), date(2012, 6, 9)},
1308 
1309             {pymd(1, 2, 3),  date(2012, 6, 27), date(2013, 8, 30)},
1310             {pymd(1, 2, 3),  date(2012, 6, 28), date(2013, 8, 31)},
1311             {pymd(1, 2, 3),  date(2012, 6, 29), date(2013, 9, 1)},
1312             {pymd(1, 2, 3),  date(2012, 6, 30), date(2013, 9, 2)},
1313             {pymd(1, 2, 3),  date(2012, 7, 1), date(2013, 9, 4)},
1314 
1315             {pymd(1, 0, 0),  date(2011, 2, 28), date(2012, 2, 28)},
1316             {pymd(4, 0, 0),  date(2011, 2, 28), date(2015, 2, 28)},
1317             {pymd(1, 0, 0),  date(2012, 2, 29), date(2013, 2, 28)},
1318             {pymd(4, 0, 0),  date(2012, 2, 29), date(2016, 2, 29)},
1319 
1320             {pymd(1, 1, 0),  date(2011, 1, 29), date(2012, 2, 29)},
1321             {pymd(1, 2, 0),  date(2012, 2, 29), date(2013, 4, 29)},
1322         };
1323     }
1324 
1325     @Test(dataProvider="addTo")
1326     public void test_addTo(Period period, LocalDate baseDate, LocalDate expected) {
1327         assertEquals(period.addTo(baseDate), expected);
1328     }
1329 
1330     @Test(dataProvider="addTo")
1331     public void test_addTo_usingLocalDatePlus(Period period, LocalDate baseDate, LocalDate expected) {
1332         assertEquals(baseDate.plus(period), expected);
1333     }
1334 
1335     @Test(expectedExceptions=NullPointerException.class)
1336     public void test_addTo_nullZero() {
1337         Period.ZERO.addTo(null);
1338     }
1339 
1340     @Test(expectedExceptions=NullPointerException.class)
1341     public void test_addTo_nullNonZero() {
1342         Period.of(2, DAYS).addTo(null);
1343     }
1344 
1345     //-----------------------------------------------------------------------
1346     // subtractFrom()
1347     //-----------------------------------------------------------------------
1348     @DataProvider(name="subtractFrom")
1349     Object[][] data_subtractFrom() {
1350         return new Object[][] {
1351             {pymd(0, 0, 0),  date(2012, 6, 30), date(2012, 6, 30)},
1352 
1353             {pymd(1, 0, 0),  date(2012, 6, 10), date(2011, 6, 10)},
1354             {pymd(0, 1, 0),  date(2012, 6, 10), date(2012, 5, 10)},
1355             {pymd(0, 0, 1),  date(2012, 6, 10), date(2012, 6, 9)},
1356 
1357             {pymd(-1, 0, 0),  date(2012, 6, 10), date(2013, 6, 10)},
1358             {pymd(0, -1, 0),  date(2012, 6, 10), date(2012, 7, 10)},
1359             {pymd(0, 0, -1),  date(2012, 6, 10), date(2012, 6, 11)},
1360 
1361             {pymd(1, 2, 3),  date(2012, 8, 30), date(2011, 6, 27)},
1362             {pymd(1, 2, 3),  date(2012, 8, 31), date(2011, 6, 27)},
1363             {pymd(1, 2, 3),  date(2012, 9, 1), date(2011, 6, 28)},
1364             {pymd(1, 2, 3),  date(2012, 9, 2), date(2011, 6, 29)},
1365             {pymd(1, 2, 3),  date(2012, 9, 3), date(2011, 6, 30)},
1366             {pymd(1, 2, 3),  date(2012, 9, 4), date(2011, 7, 1)},
1367 
1368             {pymd(1, 0, 0),  date(2011, 2, 28), date(2010, 2, 28)},
1369             {pymd(4, 0, 0),  date(2011, 2, 28), date(2007, 2, 28)},
1370             {pymd(1, 0, 0),  date(2012, 2, 29), date(2011, 2, 28)},
1371             {pymd(4, 0, 0),  date(2012, 2, 29), date(2008, 2, 29)},
1372 
1373             {pymd(1, 1, 0),  date(2013, 3, 29), date(2012, 2, 29)},
1374             {pymd(1, 2, 0),  date(2012, 2, 29), date(2010, 12, 29)},
1375         };
1376     }
1377 
1378     @Test(dataProvider="subtractFrom")
1379     public void test_subtractFrom(Period period, LocalDate baseDate, LocalDate expected) {
1380         assertEquals(period.subtractFrom(baseDate), expected);
1381     }
1382 
1383     @Test(dataProvider="subtractFrom")
1384     public void test_subtractFrom_usingLocalDateMinus(Period period, LocalDate baseDate, LocalDate expected) {
1385         assertEquals(baseDate.minus(period), expected);
1386     }
1387 
1388     @Test(expectedExceptions=NullPointerException.class)
1389     public void test_subtractFrom_nullZero() {
1390         Period.ZERO.subtractFrom(null);
1391     }
1392 
1393     @Test(expectedExceptions=NullPointerException.class)
1394     public void test_subtractFrom_nullNonZero() {
1395         Period.of(2, DAYS).subtractFrom(null);
1396     }
1397 
1398     //-----------------------------------------------------------------------
1399     // toDuration()
1400     //-----------------------------------------------------------------------
1401     public void test_toDuration() {
1402         assertEquals(Period.ZERO.toDuration(), Duration.of(0, SECONDS));
1403         assertEquals(Period.of(0, 0, 0, 4, 5, 6, 7).toDuration(), Duration.ofSeconds((4 * 60 + 5) * 60L + 6, 7));
1404     }
1405 
1406     public void test_toDuration_calculation() {
1407         assertEquals(Period.of(0, 0, 0, 2, 0, 0, 0).toDuration(), Duration.ofSeconds(2 * 3600));
1408         assertEquals(Period.of(0, 0, 0, 0, 2, 0, 0).toDuration(), Duration.of(120, SECONDS));
1409         assertEquals(Period.of(0, 0, 0, 0, 0, 2, 0).toDuration(), Duration.of(2, SECONDS));
1410 
1411         assertEquals(Period.of(0, 0, 0, 0, 0, 3, 1000000000L - 1).toDuration(), Duration.ofSeconds(3, 999999999));
1412         assertEquals(Period.of(0, 0, 0, 0, 0, 3, 1000000000L).toDuration(), Duration.ofSeconds(4, 0));
1413     }
1414 
1415     public void test_toDuration_negatives() {
1416         assertEquals(Period.of(0, 0, 0, 0, 0, 2, 1).toDuration(), Duration.ofSeconds(2, 1));
1417         assertEquals(Period.of(0, 0, 0, 0, 0, 2, -1).toDuration(), Duration.ofSeconds(1, 999999999));
1418         assertEquals(Period.of(0, 0, 0, 0, 0, -2, 1).toDuration(), Duration.ofSeconds(-2, 1));
1419         assertEquals(Period.of(0, 0, 0, 0, 0, -2, -1).toDuration(), Duration.ofSeconds(-3, 999999999));
1420     }
1421 
1422     @Test(expectedExceptions=DateTimeException.class)
1423     public void test_toDuration_years() {
1424         Period.of(1, 0, 0, 4, 5, 6, 7).toDuration();
1425     }
1426 
1427     @Test(expectedExceptions=DateTimeException.class)
1428     public void test_toDuration_months() {
1429         Period.of(0, 1, 0, 4, 5, 6, 7).toDuration();
1430     }
1431 
1432     @Test(expectedExceptions=DateTimeException.class)
1433     public void test_toDuration_days() {
1434         Duration test = Period.of(0, 0, 1, 4, 5, 6, 7).toDuration();
1435         assertEquals(test, Duration.ofSeconds(101106, 7L));
1436     }
1437 
1438     //-----------------------------------------------------------------------
1439     // equals() / hashCode()
1440     //-----------------------------------------------------------------------
1441     public void test_equals() {
1442         assertEquals(Period.of(1, 0, 0, 0, 0, 0).equals(Period.of(1, YEARS)), true);
1443         assertEquals(Period.of(0, 1, 0, 0, 0, 0).equals(Period.of(1, MONTHS)), true);
1444         assertEquals(Period.of(0, 0, 1, 0, 0, 0).equals(Period.of(1, DAYS)), true);
1445         assertEquals(Period.of(0, 0, 0, 1, 0, 0).equals(Period.of(1, HOURS)), true);
1446         assertEquals(Period.of(0, 0, 0, 0, 1, 0).equals(Period.of(1, MINUTES)), true);
1447         assertEquals(Period.of(0, 0, 0, 0, 0, 1).equals(Period.of(1, SECONDS)), true);
1448         assertEquals(Period.of(1, 2, 3, 0, 0, 0).equals(Period.ofDate(1, 2, 3)), true);
1449         assertEquals(Period.of(0, 0, 0, 1, 2, 3).equals(Period.ofTime(1, 2, 3)), true);
1450         assertEquals(Period.of(1, 2, 3, 4, 5, 6).equals(Period.of(1, 2, 3, 4, 5, 6)), true);
1451 
1452         assertEquals(Period.of(1, YEARS).equals(Period.of(1, YEARS)), true);
1453         assertEquals(Period.of(1, YEARS).equals(Period.of(2, YEARS)), false);
1454 
1455         assertEquals(Period.of(1, MONTHS).equals(Period.of(1, MONTHS)), true);
1456         assertEquals(Period.of(1, MONTHS).equals(Period.of(2, MONTHS)), false);
1457 
1458         assertEquals(Period.of(1, DAYS).equals(Period.of(1, DAYS)), true);
1459         assertEquals(Period.of(1, DAYS).equals(Period.of(2, DAYS)), false);
1460 
1461         assertEquals(Period.of(1, HOURS).equals(Period.of(1, HOURS)), true);
1462         assertEquals(Period.of(1, HOURS).equals(Period.of(2, HOURS)), false);
1463 
1464         assertEquals(Period.of(1, MINUTES).equals(Period.of(1, MINUTES)), true);
1465         assertEquals(Period.of(1, MINUTES).equals(Period.of(2, MINUTES)), false);
1466 
1467         assertEquals(Period.of(1, SECONDS).equals(Period.of(1, SECONDS)), true);
1468         assertEquals(Period.of(1, SECONDS).equals(Period.of(2, SECONDS)), false);
1469 
1470         assertEquals(Period.ofDate(1, 2, 3).equals(Period.ofDate(1, 2, 3)), true);
1471         assertEquals(Period.ofDate(1, 2, 3).equals(Period.ofDate(0, 2, 3)), false);
1472         assertEquals(Period.ofDate(1, 2, 3).equals(Period.ofDate(1, 0, 3)), false);
1473         assertEquals(Period.ofDate(1, 2, 3).equals(Period.ofDate(1, 2, 0)), false);
1474 
1475         assertEquals(Period.ofTime(1, 2, 3).equals(Period.ofTime(1, 2, 3)), true);
1476         assertEquals(Period.ofTime(1, 2, 3).equals(Period.ofTime(0, 2, 3)), false);
1477         assertEquals(Period.ofTime(1, 2, 3).equals(Period.ofTime(1, 0, 3)), false);
1478         assertEquals(Period.ofTime(1, 2, 3).equals(Period.ofTime(1, 2, 0)), false);
1479     }
1480 
1481     public void test_equals_self() {
1482         Period test = Period.of(1, 2, 3, 4, 5, 6);
1483         assertEquals(test.equals(test), true);
1484     }
1485 
1486     public void test_equals_null() {
1487         Period test = Period.of(1, 2, 3, 4, 5, 6);
1488         assertEquals(test.equals(null), false);
1489     }
1490 
1491     public void test_equals_otherClass() {
1492         Period test = Period.of(1, 2, 3, 4, 5, 6);
1493         assertEquals(test.equals(""), false);
1494     }
1495 
1496     //-----------------------------------------------------------------------
1497     public void test_hashCode() {
1498         Period test5 = Period.of(5, DAYS);
1499         Period test6 = Period.of(6, DAYS);
1500         Period test5M = Period.of(5, MONTHS);
1501         Period test5Y = Period.of(5, YEARS);
1502         assertEquals(test5.hashCode() == test5.hashCode(), true);
1503         assertEquals(test5.hashCode() == test6.hashCode(), false);
1504         assertEquals(test5.hashCode() == test5M.hashCode(), false);
1505         assertEquals(test5.hashCode() == test5Y.hashCode(), false);
1506     }
1507 
1508     //-----------------------------------------------------------------------
1509     // toString()
1510     //-----------------------------------------------------------------------
1511     @DataProvider(name="toStringAndParse")
1512     Object[][] data_toString() {
1513         return new Object[][] {
1514             {Period.ZERO, "PT0S"},
1515             {Period.of(0, DAYS), "PT0S"},
1516             {Period.of(1, YEARS), "P1Y"},
1517             {Period.of(1, MONTHS), "P1M"},
1518             {Period.of(1, DAYS), "P1D"},
1519             {Period.of(1, HOURS), "PT1H"},
1520             {Period.of(1, MINUTES), "PT1M"},
1521             {Period.of(1, SECONDS), "PT1S"},
1522             {Period.of(12, SECONDS), "PT12S"},
1523             {Period.of(123, SECONDS), "PT2M3S"},
1524             {Period.of(1234, SECONDS), "PT20M34S"},
1525             {Period.of(-1, SECONDS), "PT-1S"},
1526             {Period.of(-12, SECONDS), "PT-12S"},
1527             {Period.of(-123, SECONDS), "PT-2M-3S"},
1528             {Period.of(-1234, SECONDS), "PT-20M-34S"},
1529             {Period.of(1, 2, 3, 4, 5, 6), "P1Y2M3DT4H5M6S"},
1530             {Period.of(1, 2, 3, 4, 5, 6, 700000000), "P1Y2M3DT4H5M6.7S"},
1531             {Period.of(0, 0, 0, 0, 0, 0, 100000000), "PT0.1S"},
1532             {Period.of(0, 0, 0, 0, 0, 0, -100000000), "PT-0.1S"},
1533             {Period.of(0, 0, 0, 0, 0, 1, -900000000), "PT0.1S"},
1534             {Period.of(0, 0, 0, 0, 0, -1, 900000000), "PT-0.1S"},
1535             {Period.of(0, 0, 0, 0, 0, 1, 100000000), "PT1.1S"},
1536             {Period.of(0, 0, 0, 0, 0, 1, -100000000), "PT0.9S"},
1537             {Period.of(0, 0, 0, 0, 0, -1, 100000000), "PT-0.9S"},
1538             {Period.of(0, 0, 0, 0, 0, -1, -100000000), "PT-1.1S"},
1539             {Period.of(0, 0, 0, 0, 0, 0, 10000000), "PT0.01S"},
1540             {Period.of(0, 0, 0, 0, 0, 0, -10000000), "PT-0.01S"},
1541             {Period.of(0, 0, 0, 0, 0, 0, 1000000), "PT0.001S"},
1542             {Period.of(0, 0, 0, 0, 0, 0, -1000000), "PT-0.001S"},
1543             {Period.of(0, 0, 0, 0, 0, 0, 1000), "PT0.000001S"},
1544             {Period.of(0, 0, 0, 0, 0, 0, -1000), "PT-0.000001S"},
1545             {Period.of(0, 0, 0, 0, 0, 0, 1), "PT0.000000001S"},
1546             {Period.of(0, 0, 0, 0, 0, 0, -1), "PT-0.000000001S"},
1547         };
1548     }
1549 
1550     @Test(groups="tck", dataProvider="toStringAndParse")
1551     public void test_toString(Period input, String expected) {
1552         assertEquals(input.toString(), expected);
1553     }
1554 
1555     //-----------------------------------------------------------------------
1556     private void assertPeriod(Period test, int y, int mo, int d, int h, int mn, int s, long n) {
1557         assertEquals(test.getYears(), y, "years");
1558         assertEquals(test.getMonths(), mo, "months");
1559         assertEquals(test.getDays(), d, "days");
1560         assertEquals(test.getHours(), h, "hours");
1561         assertEquals(test.getMinutes(), mn, "mins");
1562         assertEquals(test.getSeconds(), s, "secs");
1563         assertEquals(test.getNanos(), n, "nanos");
1564         assertEquals(test.getTimeNanos(), (((h * 60L + mn) * 60 + s) * 1_000_000_000L + n), "total nanos");
1565     }
1566 
1567     private static Period pymd(int y, int m, int d) {
1568         return Period.ofDate(y, m, d);
1569     }
1570 
1571     private static LocalDate date(int y, int m, int d) {
1572         return LocalDate.of(y, m, d);
1573     }
1574 
1575 }


  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 test.java.time;
  61 










  62 import static org.testng.Assert.assertEquals;
  63 import static org.testng.Assert.assertSame;

  64 











  65 import java.time.Period;

  66 

  67 import org.testng.annotations.Test;
  68 
  69 /**
  70  * Test.
  71  */
  72 @Test
  73 public class TestPeriod extends AbstractTest {
  74 

































  75     @Test
  76     public void test_immutable() {
  77         assertImmutable(Period.class);
  78     }
  79 
  80     //-----------------------------------------------------------------------
  81     // factories
  82     //-----------------------------------------------------------------------
  83     public void factory_zeroSingleton() {
  84         assertSame(Period.ZERO, Period.ZERO);
  85         assertSame(Period.ofYears(0), Period.ZERO);
  86         assertSame(Period.ofMonths(0), Period.ZERO);
  87         assertSame(Period.ofDays(0), Period.ZERO);
  88         assertSame(Period.of(0, 0, 0), Period.ZERO);
























































































































































































































































































































































































































































































































































































































































































































































































































































































  89     }
  90 
  91     //-----------------------------------------------------------------------
  92     // hashCode()










































































































































































































































































































































































































































































































  93     //-----------------------------------------------------------------------
  94     public void test_hashCode() {
  95         Period test5 = Period.ofDays(5);
  96         Period test6 = Period.ofDays(6);
  97         Period test5M = Period.ofMonths(5);
  98         Period test5Y = Period.ofYears(5);
  99         assertEquals(test5.hashCode() == test5.hashCode(), true);
 100         assertEquals(test5.hashCode() == test6.hashCode(), false);
 101         assertEquals(test5.hashCode() == test5M.hashCode(), false);
 102         assertEquals(test5.hashCode() == test5Y.hashCode(), false);
 103     }
 104 



































































 105 }