< prev index next >

test/java/time/tck/java/time/TCKLocalDate.java

Print this page


   1 /*
   2  * Copyright (c) 2012, 2015, 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  */


1268 
1269     @Test(expectedExceptions={DateTimeException.class})
1270     public void test_plusWeeks_invalidTooLarge() {
1271         LocalDate.of(Year.MAX_VALUE, 12, 25).plusWeeks(1);
1272     }
1273 
1274     @Test(expectedExceptions={DateTimeException.class})
1275     public void test_plusWeeks_invalidTooSmall() {
1276         LocalDate.of(Year.MIN_VALUE, 1, 7).plusWeeks(-1);
1277     }
1278 
1279     @Test(expectedExceptions={ArithmeticException.class})
1280     public void test_plusWeeks_invalidMaxMinusMax() {
1281         LocalDate.of(Year.MAX_VALUE, 12, 25).plusWeeks(Long.MAX_VALUE);
1282     }
1283 
1284     @Test(expectedExceptions={ArithmeticException.class})
1285     public void test_plusWeeks_invalidMaxMinusMin() {
1286         LocalDate.of(Year.MAX_VALUE, 12, 25).plusWeeks(Long.MIN_VALUE);
1287     }
























1288 
1289     @Test
1290     public void test_plusDays_normal() {
1291         LocalDate t = TEST_2007_07_15.plusDays(1);
1292         assertEquals(t, LocalDate.of(2007, 7, 16));
1293     }
1294 
1295     @Test
1296     public void test_plusDays_overMonths() {
1297         LocalDate t = TEST_2007_07_15.plusDays(62);
1298         assertEquals(t, LocalDate.of(2007, 9, 15));
1299     }
1300 
1301     @Test
1302     public void test_plusDays_overYears() {
1303         LocalDate t = LocalDate.of(2006, 7, 14).plusDays(366);
1304         assertEquals(t, TEST_2007_07_15);
1305     }
1306 
1307     @Test
1308     public void test_plusDays_overLeapYears() {
1309         LocalDate t = TEST_2007_07_15.plusYears(-1).plusDays(365 + 366);
1310         assertEquals(t, LocalDate.of(2008, 7, 15));
1311     }
1312 


   1 /*
   2  * Copyright (c) 2012, 2016, 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  */


1268 
1269     @Test(expectedExceptions={DateTimeException.class})
1270     public void test_plusWeeks_invalidTooLarge() {
1271         LocalDate.of(Year.MAX_VALUE, 12, 25).plusWeeks(1);
1272     }
1273 
1274     @Test(expectedExceptions={DateTimeException.class})
1275     public void test_plusWeeks_invalidTooSmall() {
1276         LocalDate.of(Year.MIN_VALUE, 1, 7).plusWeeks(-1);
1277     }
1278 
1279     @Test(expectedExceptions={ArithmeticException.class})
1280     public void test_plusWeeks_invalidMaxMinusMax() {
1281         LocalDate.of(Year.MAX_VALUE, 12, 25).plusWeeks(Long.MAX_VALUE);
1282     }
1283 
1284     @Test(expectedExceptions={ArithmeticException.class})
1285     public void test_plusWeeks_invalidMaxMinusMin() {
1286         LocalDate.of(Year.MAX_VALUE, 12, 25).plusWeeks(Long.MIN_VALUE);
1287     }
1288     //-----------------------------------------------------------------------
1289     @DataProvider(name="PlusDays")
1290     Object[][] provider_plusDays() {
1291         return new Object[][] {
1292                 {LocalDate.of(2007, 7, 15), 1, LocalDate.of(2007, 7, 16)},
1293                 {LocalDate.of(2007, 7, 15), 17, LocalDate.of(2007, 8, 1)},
1294                 {LocalDate.of(2007, 12, 31), 1, LocalDate.of(2008, 1, 1)},
1295                 {LocalDate.of(2007, 1, 1), 58, LocalDate.of(2007, 2, 28)},
1296                 {LocalDate.of(2007, 1, 1), 59, LocalDate.of(2007, 3, 1)},
1297                 {LocalDate.of(2008, 1, 1), 60, LocalDate.of(2008, 3, 1)},
1298                 {LocalDate.of(2007, 2, 1), 27, LocalDate.of(2007, 2, 28)},
1299                 {LocalDate.of(2007, 2, 1), 28, LocalDate.of(2007, 3, 1)},
1300                 {LocalDate.of(2007, 1, 1), 29, LocalDate.of(2007, 1, 30)},
1301                 {LocalDate.of(2007, 1, 1), 30, LocalDate.of(2007, 1, 31)},
1302                 {LocalDate.of(2007, 1, 15), 13, LocalDate.of(2007, 1, 28)},
1303                 {LocalDate.of(2007, 1, 15), 14, LocalDate.of(2007, 1, 29)},
1304                 {LocalDate.of(2007, 1, 15), 15, LocalDate.of(2007, 1, 30)},
1305                 {LocalDate.of(2007, 1, 15), 16, LocalDate.of(2007, 1, 31)},
1306                 {LocalDate.of(2007, 2, 15), 13, LocalDate.of(2007, 2, 28)},
1307                 {LocalDate.of(2007, 2, 15), 14, LocalDate.of(2007, 3, 1)},
1308                 {LocalDate.of(2007, 2, 15), 15, LocalDate.of(2007, 3, 2)},
1309                 {LocalDate.of(2007, 2, 15), 16, LocalDate.of(2007, 3, 3)},
1310         };
1311     }
1312 
1313     @Test(dataProvider="PlusDays")
1314     public void test_plusDays_normal(LocalDate input, int amountsToAdd, LocalDate expected) {
1315         LocalDate actual = input.plusDays(amountsToAdd);
1316         assertEquals(actual, expected);
1317      }
1318 
1319     @Test
1320     public void test_plusDays_overMonths() {
1321         LocalDate t = TEST_2007_07_15.plusDays(62);
1322         assertEquals(t, LocalDate.of(2007, 9, 15));
1323     }
1324 
1325     @Test
1326     public void test_plusDays_overYears() {
1327         LocalDate t = LocalDate.of(2006, 7, 14).plusDays(366);
1328         assertEquals(t, TEST_2007_07_15);
1329     }
1330 
1331     @Test
1332     public void test_plusDays_overLeapYears() {
1333         LocalDate t = TEST_2007_07_15.plusYears(-1).plusDays(365 + 366);
1334         assertEquals(t, LocalDate.of(2008, 7, 15));
1335     }
1336 


< prev index next >