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 };
1299 }
1300
1301 @Test(dataProvider="PlusDays")
1302 public void test_plusDays_normal(LocalDate input, int amountsToAdd, LocalDate expected) {
1303 LocalDate actual = input.plusDays(amountsToAdd);
1304 assertEquals(actual, expected);
1305 }
1306
1307 @Test
1308 public void test_plusDays_overMonths() {
1309 LocalDate t = TEST_2007_07_15.plusDays(62);
1310 assertEquals(t, LocalDate.of(2007, 9, 15));
1311 }
1312
1313 @Test
1314 public void test_plusDays_overYears() {
1315 LocalDate t = LocalDate.of(2006, 7, 14).plusDays(366);
1316 assertEquals(t, TEST_2007_07_15);
1317 }
1318
1319 @Test
1320 public void test_plusDays_overLeapYears() {
1321 LocalDate t = TEST_2007_07_15.plusYears(-1).plusDays(365 + 366);
1322 assertEquals(t, LocalDate.of(2008, 7, 15));
1323 }
1324
|