1 /* 2 * Copyright (c) 2012, 2017, 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) 2008-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; 61 62 import static java.time.temporal.ChronoField.AMPM_OF_DAY; 63 import static java.time.temporal.ChronoField.CLOCK_HOUR_OF_AMPM; 64 import static java.time.temporal.ChronoField.CLOCK_HOUR_OF_DAY; 65 import static java.time.temporal.ChronoField.HOUR_OF_AMPM; 66 import static java.time.temporal.ChronoField.HOUR_OF_DAY; 67 import static java.time.temporal.ChronoField.MICRO_OF_DAY; 68 import static java.time.temporal.ChronoField.MICRO_OF_SECOND; 69 import static java.time.temporal.ChronoField.MILLI_OF_DAY; 70 import static java.time.temporal.ChronoField.MILLI_OF_SECOND; 71 import static java.time.temporal.ChronoField.MINUTE_OF_DAY; 72 import static java.time.temporal.ChronoField.MINUTE_OF_HOUR; 73 import static java.time.temporal.ChronoField.NANO_OF_DAY; 74 import static java.time.temporal.ChronoField.NANO_OF_SECOND; 75 import static java.time.temporal.ChronoField.OFFSET_SECONDS; 76 import static java.time.temporal.ChronoField.SECOND_OF_DAY; 77 import static java.time.temporal.ChronoField.SECOND_OF_MINUTE; 78 import static java.time.temporal.ChronoUnit.MONTHS; 79 import static java.time.temporal.ChronoUnit.DAYS; 80 import static java.time.temporal.ChronoUnit.HOURS; 81 import static java.time.temporal.ChronoUnit.MINUTES; 82 import static java.time.temporal.ChronoUnit.MICROS; 83 import static java.time.temporal.ChronoUnit.MILLIS; 84 import static java.time.temporal.ChronoUnit.HALF_DAYS; 85 import static java.time.temporal.ChronoUnit.NANOS; 86 import static java.time.temporal.ChronoUnit.SECONDS; 87 import static org.testng.Assert.assertEquals; 88 import static org.testng.Assert.assertNotNull; 89 import static org.testng.Assert.assertTrue; 90 import static org.testng.Assert.fail; 91 92 import java.time.Clock; 93 import java.time.DateTimeException; 94 import java.time.Instant; 95 import java.time.LocalDate; 96 import java.time.LocalDateTime; 97 import java.time.LocalTime; 98 import java.time.OffsetDateTime; 99 import java.time.OffsetTime; 100 import java.time.Period; 101 import java.time.ZoneId; 102 import java.time.ZoneOffset; 103 import java.time.ZonedDateTime; 104 import java.time.format.DateTimeFormatter; 105 import java.time.format.DateTimeParseException; 106 import java.time.temporal.ChronoField; 107 import java.time.temporal.ChronoUnit; 108 import java.time.temporal.JulianFields; 109 import java.time.temporal.Temporal; 110 import java.time.temporal.TemporalAccessor; 111 import java.time.temporal.TemporalAdjuster; 112 import java.time.temporal.TemporalAmount; 113 import java.time.temporal.TemporalField; 114 import java.time.temporal.TemporalQueries; 115 import java.time.temporal.TemporalQuery; 116 import java.time.temporal.TemporalUnit; 117 import java.util.ArrayList; 118 import java.util.Arrays; 119 import java.util.List; 120 121 import org.testng.annotations.BeforeClass; 122 import org.testng.annotations.DataProvider; 123 import org.testng.annotations.Test; 124 import test.java.time.MockSimplePeriod; 125 126 /** 127 * Test OffsetTime. 128 */ 129 @Test 130 public class TCKOffsetTime extends AbstractDateTimeTest { 131 132 private static final ZoneId ZONE_GAZA = ZoneId.of("Asia/Gaza"); 133 private static final ZoneOffset OFFSET_PONE = ZoneOffset.ofHours(1); 134 private static final ZoneOffset OFFSET_PTWO = ZoneOffset.ofHours(2); 135 private static final ZoneOffset OFFSET_MTWO = ZoneOffset.ofHours(-2); 136 private static final LocalDate DATE = LocalDate.of(2008, 12, 3); 137 138 // Android-changed: This was originally non-static and initialized in @BeforeMethod, 139 // but @BeforeMethod is run after @DataProvider methods are run, so it only worked by accident, 140 // since multiple test methods were run and the first one did not require this value. 141 private static OffsetTime TEST_11_30_59_500_PONE; 142 143 @BeforeClass setUp()144 public static void setUp() { 145 TEST_11_30_59_500_PONE = OffsetTime.of(11, 30, 59, 500, OFFSET_PONE); 146 } 147 148 //----------------------------------------------------------------------- 149 @Override samples()150 protected List<TemporalAccessor> samples() { 151 TemporalAccessor[] array = {TEST_11_30_59_500_PONE, OffsetTime.MIN, OffsetTime.MAX}; 152 return Arrays.asList(array); 153 } 154 155 @Override validFields()156 protected List<TemporalField> validFields() { 157 TemporalField[] array = { 158 NANO_OF_SECOND, 159 NANO_OF_DAY, 160 MICRO_OF_SECOND, 161 MICRO_OF_DAY, 162 MILLI_OF_SECOND, 163 MILLI_OF_DAY, 164 SECOND_OF_MINUTE, 165 SECOND_OF_DAY, 166 MINUTE_OF_HOUR, 167 MINUTE_OF_DAY, 168 CLOCK_HOUR_OF_AMPM, 169 HOUR_OF_AMPM, 170 CLOCK_HOUR_OF_DAY, 171 HOUR_OF_DAY, 172 AMPM_OF_DAY, 173 OFFSET_SECONDS, 174 }; 175 return Arrays.asList(array); 176 } 177 178 @Override invalidFields()179 protected List<TemporalField> invalidFields() { 180 List<TemporalField> list = new ArrayList<>(Arrays.<TemporalField>asList(ChronoField.values())); 181 list.removeAll(validFields()); 182 list.add(JulianFields.JULIAN_DAY); 183 list.add(JulianFields.MODIFIED_JULIAN_DAY); 184 list.add(JulianFields.RATA_DIE); 185 return list; 186 } 187 188 //----------------------------------------------------------------------- 189 // constants 190 //----------------------------------------------------------------------- 191 @Test constant_MIN()192 public void constant_MIN() { 193 check(OffsetTime.MIN, 0, 0, 0, 0, ZoneOffset.MAX); 194 } 195 196 @Test constant_MAX()197 public void constant_MAX() { 198 check(OffsetTime.MAX, 23, 59, 59, 999999999, ZoneOffset.MIN); 199 } 200 201 //----------------------------------------------------------------------- 202 // now() 203 //----------------------------------------------------------------------- 204 @Test now()205 public void now() { 206 final long DELTA = 20_000_000_000L; // 20 seconds of nanos leeway 207 ZonedDateTime nowDT = ZonedDateTime.now(); 208 209 OffsetTime expected = OffsetTime.now(Clock.systemDefaultZone()); 210 OffsetTime test = OffsetTime.now(); 211 long diff = Math.abs(test.toLocalTime().toNanoOfDay() - expected.toLocalTime().toNanoOfDay()); 212 if (diff >= DELTA) { 213 // may be date change 214 expected = OffsetTime.now(Clock.systemDefaultZone()); 215 test = OffsetTime.now(); 216 diff = Math.abs(test.toLocalTime().toNanoOfDay() - expected.toLocalTime().toNanoOfDay()); 217 } 218 assertTrue(diff < DELTA); 219 assertEquals(test.getOffset(), nowDT.getOffset()); 220 } 221 222 //----------------------------------------------------------------------- 223 // now(Clock) 224 //----------------------------------------------------------------------- 225 @Test 226 public void now_Clock_allSecsInDay() { 227 for (int i = 0; i < (2 * 24 * 60 * 60); i++) { 228 Instant instant = Instant.ofEpochSecond(i, 8); 229 Clock clock = Clock.fixed(instant, ZoneOffset.UTC); 230 OffsetTime test = OffsetTime.now(clock); 231 assertEquals(test.getHour(), (i / (60 * 60)) % 24); 232 assertEquals(test.getMinute(), (i / 60) % 60); 233 assertEquals(test.getSecond(), i % 60); 234 assertEquals(test.getNano(), 8); 235 assertEquals(test.getOffset(), ZoneOffset.UTC); 236 } 237 } 238 239 @Test 240 public void now_Clock_beforeEpoch() { 241 for (int i =-1; i >= -(24 * 60 * 60); i--) { 242 Instant instant = Instant.ofEpochSecond(i, 8); 243 Clock clock = Clock.fixed(instant, ZoneOffset.UTC); 244 OffsetTime test = OffsetTime.now(clock); 245 assertEquals(test.getHour(), ((i + 24 * 60 * 60) / (60 * 60)) % 24); 246 assertEquals(test.getMinute(), ((i + 24 * 60 * 60) / 60) % 60); 247 assertEquals(test.getSecond(), (i + 24 * 60 * 60) % 60); 248 assertEquals(test.getNano(), 8); 249 assertEquals(test.getOffset(), ZoneOffset.UTC); 250 } 251 } 252 253 @Test 254 public void now_Clock_offsets() { 255 Instant base = LocalDateTime.of(1970, 1, 1, 12, 0).toInstant(ZoneOffset.UTC); 256 for (int i = -9; i < 15; i++) { 257 ZoneOffset offset = ZoneOffset.ofHours(i); 258 Clock clock = Clock.fixed(base, offset); 259 OffsetTime test = OffsetTime.now(clock); 260 assertEquals(test.getHour(), (12 + i) % 24); 261 assertEquals(test.getMinute(), 0); 262 assertEquals(test.getSecond(), 0); 263 assertEquals(test.getNano(), 0); 264 assertEquals(test.getOffset(), offset); 265 } 266 } 267 268 @Test(expectedExceptions=NullPointerException.class) 269 public void now_Clock_nullZoneId() { 270 OffsetTime.now((ZoneId) null); 271 } 272 273 @Test(expectedExceptions=NullPointerException.class) 274 public void now_Clock_nullClock() { 275 OffsetTime.now((Clock) null); 276 } 277 278 //----------------------------------------------------------------------- 279 // factories 280 //----------------------------------------------------------------------- 281 private void check(OffsetTime test, int h, int m, int s, int n, ZoneOffset offset) { 282 assertEquals(test.toLocalTime(), LocalTime.of(h, m, s, n)); 283 assertEquals(test.getOffset(), offset); 284 285 assertEquals(test.getHour(), h); 286 assertEquals(test.getMinute(), m); 287 assertEquals(test.getSecond(), s); 288 assertEquals(test.getNano(), n); 289 290 assertEquals(test, test); 291 assertEquals(test.hashCode(), test.hashCode()); 292 assertEquals(OffsetTime.of(LocalTime.of(h, m, s, n), offset), test); 293 } 294 295 //----------------------------------------------------------------------- 296 @Test 297 public void factory_intsHMSN() { 298 OffsetTime test = OffsetTime.of(11, 30, 10, 500, OFFSET_PONE); 299 check(test, 11, 30, 10, 500, OFFSET_PONE); 300 } 301 302 //----------------------------------------------------------------------- 303 @Test 304 public void factory_LocalTimeZoneOffset() { 305 LocalTime localTime = LocalTime.of(11, 30, 10, 500); 306 OffsetTime test = OffsetTime.of(localTime, OFFSET_PONE); 307 check(test, 11, 30, 10, 500, OFFSET_PONE); 308 } 309 310 @Test(expectedExceptions=NullPointerException.class) 311 public void factory_LocalTimeZoneOffset_nullTime() { 312 OffsetTime.of((LocalTime) null, OFFSET_PONE); 313 } 314 315 @Test(expectedExceptions=NullPointerException.class) 316 public void factory_LocalTimeZoneOffset_nullOffset() { 317 LocalTime localTime = LocalTime.of(11, 30, 10, 500); 318 OffsetTime.of(localTime, (ZoneOffset) null); 319 } 320 321 //----------------------------------------------------------------------- 322 // ofInstant() 323 //----------------------------------------------------------------------- 324 @Test(expectedExceptions=NullPointerException.class) 325 public void factory_ofInstant_nullInstant() { 326 OffsetTime.ofInstant((Instant) null, ZoneOffset.UTC); 327 } 328 329 @Test(expectedExceptions=NullPointerException.class) 330 public void factory_ofInstant_nullOffset() { 331 Instant instant = Instant.ofEpochSecond(0L); 332 OffsetTime.ofInstant(instant, (ZoneOffset) null); 333 } 334 335 @Test 336 public void factory_ofInstant_allSecsInDay() { 337 for (int i = 0; i < (2 * 24 * 60 * 60); i++) { 338 Instant instant = Instant.ofEpochSecond(i, 8); 339 OffsetTime test = OffsetTime.ofInstant(instant, ZoneOffset.UTC); 340 assertEquals(test.getHour(), (i / (60 * 60)) % 24); 341 assertEquals(test.getMinute(), (i / 60) % 60); 342 assertEquals(test.getSecond(), i % 60); 343 assertEquals(test.getNano(), 8); 344 } 345 } 346 347 @Test 348 public void factory_ofInstant_beforeEpoch() { 349 for (int i =-1; i >= -(24 * 60 * 60); i--) { 350 Instant instant = Instant.ofEpochSecond(i, 8); 351 OffsetTime test = OffsetTime.ofInstant(instant, ZoneOffset.UTC); 352 assertEquals(test.getHour(), ((i + 24 * 60 * 60) / (60 * 60)) % 24); 353 assertEquals(test.getMinute(), ((i + 24 * 60 * 60) / 60) % 60); 354 assertEquals(test.getSecond(), (i + 24 * 60 * 60) % 60); 355 assertEquals(test.getNano(), 8); 356 } 357 } 358 359 //----------------------------------------------------------------------- 360 @Test 361 public void factory_ofInstant_maxYear() { 362 OffsetTime test = OffsetTime.ofInstant(Instant.MAX, ZoneOffset.UTC); 363 assertEquals(test.getHour(), 23); 364 assertEquals(test.getMinute(), 59); 365 assertEquals(test.getSecond(), 59); 366 assertEquals(test.getNano(), 999_999_999); 367 } 368 369 @Test 370 public void factory_ofInstant_minYear() { 371 OffsetTime test = OffsetTime.ofInstant(Instant.MIN, ZoneOffset.UTC); 372 assertEquals(test.getHour(), 0); 373 assertEquals(test.getMinute(), 0); 374 assertEquals(test.getSecond(), 0); 375 assertEquals(test.getNano(), 0); 376 } 377 378 //----------------------------------------------------------------------- 379 // from(TemporalAccessor) 380 //----------------------------------------------------------------------- 381 @Test 382 public void factory_from_TemporalAccessor_OT() { 383 assertEquals(OffsetTime.from(OffsetTime.of(17, 30, 0, 0, OFFSET_PONE)), OffsetTime.of(17, 30, 0, 0, OFFSET_PONE)); 384 } 385 386 @Test 387 public void test_from_TemporalAccessor_ZDT() { 388 ZonedDateTime base = LocalDateTime.of(2007, 7, 15, 11, 30, 59, 500).atZone(OFFSET_PONE); 389 assertEquals(OffsetTime.from(base), TEST_11_30_59_500_PONE); 390 } 391 392 @Test(expectedExceptions=DateTimeException.class) 393 public void factory_from_TemporalAccessor_invalid_noDerive() { 394 OffsetTime.from(LocalDate.of(2007, 7, 15)); 395 } 396 397 @Test(expectedExceptions=NullPointerException.class) 398 public void factory_from_TemporalAccessor_null() { 399 OffsetTime.from((TemporalAccessor) null); 400 } 401 402 //----------------------------------------------------------------------- 403 // parse() 404 //----------------------------------------------------------------------- 405 @Test(dataProvider = "sampleToString") 406 public void factory_parse_validText(int h, int m, int s, int n, String offsetId, String parsable) { 407 OffsetTime t = OffsetTime.parse(parsable); 408 assertNotNull(t, parsable); 409 check(t, h, m, s, n, ZoneOffset.of(offsetId)); 410 } 411 412 @DataProvider(name="sampleBadParse") 413 Object[][] provider_sampleBadParse() { 414 return new Object[][]{ 415 {"00;00"}, 416 {"12-00"}, 417 {"-01:00"}, 418 {"00:00:00-09"}, 419 {"00:00:00,09"}, 420 {"00:00:abs"}, 421 {"11"}, 422 {"11:30"}, 423 {"11:30+01:00[Europe/Paris]"}, 424 }; 425 } 426 427 @Test(dataProvider = "sampleBadParse", expectedExceptions={DateTimeParseException.class}) 428 public void factory_parse_invalidText(String unparsable) { 429 OffsetTime.parse(unparsable); 430 } 431 432 //-----------------------------------------------------------------------s 433 @Test(expectedExceptions={DateTimeParseException.class}) 434 public void factory_parse_illegalHour() { 435 OffsetTime.parse("25:00+01:00"); 436 } 437 438 @Test(expectedExceptions={DateTimeParseException.class}) 439 public void factory_parse_illegalMinute() { 440 OffsetTime.parse("12:60+01:00"); 441 } 442 443 @Test(expectedExceptions={DateTimeParseException.class}) 444 public void factory_parse_illegalSecond() { 445 OffsetTime.parse("12:12:60+01:00"); 446 } 447 448 //----------------------------------------------------------------------- 449 // parse(DateTimeFormatter) 450 //----------------------------------------------------------------------- 451 @Test 452 public void factory_parse_formatter() { 453 DateTimeFormatter f = DateTimeFormatter.ofPattern("H m s XXX"); 454 OffsetTime test = OffsetTime.parse("11 30 0 +01:00", f); 455 assertEquals(test, OffsetTime.of(11, 30, 0, 0, ZoneOffset.ofHours(1))); 456 } 457 458 @Test(expectedExceptions=NullPointerException.class) 459 public void factory_parse_formatter_nullText() { 460 DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d H m s"); 461 OffsetTime.parse((String) null, f); 462 } 463 464 @Test(expectedExceptions=NullPointerException.class) 465 public void factory_parse_formatter_nullFormatter() { 466 OffsetTime.parse("ANY", null); 467 } 468 469 //----------------------------------------------------------------------- 470 // constructor via factory 471 //----------------------------------------------------------------------- 472 @Test(expectedExceptions=NullPointerException.class) 473 public void constructor_nullTime() throws Throwable { 474 OffsetTime.of(null, OFFSET_PONE); 475 } 476 477 @Test(expectedExceptions=NullPointerException.class) 478 public void constructor_nullOffset() throws Throwable { 479 OffsetTime.of(LocalTime.of(11, 30, 0, 0), null); 480 } 481 482 //----------------------------------------------------------------------- 483 // basics 484 //----------------------------------------------------------------------- 485 @DataProvider(name="sampleTimes") 486 Object[][] provider_sampleTimes() { 487 return new Object[][] { 488 {11, 30, 20, 500, OFFSET_PONE}, 489 {11, 0, 0, 0, OFFSET_PONE}, 490 {23, 59, 59, 999999999, OFFSET_PONE}, 491 }; 492 } 493 494 @Test(dataProvider="sampleTimes") 495 public void test_get(int h, int m, int s, int n, ZoneOffset offset) { 496 LocalTime localTime = LocalTime.of(h, m, s, n); 497 OffsetTime a = OffsetTime.of(localTime, offset); 498 499 assertEquals(a.toLocalTime(), localTime); 500 assertEquals(a.getOffset(), offset); 501 assertEquals(a.toString(), localTime.toString() + offset.toString()); 502 assertEquals(a.getHour(), localTime.getHour()); 503 assertEquals(a.getMinute(), localTime.getMinute()); 504 assertEquals(a.getSecond(), localTime.getSecond()); 505 assertEquals(a.getNano(), localTime.getNano()); 506 } 507 508 //----------------------------------------------------------------------- 509 // isSupported(TemporalField) 510 //----------------------------------------------------------------------- 511 @Test 512 public void test_isSupported_TemporalField() { 513 assertEquals(TEST_11_30_59_500_PONE.isSupported((TemporalField) null), false); 514 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.NANO_OF_SECOND), true); 515 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.NANO_OF_DAY), true); 516 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.MICRO_OF_SECOND), true); 517 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.MICRO_OF_DAY), true); 518 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.MILLI_OF_SECOND), true); 519 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.MILLI_OF_DAY), true); 520 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.SECOND_OF_MINUTE), true); 521 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.SECOND_OF_DAY), true); 522 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.MINUTE_OF_HOUR), true); 523 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.MINUTE_OF_DAY), true); 524 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.HOUR_OF_AMPM), true); 525 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.CLOCK_HOUR_OF_AMPM), true); 526 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.HOUR_OF_DAY), true); 527 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.CLOCK_HOUR_OF_DAY), true); 528 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.AMPM_OF_DAY), true); 529 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.DAY_OF_WEEK), false); 530 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH), false); 531 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR), false); 532 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.DAY_OF_MONTH), false); 533 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.DAY_OF_YEAR), false); 534 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.EPOCH_DAY), false); 535 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.ALIGNED_WEEK_OF_MONTH), false); 536 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.ALIGNED_WEEK_OF_YEAR), false); 537 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.MONTH_OF_YEAR), false); 538 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.PROLEPTIC_MONTH), false); 539 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.YEAR), false); 540 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.YEAR_OF_ERA), false); 541 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.ERA), false); 542 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.INSTANT_SECONDS), false); 543 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoField.OFFSET_SECONDS), true); 544 } 545 546 //----------------------------------------------------------------------- 547 // isSupported(TemporalUnit) 548 //----------------------------------------------------------------------- 549 @Test 550 public void test_isSupported_TemporalUnit() { 551 assertEquals(TEST_11_30_59_500_PONE.isSupported((TemporalUnit) null), false); 552 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.NANOS), true); 553 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.MICROS), true); 554 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.MILLIS), true); 555 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.SECONDS), true); 556 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.MINUTES), true); 557 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.HOURS), true); 558 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.HALF_DAYS), true); 559 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.DAYS), false); 560 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.WEEKS), false); 561 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.MONTHS), false); 562 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.YEARS), false); 563 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.DECADES), false); 564 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.CENTURIES), false); 565 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.MILLENNIA), false); 566 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.ERAS), false); 567 assertEquals(TEST_11_30_59_500_PONE.isSupported(ChronoUnit.FOREVER), false); 568 } 569 570 //----------------------------------------------------------------------- 571 // get(TemporalField) 572 //----------------------------------------------------------------------- 573 @Test 574 public void test_get_TemporalField() { 575 OffsetTime test = OffsetTime.of(12, 30, 40, 987654321, OFFSET_PONE); 576 assertEquals(test.get(ChronoField.HOUR_OF_DAY), 12); 577 assertEquals(test.get(ChronoField.MINUTE_OF_HOUR), 30); 578 assertEquals(test.get(ChronoField.SECOND_OF_MINUTE), 40); 579 assertEquals(test.get(ChronoField.NANO_OF_SECOND), 987654321); 580 assertEquals(test.get(ChronoField.HOUR_OF_AMPM), 0); 581 assertEquals(test.get(ChronoField.AMPM_OF_DAY), 1); 582 583 assertEquals(test.get(ChronoField.OFFSET_SECONDS), 3600); 584 } 585 586 @Test 587 public void test_getLong_TemporalField() { 588 OffsetTime test = OffsetTime.of(12, 30, 40, 987654321, OFFSET_PONE); 589 assertEquals(test.getLong(ChronoField.HOUR_OF_DAY), 12); 590 assertEquals(test.getLong(ChronoField.MINUTE_OF_HOUR), 30); 591 assertEquals(test.getLong(ChronoField.SECOND_OF_MINUTE), 40); 592 assertEquals(test.getLong(ChronoField.NANO_OF_SECOND), 987654321); 593 assertEquals(test.getLong(ChronoField.HOUR_OF_AMPM), 0); 594 assertEquals(test.getLong(ChronoField.AMPM_OF_DAY), 1); 595 596 assertEquals(test.getLong(ChronoField.OFFSET_SECONDS), 3600); 597 } 598 599 //----------------------------------------------------------------------- 600 // query(TemporalQuery) 601 //----------------------------------------------------------------------- 602 @DataProvider(name="query") 603 Object[][] data_query() { 604 return new Object[][] { 605 {TEST_11_30_59_500_PONE, TemporalQueries.chronology(), null}, 606 {TEST_11_30_59_500_PONE, TemporalQueries.zoneId(), null}, 607 {TEST_11_30_59_500_PONE, TemporalQueries.precision(), ChronoUnit.NANOS}, 608 {TEST_11_30_59_500_PONE, TemporalQueries.zone(), OFFSET_PONE}, 609 {TEST_11_30_59_500_PONE, TemporalQueries.offset(), OFFSET_PONE}, 610 {TEST_11_30_59_500_PONE, TemporalQueries.localDate(), null}, 611 {TEST_11_30_59_500_PONE, TemporalQueries.localTime(), LocalTime.of(11, 30, 59, 500)}, 612 }; 613 } 614 615 @Test(dataProvider="query") 616 public <T> void test_query(TemporalAccessor temporal, TemporalQuery<T> query, T expected) { 617 assertEquals(temporal.query(query), expected); 618 } 619 620 @Test(dataProvider="query") 621 public <T> void test_queryFrom(TemporalAccessor temporal, TemporalQuery<T> query, T expected) { 622 assertEquals(query.queryFrom(temporal), expected); 623 } 624 625 @Test(expectedExceptions=NullPointerException.class) 626 public void test_query_null() { 627 TEST_11_30_59_500_PONE.query(null); 628 } 629 630 //----------------------------------------------------------------------- 631 // withOffsetSameLocal() 632 //----------------------------------------------------------------------- 633 @Test 634 public void test_withOffsetSameLocal() { 635 OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); 636 OffsetTime test = base.withOffsetSameLocal(OFFSET_PTWO); 637 assertEquals(test.toLocalTime(), base.toLocalTime()); 638 assertEquals(test.getOffset(), OFFSET_PTWO); 639 } 640 641 @Test 642 public void test_withOffsetSameLocal_noChange() { 643 OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); 644 OffsetTime test = base.withOffsetSameLocal(OFFSET_PONE); 645 assertEquals(test, base); 646 } 647 648 @Test(expectedExceptions=NullPointerException.class) 649 public void test_withOffsetSameLocal_null() { 650 OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); 651 base.withOffsetSameLocal(null); 652 } 653 654 //----------------------------------------------------------------------- 655 // withOffsetSameInstant() 656 //----------------------------------------------------------------------- 657 @Test 658 public void test_withOffsetSameInstant() { 659 OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); 660 OffsetTime test = base.withOffsetSameInstant(OFFSET_PTWO); 661 OffsetTime expected = OffsetTime.of(12, 30, 59, 0, OFFSET_PTWO); 662 assertEquals(test, expected); 663 } 664 665 @Test 666 public void test_withOffsetSameInstant_noChange() { 667 OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); 668 OffsetTime test = base.withOffsetSameInstant(OFFSET_PONE); 669 assertEquals(test, base); 670 } 671 672 @Test(expectedExceptions=NullPointerException.class) 673 public void test_withOffsetSameInstant_null() { 674 OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); 675 base.withOffsetSameInstant(null); 676 } 677 678 //----------------------------------------------------------------------- 679 // adjustInto(Temporal) 680 //----------------------------------------------------------------------- 681 @DataProvider(name="adjustInto") 682 Object[][] data_adjustInto() { 683 return new Object[][]{ 684 {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetTime.of(LocalTime.of(1, 1, 1, 100), ZoneOffset.UTC), OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), null}, 685 {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetTime.MAX, OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), null}, 686 {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetTime.MIN, OffsetTime.of(LocalTime.of(23 , 5), OFFSET_PONE), null}, 687 {OffsetTime.MAX, OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetTime.of(OffsetTime.MAX.toLocalTime(), ZoneOffset.ofHours(-18)), null}, 688 {OffsetTime.MIN, OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetTime.of(OffsetTime.MIN.toLocalTime(), ZoneOffset.ofHours(18)), null}, 689 690 691 {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), ZonedDateTime.of(LocalDateTime.of(2012, 3, 4, 1, 1, 1, 100), ZONE_GAZA), ZonedDateTime.of(LocalDateTime.of(2012, 3, 4, 23, 5), ZONE_GAZA), null}, 692 {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetDateTime.of(LocalDateTime.of(2012, 3, 4, 1, 1, 1, 100), ZoneOffset.UTC), OffsetDateTime.of(LocalDateTime.of(2012, 3, 4, 23, 5), OFFSET_PONE), null}, 693 694 {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), LocalDateTime.of(2012, 3, 4, 1, 1, 1, 100), null, DateTimeException.class}, 695 {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), LocalDate.of(2210, 2, 2), null, DateTimeException.class}, 696 {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), LocalTime.of(22, 3, 0), null, DateTimeException.class}, 697 {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), null, null, NullPointerException.class}, 698 699 }; 700 } 701 702 @Test(dataProvider="adjustInto") 703 public void test_adjustInto(OffsetTime test, Temporal temporal, Temporal expected, Class<?> expectedEx) { 704 if (expectedEx == null) { 705 Temporal result = test.adjustInto(temporal); 706 assertEquals(result, expected); 707 } else { 708 try { 709 Temporal result = test.adjustInto(temporal); 710 fail(); 711 } catch (Exception ex) { 712 assertTrue(expectedEx.isInstance(ex)); 713 } 714 } 715 } 716 717 //----------------------------------------------------------------------- 718 // with(WithAdjuster) 719 //----------------------------------------------------------------------- 720 @Test 721 public void test_with_adjustment() { 722 final OffsetTime sample = OffsetTime.of(23, 5, 0, 0, OFFSET_PONE); 723 TemporalAdjuster adjuster = new TemporalAdjuster() { 724 @Override 725 public Temporal adjustInto(Temporal dateTime) { 726 return sample; 727 } 728 }; 729 assertEquals(TEST_11_30_59_500_PONE.with(adjuster), sample); 730 } 731 732 @Test 733 public void test_with_adjustment_LocalTime() { 734 OffsetTime test = TEST_11_30_59_500_PONE.with(LocalTime.of(13, 30)); 735 assertEquals(test, OffsetTime.of(13, 30, 0, 0, OFFSET_PONE)); 736 } 737 738 @Test 739 public void test_with_adjustment_OffsetTime() { 740 OffsetTime test = TEST_11_30_59_500_PONE.with(OffsetTime.of(13, 35, 0, 0, OFFSET_PTWO)); 741 assertEquals(test, OffsetTime.of(13, 35, 0, 0, OFFSET_PTWO)); 742 } 743 744 @Test 745 public void test_with_adjustment_ZoneOffset() { 746 OffsetTime test = TEST_11_30_59_500_PONE.with(OFFSET_PTWO); 747 assertEquals(test, OffsetTime.of(11, 30, 59, 500, OFFSET_PTWO)); 748 } 749 750 @Test 751 public void test_with_adjustment_AmPm() { 752 OffsetTime test = TEST_11_30_59_500_PONE.with(new TemporalAdjuster() { 753 @Override 754 public Temporal adjustInto(Temporal dateTime) { 755 return dateTime.with(HOUR_OF_DAY, 23); 756 } 757 }); 758 assertEquals(test, OffsetTime.of(23, 30, 59, 500, OFFSET_PONE)); 759 } 760 761 @Test(expectedExceptions=NullPointerException.class) 762 public void test_with_adjustment_null() { 763 TEST_11_30_59_500_PONE.with((TemporalAdjuster) null); 764 } 765 766 //----------------------------------------------------------------------- 767 // with(TemporalField, long) 768 //----------------------------------------------------------------------- 769 @Test 770 public void test_with_TemporalField() { 771 OffsetTime test = OffsetTime.of(12, 30, 40, 987654321, OFFSET_PONE); 772 assertEquals(test.with(ChronoField.HOUR_OF_DAY, 15), OffsetTime.of(15, 30, 40, 987654321, OFFSET_PONE)); 773 assertEquals(test.with(ChronoField.MINUTE_OF_HOUR, 50), OffsetTime.of(12, 50, 40, 987654321, OFFSET_PONE)); 774 assertEquals(test.with(ChronoField.SECOND_OF_MINUTE, 50), OffsetTime.of(12, 30, 50, 987654321, OFFSET_PONE)); 775 assertEquals(test.with(ChronoField.NANO_OF_SECOND, 12345), OffsetTime.of(12, 30, 40, 12345, OFFSET_PONE)); 776 assertEquals(test.with(ChronoField.HOUR_OF_AMPM, 6), OffsetTime.of(18, 30, 40, 987654321, OFFSET_PONE)); 777 assertEquals(test.with(ChronoField.AMPM_OF_DAY, 0), OffsetTime.of(0, 30, 40, 987654321, OFFSET_PONE)); 778 779 assertEquals(test.with(ChronoField.OFFSET_SECONDS, 7205), OffsetTime.of(12, 30, 40, 987654321, ZoneOffset.ofHoursMinutesSeconds(2, 0, 5))); 780 } 781 782 @Test(expectedExceptions=NullPointerException.class ) 783 public void test_with_TemporalField_null() { 784 TEST_11_30_59_500_PONE.with((TemporalField) null, 0); 785 } 786 787 @Test(expectedExceptions=DateTimeException.class ) 788 public void test_with_TemporalField_invalidField() { 789 TEST_11_30_59_500_PONE.with(ChronoField.YEAR, 0); 790 } 791 792 //----------------------------------------------------------------------- 793 // withHour() 794 //----------------------------------------------------------------------- 795 @Test 796 public void test_withHour_normal() { 797 OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); 798 OffsetTime test = base.withHour(15); 799 assertEquals(test, OffsetTime.of(15, 30, 59, 0, OFFSET_PONE)); 800 } 801 802 @Test 803 public void test_withHour_noChange() { 804 OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); 805 OffsetTime test = base.withHour(11); 806 assertEquals(test, base); 807 } 808 809 //----------------------------------------------------------------------- 810 // withMinute() 811 //----------------------------------------------------------------------- 812 @Test 813 public void test_withMinute_normal() { 814 OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); 815 OffsetTime test = base.withMinute(15); 816 assertEquals(test, OffsetTime.of(11, 15, 59, 0, OFFSET_PONE)); 817 } 818 819 @Test 820 public void test_withMinute_noChange() { 821 OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); 822 OffsetTime test = base.withMinute(30); 823 assertEquals(test, base); 824 } 825 826 //----------------------------------------------------------------------- 827 // withSecond() 828 //----------------------------------------------------------------------- 829 @Test 830 public void test_withSecond_normal() { 831 OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); 832 OffsetTime test = base.withSecond(15); 833 assertEquals(test, OffsetTime.of(11, 30, 15, 0, OFFSET_PONE)); 834 } 835 836 @Test 837 public void test_withSecond_noChange() { 838 OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); 839 OffsetTime test = base.withSecond(59); 840 assertEquals(test, base); 841 } 842 843 //----------------------------------------------------------------------- 844 // withNano() 845 //----------------------------------------------------------------------- 846 @Test 847 public void test_withNanoOfSecond_normal() { 848 OffsetTime base = OffsetTime.of(11, 30, 59, 1, OFFSET_PONE); 849 OffsetTime test = base.withNano(15); 850 assertEquals(test, OffsetTime.of(11, 30, 59, 15, OFFSET_PONE)); 851 } 852 853 @Test 854 public void test_withNanoOfSecond_noChange() { 855 OffsetTime base = OffsetTime.of(11, 30, 59, 1, OFFSET_PONE); 856 OffsetTime test = base.withNano(1); 857 assertEquals(test, base); 858 } 859 860 //----------------------------------------------------------------------- 861 // truncatedTo(TemporalUnit) 862 //----------------------------------------------------------------------- 863 @Test 864 public void test_truncatedTo_normal() { 865 assertEquals(TEST_11_30_59_500_PONE.truncatedTo(NANOS), TEST_11_30_59_500_PONE); 866 assertEquals(TEST_11_30_59_500_PONE.truncatedTo(SECONDS), TEST_11_30_59_500_PONE.withNano(0)); 867 assertEquals(TEST_11_30_59_500_PONE.truncatedTo(DAYS), TEST_11_30_59_500_PONE.with(LocalTime.MIDNIGHT)); 868 } 869 870 @Test(expectedExceptions=NullPointerException.class) 871 public void test_truncatedTo_null() { 872 TEST_11_30_59_500_PONE.truncatedTo(null); 873 } 874 875 //----------------------------------------------------------------------- 876 // plus(PlusAdjuster) 877 //----------------------------------------------------------------------- 878 @Test 879 public void test_plus_PlusAdjuster() { 880 MockSimplePeriod period = MockSimplePeriod.of(7, ChronoUnit.MINUTES); 881 OffsetTime t = TEST_11_30_59_500_PONE.plus(period); 882 assertEquals(t, OffsetTime.of(11, 37, 59, 500, OFFSET_PONE)); 883 } 884 885 @Test 886 public void test_plus_PlusAdjuster_noChange() { 887 OffsetTime t = TEST_11_30_59_500_PONE.plus(MockSimplePeriod.of(0, SECONDS)); 888 assertEquals(t, TEST_11_30_59_500_PONE); 889 } 890 891 @Test 892 public void test_plus_PlusAdjuster_zero() { 893 OffsetTime t = TEST_11_30_59_500_PONE.plus(Period.ZERO); 894 assertEquals(t, TEST_11_30_59_500_PONE); 895 } 896 897 @Test(expectedExceptions=NullPointerException.class) 898 public void test_plus_PlusAdjuster_null() { 899 TEST_11_30_59_500_PONE.plus((TemporalAmount) null); 900 } 901 902 //----------------------------------------------------------------------- 903 // plusHours() 904 //----------------------------------------------------------------------- 905 @Test 906 public void test_plusHours() { 907 OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); 908 OffsetTime test = base.plusHours(13); 909 assertEquals(test, OffsetTime.of(0, 30, 59, 0, OFFSET_PONE)); 910 } 911 912 @Test 913 public void test_plusHours_zero() { 914 OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); 915 OffsetTime test = base.plusHours(0); 916 assertEquals(test, base); 917 } 918 919 //----------------------------------------------------------------------- 920 // plusMinutes() 921 //----------------------------------------------------------------------- 922 @Test 923 public void test_plusMinutes() { 924 OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); 925 OffsetTime test = base.plusMinutes(30); 926 assertEquals(test, OffsetTime.of(12, 0, 59, 0, OFFSET_PONE)); 927 } 928 929 @Test 930 public void test_plusMinutes_zero() { 931 OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); 932 OffsetTime test = base.plusMinutes(0); 933 assertEquals(test, base); 934 } 935 936 //----------------------------------------------------------------------- 937 // plusSeconds() 938 //----------------------------------------------------------------------- 939 @Test 940 public void test_plusSeconds() { 941 OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); 942 OffsetTime test = base.plusSeconds(1); 943 assertEquals(test, OffsetTime.of(11, 31, 0, 0, OFFSET_PONE)); 944 } 945 946 @Test 947 public void test_plusSeconds_zero() { 948 OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); 949 OffsetTime test = base.plusSeconds(0); 950 assertEquals(test, base); 951 } 952 953 //----------------------------------------------------------------------- 954 // plusNanos() 955 //----------------------------------------------------------------------- 956 @Test 957 public void test_plusNanos() { 958 OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); 959 OffsetTime test = base.plusNanos(1); 960 assertEquals(test, OffsetTime.of(11, 30, 59, 1, OFFSET_PONE)); 961 } 962 963 @Test 964 public void test_plusNanos_zero() { 965 OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); 966 OffsetTime test = base.plusNanos(0); 967 assertEquals(test, base); 968 } 969 970 //----------------------------------------------------------------------- 971 // minus(MinusAdjuster) 972 //----------------------------------------------------------------------- 973 @Test 974 public void test_minus_MinusAdjuster() { 975 MockSimplePeriod period = MockSimplePeriod.of(7, ChronoUnit.MINUTES); 976 OffsetTime t = TEST_11_30_59_500_PONE.minus(period); 977 assertEquals(t, OffsetTime.of(11, 23, 59, 500, OFFSET_PONE)); 978 } 979 980 @Test 981 public void test_minus_MinusAdjuster_noChange() { 982 OffsetTime t = TEST_11_30_59_500_PONE.minus(MockSimplePeriod.of(0, SECONDS)); 983 assertEquals(t, TEST_11_30_59_500_PONE); 984 } 985 986 @Test 987 public void test_minus_MinusAdjuster_zero() { 988 OffsetTime t = TEST_11_30_59_500_PONE.minus(Period.ZERO); 989 assertEquals(t, TEST_11_30_59_500_PONE); 990 } 991 992 @Test(expectedExceptions=NullPointerException.class) 993 public void test_minus_MinusAdjuster_null() { 994 TEST_11_30_59_500_PONE.minus((TemporalAmount) null); 995 } 996 997 //----------------------------------------------------------------------- 998 // minusHours() 999 //----------------------------------------------------------------------- 1000 @Test 1001 public void test_minusHours() { 1002 OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); 1003 OffsetTime test = base.minusHours(-13); 1004 assertEquals(test, OffsetTime.of(0, 30, 59, 0, OFFSET_PONE)); 1005 } 1006 1007 @Test 1008 public void test_minusHours_zero() { 1009 OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); 1010 OffsetTime test = base.minusHours(0); 1011 assertEquals(test, base); 1012 } 1013 1014 //----------------------------------------------------------------------- 1015 // minusMinutes() 1016 //----------------------------------------------------------------------- 1017 @Test 1018 public void test_minusMinutes() { 1019 OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); 1020 OffsetTime test = base.minusMinutes(50); 1021 assertEquals(test, OffsetTime.of(10, 40, 59, 0, OFFSET_PONE)); 1022 } 1023 1024 @Test 1025 public void test_minusMinutes_zero() { 1026 OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); 1027 OffsetTime test = base.minusMinutes(0); 1028 assertEquals(test, base); 1029 } 1030 1031 //----------------------------------------------------------------------- 1032 // minusSeconds() 1033 //----------------------------------------------------------------------- 1034 @Test 1035 public void test_minusSeconds() { 1036 OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); 1037 OffsetTime test = base.minusSeconds(60); 1038 assertEquals(test, OffsetTime.of(11, 29, 59, 0, OFFSET_PONE)); 1039 } 1040 1041 @Test 1042 public void test_minusSeconds_zero() { 1043 OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); 1044 OffsetTime test = base.minusSeconds(0); 1045 assertEquals(test, base); 1046 } 1047 1048 //----------------------------------------------------------------------- 1049 // minusNanos() 1050 //----------------------------------------------------------------------- 1051 @Test 1052 public void test_minusNanos() { 1053 OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); 1054 OffsetTime test = base.minusNanos(1); 1055 assertEquals(test, OffsetTime.of(11, 30, 58, 999999999, OFFSET_PONE)); 1056 } 1057 1058 @Test 1059 public void test_minusNanos_zero() { 1060 OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); 1061 OffsetTime test = base.minusNanos(0); 1062 assertEquals(test, base); 1063 } 1064 1065 //----------------------------------------------------------------------- 1066 // until(Temporal, TemporalUnit) 1067 //----------------------------------------------------------------------- 1068 @DataProvider(name="periodUntilUnit") 1069 Object[][] data_untilUnit() { 1070 return new Object[][] { 1071 {OffsetTime.of(1, 1, 1, 0, OFFSET_PONE), OffsetTime.of(13, 1, 1, 0, OFFSET_PONE), HALF_DAYS, 1}, 1072 {OffsetTime.of(1, 1, 1, 0, OFFSET_PONE), OffsetTime.of(2, 1, 1, 0, OFFSET_PONE), HOURS, 1}, 1073 {OffsetTime.of(1, 1, 1, 0, OFFSET_PONE), OffsetTime.of(2, 1, 1, 0, OFFSET_PONE), MINUTES, 60}, 1074 {OffsetTime.of(1, 1, 1, 0, OFFSET_PONE), OffsetTime.of(2, 1, 1, 0, OFFSET_PONE), SECONDS, 3600}, 1075 {OffsetTime.of(1, 1, 1, 0, OFFSET_PONE), OffsetTime.of(2, 1, 1, 0, OFFSET_PONE), MILLIS, 3600*1000}, 1076 {OffsetTime.of(1, 1, 1, 0, OFFSET_PONE), OffsetTime.of(2, 1, 1, 0, OFFSET_PONE), MICROS, 3600*1000*1000L}, 1077 {OffsetTime.of(1, 1, 1, 0, OFFSET_PONE), OffsetTime.of(2, 1, 1, 0, OFFSET_PONE), NANOS, 3600*1000*1000L*1000}, 1078 1079 {OffsetTime.of(1, 1, 1, 0, OFFSET_PONE), OffsetTime.of(14, 1, 1, 0, OFFSET_PTWO), HALF_DAYS, 1}, 1080 {OffsetTime.of(1, 1, 1, 0, OFFSET_PONE), OffsetTime.of(3, 1, 1, 0, OFFSET_PTWO), HOURS, 1}, 1081 {OffsetTime.of(1, 1, 1, 0, OFFSET_PONE), OffsetTime.of(3, 1, 1, 0, OFFSET_PTWO), MINUTES, 60}, 1082 {OffsetTime.of(1, 1, 1, 0, OFFSET_PONE), OffsetTime.of(3, 1, 1, 0, OFFSET_PTWO), SECONDS, 3600}, 1083 {OffsetTime.of(1, 1, 1, 0, OFFSET_PONE), OffsetTime.of(3, 1, 1, 0, OFFSET_PTWO), MILLIS, 3600*1000}, 1084 {OffsetTime.of(1, 1, 1, 0, OFFSET_PONE), OffsetTime.of(3, 1, 1, 0, OFFSET_PTWO), MICROS, 3600*1000*1000L}, 1085 {OffsetTime.of(1, 1, 1, 0, OFFSET_PONE), OffsetTime.of(3, 1, 1, 0, OFFSET_PTWO), NANOS, 3600*1000*1000L*1000}, 1086 }; 1087 } 1088 1089 @Test(dataProvider="periodUntilUnit") 1090 public void test_until_TemporalUnit(OffsetTime offsetTime1, OffsetTime offsetTime2, TemporalUnit unit, long expected) { 1091 long amount = offsetTime1.until(offsetTime2, unit); 1092 assertEquals(amount, expected); 1093 } 1094 1095 @Test(dataProvider="periodUntilUnit") 1096 public void test_until_TemporalUnit_negated(OffsetTime offsetTime1, OffsetTime offsetTime2, TemporalUnit unit, long expected) { 1097 long amount = offsetTime2.until(offsetTime1, unit); 1098 assertEquals(amount, -expected); 1099 } 1100 1101 @Test(dataProvider="periodUntilUnit") 1102 public void test_until_TemporalUnit_between(OffsetTime offsetTime1, OffsetTime offsetTime2, TemporalUnit unit, long expected) { 1103 long amount = unit.between(offsetTime1, offsetTime2); 1104 assertEquals(amount, expected); 1105 } 1106 1107 @Test 1108 public void test_until_convertedType() { 1109 OffsetTime offsetTime = OffsetTime.of(1, 1, 1, 0, OFFSET_PONE); 1110 OffsetDateTime offsetDateTime = offsetTime.plusSeconds(3).atDate(LocalDate.of(1980, 2, 10)); 1111 assertEquals(offsetTime.until(offsetDateTime, SECONDS), 3); 1112 } 1113 1114 @Test(expectedExceptions=DateTimeException.class) 1115 public void test_until_invalidType() { 1116 OffsetTime offsetTime = OffsetTime.of(1, 1, 1, 0, OFFSET_PONE); 1117 offsetTime.until(LocalDate.of(1980, 2, 10), SECONDS); 1118 } 1119 1120 @Test(expectedExceptions=DateTimeException.class) 1121 public void test_until_invalidTemporalUnit() { 1122 OffsetTime offsetTime1 = OffsetTime.of(1, 1, 1, 0, OFFSET_PONE); 1123 OffsetTime offsetTime2 = OffsetTime.of(2, 1, 1, 0, OFFSET_PONE); 1124 offsetTime1.until(offsetTime2, MONTHS); 1125 } 1126 1127 //----------------------------------------------------------------------- 1128 // format(DateTimeFormatter) 1129 //----------------------------------------------------------------------- 1130 @Test 1131 public void test_format_formatter() { 1132 DateTimeFormatter f = DateTimeFormatter.ofPattern("H m s"); 1133 String t = OffsetTime.of(11, 30, 0, 0, OFFSET_PONE).format(f); 1134 assertEquals(t, "11 30 0"); 1135 } 1136 1137 @Test(expectedExceptions=NullPointerException.class) 1138 public void test_format_formatter_null() { 1139 OffsetTime.of(11, 30, 0, 0, OFFSET_PONE).format(null); 1140 } 1141 1142 //----------------------------------------------------------------------- 1143 // toEpochSecond() 1144 //----------------------------------------------------------------------- 1145 @DataProvider(name="epochSecond") 1146 Object[][] provider_toEpochSecond() { 1147 return new Object[][] { 1148 {OffsetTime.of(0, 0, 0, 0, OFFSET_PTWO).toEpochSecond(LocalDate.of(1970, 1, 1)), -7200L}, 1149 {OffsetTime.of(11, 30, 0, 0, OFFSET_MTWO).toEpochSecond(LocalDate.of(1995, 9, 27)), 812208600L}, 1150 {OffsetTime.of(0, 0, 0, 0, OFFSET_PONE).toEpochSecond(LocalDate.of(1970, 1, 1)), 1151 Instant.ofEpochSecond(-3600).getEpochSecond()}, 1152 {OffsetTime.of(11, 30, 0, 0, OFFSET_PTWO).toEpochSecond(LocalDate.of(1965, 12, 31)), 1153 Instant.ofEpochSecond(-126282600L).getEpochSecond()}, 1154 {OffsetTime.of(11, 30, 0, 0, OFFSET_MTWO).toEpochSecond(LocalDate.of(1970, 1, 1)), 1155 OffsetDateTime.of(LocalDate.of(1970, 1, 1), LocalTime.of(11, 30), OFFSET_MTWO) 1156 .toEpochSecond()}, 1157 }; 1158 } 1159 1160 @Test(dataProvider="epochSecond") 1161 public void test_toEpochSecond(long actual, long expected) { 1162 assertEquals(actual, expected); 1163 } 1164 1165 //----------------------------------------------------------------------- 1166 // compareTo() 1167 //----------------------------------------------------------------------- 1168 @Test 1169 public void test_compareTo_time() { 1170 OffsetTime a = OffsetTime.of(11, 29, 0, 0, OFFSET_PONE); 1171 OffsetTime b = OffsetTime.of(11, 30, 0, 0, OFFSET_PONE); // a is before b due to time 1172 assertEquals(a.compareTo(b) < 0, true); 1173 assertEquals(b.compareTo(a) > 0, true); 1174 assertEquals(a.compareTo(a) == 0, true); 1175 assertEquals(b.compareTo(b) == 0, true); 1176 assertEquals(convertInstant(a).compareTo(convertInstant(b)) < 0, true); 1177 } 1178 1179 @Test 1180 public void test_compareTo_offset() { 1181 OffsetTime a = OffsetTime.of(11, 30, 0, 0, OFFSET_PTWO); 1182 OffsetTime b = OffsetTime.of(11, 30, 0, 0, OFFSET_PONE); // a is before b due to offset 1183 assertEquals(a.compareTo(b) < 0, true); 1184 assertEquals(b.compareTo(a) > 0, true); 1185 assertEquals(a.compareTo(a) == 0, true); 1186 assertEquals(b.compareTo(b) == 0, true); 1187 assertEquals(convertInstant(a).compareTo(convertInstant(b)) < 0, true); 1188 } 1189 1190 @Test 1191 public void test_compareTo_both() { 1192 OffsetTime a = OffsetTime.of(11, 50, 0, 0, OFFSET_PTWO); 1193 OffsetTime b = OffsetTime.of(11, 20, 0, 0, OFFSET_PONE); // a is before b on instant scale 1194 assertEquals(a.compareTo(b) < 0, true); 1195 assertEquals(b.compareTo(a) > 0, true); 1196 assertEquals(a.compareTo(a) == 0, true); 1197 assertEquals(b.compareTo(b) == 0, true); 1198 assertEquals(convertInstant(a).compareTo(convertInstant(b)) < 0, true); 1199 } 1200 1201 @Test 1202 public void test_compareTo_bothNearStartOfDay() { 1203 OffsetTime a = OffsetTime.of(0, 10, 0, 0, OFFSET_PONE); 1204 OffsetTime b = OffsetTime.of(2, 30, 0, 0, OFFSET_PTWO); // a is before b on instant scale 1205 assertEquals(a.compareTo(b) < 0, true); 1206 assertEquals(b.compareTo(a) > 0, true); 1207 assertEquals(a.compareTo(a) == 0, true); 1208 assertEquals(b.compareTo(b) == 0, true); 1209 assertEquals(convertInstant(a).compareTo(convertInstant(b)) < 0, true); 1210 } 1211 1212 @Test 1213 public void test_compareTo_hourDifference() { 1214 OffsetTime a = OffsetTime.of(10, 0, 0, 0, OFFSET_PONE); 1215 OffsetTime b = OffsetTime.of(11, 0, 0, 0, OFFSET_PTWO); // a is before b despite being same time-line time 1216 assertEquals(a.compareTo(b) < 0, true); 1217 assertEquals(b.compareTo(a) > 0, true); 1218 assertEquals(a.compareTo(a) == 0, true); 1219 assertEquals(b.compareTo(b) == 0, true); 1220 assertEquals(convertInstant(a).compareTo(convertInstant(b)) == 0, true); 1221 } 1222 1223 @Test(expectedExceptions=NullPointerException.class) 1224 public void test_compareTo_null() { 1225 OffsetTime a = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); 1226 a.compareTo(null); 1227 } 1228 1229 @Test(expectedExceptions=ClassCastException.class) 1230 @SuppressWarnings({"unchecked", "rawtypes"}) 1231 public void compareToNonOffsetTime() { 1232 Comparable c = TEST_11_30_59_500_PONE; 1233 c.compareTo(new Object()); 1234 } 1235 1236 private Instant convertInstant(OffsetTime ot) { 1237 return DATE.atTime(ot.toLocalTime()).toInstant(ot.getOffset()); 1238 } 1239 1240 //----------------------------------------------------------------------- 1241 // isAfter() / isBefore() / isEqual() 1242 //----------------------------------------------------------------------- 1243 @Test 1244 public void test_isBeforeIsAfterIsEqual1() { 1245 OffsetTime a = OffsetTime.of(11, 30, 58, 0, OFFSET_PONE); 1246 OffsetTime b = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); // a is before b due to time 1247 assertEquals(a.isBefore(b), true); 1248 assertEquals(a.isEqual(b), false); 1249 assertEquals(a.isAfter(b), false); 1250 1251 assertEquals(b.isBefore(a), false); 1252 assertEquals(b.isEqual(a), false); 1253 assertEquals(b.isAfter(a), true); 1254 1255 assertEquals(a.isBefore(a), false); 1256 assertEquals(b.isBefore(b), false); 1257 1258 assertEquals(a.isEqual(a), true); 1259 assertEquals(b.isEqual(b), true); 1260 1261 assertEquals(a.isAfter(a), false); 1262 assertEquals(b.isAfter(b), false); 1263 } 1264 1265 @Test 1266 public void test_isBeforeIsAfterIsEqual1nanos() { 1267 OffsetTime a = OffsetTime.of(11, 30, 59, 3, OFFSET_PONE); 1268 OffsetTime b = OffsetTime.of(11, 30, 59, 4, OFFSET_PONE); // a is before b due to time 1269 assertEquals(a.isBefore(b), true); 1270 assertEquals(a.isEqual(b), false); 1271 assertEquals(a.isAfter(b), false); 1272 1273 assertEquals(b.isBefore(a), false); 1274 assertEquals(b.isEqual(a), false); 1275 assertEquals(b.isAfter(a), true); 1276 1277 assertEquals(a.isBefore(a), false); 1278 assertEquals(b.isBefore(b), false); 1279 1280 assertEquals(a.isEqual(a), true); 1281 assertEquals(b.isEqual(b), true); 1282 1283 assertEquals(a.isAfter(a), false); 1284 assertEquals(b.isAfter(b), false); 1285 } 1286 1287 @Test 1288 public void test_isBeforeIsAfterIsEqual2() { 1289 OffsetTime a = OffsetTime.of(11, 30, 59, 0, OFFSET_PTWO); 1290 OffsetTime b = OffsetTime.of(11, 30, 58, 0, OFFSET_PONE); // a is before b due to offset 1291 assertEquals(a.isBefore(b), true); 1292 assertEquals(a.isEqual(b), false); 1293 assertEquals(a.isAfter(b), false); 1294 1295 assertEquals(b.isBefore(a), false); 1296 assertEquals(b.isEqual(a), false); 1297 assertEquals(b.isAfter(a), true); 1298 1299 assertEquals(a.isBefore(a), false); 1300 assertEquals(b.isBefore(b), false); 1301 1302 assertEquals(a.isEqual(a), true); 1303 assertEquals(b.isEqual(b), true); 1304 1305 assertEquals(a.isAfter(a), false); 1306 assertEquals(b.isAfter(b), false); 1307 } 1308 1309 @Test 1310 public void test_isBeforeIsAfterIsEqual2nanos() { 1311 OffsetTime a = OffsetTime.of(11, 30, 59, 4, ZoneOffset.ofTotalSeconds(OFFSET_PONE.getTotalSeconds() + 1)); 1312 OffsetTime b = OffsetTime.of(11, 30, 59, 3, OFFSET_PONE); // a is before b due to offset 1313 assertEquals(a.isBefore(b), true); 1314 assertEquals(a.isEqual(b), false); 1315 assertEquals(a.isAfter(b), false); 1316 1317 assertEquals(b.isBefore(a), false); 1318 assertEquals(b.isEqual(a), false); 1319 assertEquals(b.isAfter(a), true); 1320 1321 assertEquals(a.isBefore(a), false); 1322 assertEquals(b.isBefore(b), false); 1323 1324 assertEquals(a.isEqual(a), true); 1325 assertEquals(b.isEqual(b), true); 1326 1327 assertEquals(a.isAfter(a), false); 1328 assertEquals(b.isAfter(b), false); 1329 } 1330 1331 @Test 1332 public void test_isBeforeIsAfterIsEqual_instantComparison() { 1333 OffsetTime a = OffsetTime.of(11, 30, 59, 0, OFFSET_PTWO); 1334 OffsetTime b = OffsetTime.of(10, 30, 59, 0, OFFSET_PONE); // a is same instant as b 1335 assertEquals(a.isBefore(b), false); 1336 assertEquals(a.isEqual(b), true); 1337 assertEquals(a.isAfter(b), false); 1338 1339 assertEquals(b.isBefore(a), false); 1340 assertEquals(b.isEqual(a), true); 1341 assertEquals(b.isAfter(a), false); 1342 1343 assertEquals(a.isBefore(a), false); 1344 assertEquals(b.isBefore(b), false); 1345 1346 assertEquals(a.isEqual(a), true); 1347 assertEquals(b.isEqual(b), true); 1348 1349 assertEquals(a.isAfter(a), false); 1350 assertEquals(b.isAfter(b), false); 1351 } 1352 1353 @Test(expectedExceptions=NullPointerException.class) 1354 public void test_isBefore_null() { 1355 OffsetTime a = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); 1356 a.isBefore(null); 1357 } 1358 1359 @Test(expectedExceptions=NullPointerException.class) 1360 public void test_isAfter_null() { 1361 OffsetTime a = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); 1362 a.isAfter(null); 1363 } 1364 1365 @Test(expectedExceptions=NullPointerException.class) 1366 public void test_isEqual_null() { 1367 OffsetTime a = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE); 1368 a.isEqual(null); 1369 } 1370 1371 //----------------------------------------------------------------------- 1372 // equals() / hashCode() 1373 //----------------------------------------------------------------------- 1374 @Test(dataProvider="sampleTimes") 1375 public void test_equals_true(int h, int m, int s, int n, ZoneOffset ignored) { 1376 OffsetTime a = OffsetTime.of(h, m, s, n, OFFSET_PONE); 1377 OffsetTime b = OffsetTime.of(h, m, s, n, OFFSET_PONE); 1378 assertEquals(a.equals(b), true); 1379 assertEquals(a.hashCode() == b.hashCode(), true); 1380 } 1381 @Test(dataProvider="sampleTimes") 1382 public void test_equals_false_hour_differs(int h, int m, int s, int n, ZoneOffset ignored) { 1383 h = (h == 23 ? 22 : h); 1384 OffsetTime a = OffsetTime.of(h, m, s, n, OFFSET_PONE); 1385 OffsetTime b = OffsetTime.of(h + 1, m, s, n, OFFSET_PONE); 1386 assertEquals(a.equals(b), false); 1387 } 1388 @Test(dataProvider="sampleTimes") 1389 public void test_equals_false_minute_differs(int h, int m, int s, int n, ZoneOffset ignored) { 1390 m = (m == 59 ? 58 : m); 1391 OffsetTime a = OffsetTime.of(h, m, s, n, OFFSET_PONE); 1392 OffsetTime b = OffsetTime.of(h, m + 1, s, n, OFFSET_PONE); 1393 assertEquals(a.equals(b), false); 1394 } 1395 @Test(dataProvider="sampleTimes") 1396 public void test_equals_false_second_differs(int h, int m, int s, int n, ZoneOffset ignored) { 1397 s = (s == 59 ? 58 : s); 1398 OffsetTime a = OffsetTime.of(h, m, s, n, OFFSET_PONE); 1399 OffsetTime b = OffsetTime.of(h, m, s + 1, n, OFFSET_PONE); 1400 assertEquals(a.equals(b), false); 1401 } 1402 @Test(dataProvider="sampleTimes") 1403 public void test_equals_false_nano_differs(int h, int m, int s, int n, ZoneOffset ignored) { 1404 n = (n == 999999999 ? 999999998 : n); 1405 OffsetTime a = OffsetTime.of(h, m, s, n, OFFSET_PONE); 1406 OffsetTime b = OffsetTime.of(h, m, s, n + 1, OFFSET_PONE); 1407 assertEquals(a.equals(b), false); 1408 } 1409 @Test(dataProvider="sampleTimes") 1410 public void test_equals_false_offset_differs(int h, int m, int s, int n, ZoneOffset ignored) { 1411 OffsetTime a = OffsetTime.of(h, m, s, n, OFFSET_PONE); 1412 OffsetTime b = OffsetTime.of(h, m, s, n, OFFSET_PTWO); 1413 assertEquals(a.equals(b), false); 1414 } 1415 1416 @Test 1417 public void test_equals_itself_true() { 1418 assertEquals(TEST_11_30_59_500_PONE.equals(TEST_11_30_59_500_PONE), true); 1419 } 1420 1421 @Test 1422 public void test_equals_string_false() { 1423 assertEquals(TEST_11_30_59_500_PONE.equals("2007-07-15"), false); 1424 } 1425 1426 @Test 1427 public void test_equals_null_false() { 1428 assertEquals(TEST_11_30_59_500_PONE.equals(null), false); 1429 } 1430 1431 //----------------------------------------------------------------------- 1432 // toString() 1433 //----------------------------------------------------------------------- 1434 @DataProvider(name="sampleToString") 1435 Object[][] provider_sampleToString() { 1436 return new Object[][] { 1437 {11, 30, 59, 0, "Z", "11:30:59Z"}, 1438 {11, 30, 59, 0, "+01:00", "11:30:59+01:00"}, 1439 {11, 30, 59, 999000000, "Z", "11:30:59.999Z"}, 1440 {11, 30, 59, 999000000, "+01:00", "11:30:59.999+01:00"}, 1441 {11, 30, 59, 999000, "Z", "11:30:59.000999Z"}, 1442 {11, 30, 59, 999000, "+01:00", "11:30:59.000999+01:00"}, 1443 {11, 30, 59, 999, "Z", "11:30:59.000000999Z"}, 1444 {11, 30, 59, 999, "+01:00", "11:30:59.000000999+01:00"}, 1445 }; 1446 } 1447 1448 @Test(dataProvider="sampleToString") 1449 public void test_toString(int h, int m, int s, int n, String offsetId, String expected) { 1450 OffsetTime t = OffsetTime.of(h, m, s, n, ZoneOffset.of(offsetId)); 1451 String str = t.toString(); 1452 assertEquals(str, expected); 1453 } 1454 1455 } 1456