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