1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package libcore.java.time; 17 18 import org.junit.Test; 19 import java.time.OffsetDateTime; 20 import java.time.ZoneOffset; 21 import java.time.temporal.ChronoUnit; 22 23 import static org.junit.Assert.assertEquals; 24 25 /** 26 * Additional tests for {@link OffsetDateTime}. 27 * 28 * @see tck.java.time.TCKOffsetDateTime 29 * @see test.java.time.TestOffsetDateTime 30 * @see test.java.time.TestOffsetDateTime_instants 31 */ 32 public class OffsetDateTimeTest { 33 34 private static final OffsetDateTime ODT = 35 OffsetDateTime.of(2000, 1, 2, 3, 4, 5, 6, ZoneOffset.UTC); 36 // 2000-01-02T03:04:05.000000006 UTC 37 38 @Test 39 public void test_plus() { 40 // Most of the logic is in LocalDateTime, to which OffsetDateTime#plus() delegates, verify 41 // only some simple cases here. In-depth tests for LocalDateTime#plus() can be found in 42 // TCKLocalDateTime. 43 assertEquals(OffsetDateTime.of(2000, 1, 2, 4, 4, 5, 6, ZoneOffset.UTC), 44 ODT.plus(1, ChronoUnit.HOURS)); 45 assertEquals(OffsetDateTime.of(2000, 1, 3, 2, 4, 5, 6, ZoneOffset.UTC), 46 ODT.plus(23, ChronoUnit.HOURS)); 47 assertEquals(OffsetDateTime.of(2000, 1, 2, 3, 5, 5, 6, ZoneOffset.UTC), 48 ODT.plus(1, ChronoUnit.MINUTES)); 49 assertEquals(OffsetDateTime.of(2000, 1, 2, 3, 5, 5, 6, ZoneOffset.UTC), 50 ODT.plus(60, ChronoUnit.SECONDS)); 51 assertEquals(OffsetDateTime.of(2000, 1, 2, 3, 4, 5, 1_000_006, ZoneOffset.UTC), 52 ODT.plus(1, ChronoUnit.MILLIS)); 53 assertEquals(OffsetDateTime.of(2000, 1, 2, 3, 4, 5, 7, ZoneOffset.UTC), 54 ODT.plus(1, ChronoUnit.NANOS)); 55 } 56 } 57