< prev index next >

test/jdk/java/time/test/java/time/TestOffsetDateTime.java

Print this page
rev 55940 : [mq]: 8211990
   1 /*
   2  * Copyright (c) 2012, 2013, 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  */


  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 test.java.time;
  61 
  62 import static org.testng.Assert.assertSame;

  63 

  64 import java.time.LocalDate;
  65 import java.time.LocalDateTime;
  66 import java.time.LocalTime;
  67 import java.time.OffsetDateTime;
  68 import java.time.ZoneOffset;
  69 
  70 import org.testng.annotations.BeforeMethod;
  71 import org.testng.annotations.DataProvider;
  72 import org.testng.annotations.Test;
  73 
  74 /**
  75  * Test OffsetDateTime.


  76  */
  77 @Test
  78 public class TestOffsetDateTime extends AbstractTest {
  79 
  80     private static final ZoneOffset OFFSET_PONE = ZoneOffset.ofHours(1);
  81     private static final ZoneOffset OFFSET_PTWO = ZoneOffset.ofHours(2);
  82     private OffsetDateTime TEST_2008_6_30_11_30_59_000000500;
  83 
  84     @BeforeMethod
  85     public void setUp() {
  86         TEST_2008_6_30_11_30_59_000000500 = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59, 500), OFFSET_PONE);
  87     }
  88 
  89     @Test
  90     public void test_immutable() {
  91         assertImmutable(OffsetDateTime.class);
  92     }
  93 
  94     //-----------------------------------------------------------------------
  95     // basics


 303     public void test_minusMinutes_zero() {
 304         OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE);
 305         OffsetDateTime test = base.minusMinutes(0);
 306         assertSame(test, base);
 307     }
 308 
 309     @Test
 310     public void test_minusSeconds_zero() {
 311         OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE);
 312         OffsetDateTime test = base.minusSeconds(0);
 313         assertSame(test, base);
 314     }
 315 
 316     @Test
 317     public void test_minusNanos_zero() {
 318         OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE);
 319         OffsetDateTime test = base.minusNanos(0);
 320         assertSame(test, base);
 321     }
 322 







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


  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 test.java.time;
  61 
  62 import static org.testng.Assert.assertSame;
  63 import static org.testng.Assert.assertEquals;
  64 
  65 import java.time.Duration;
  66 import java.time.LocalDate;
  67 import java.time.LocalDateTime;
  68 import java.time.LocalTime;
  69 import java.time.OffsetDateTime;
  70 import java.time.ZoneOffset;
  71 
  72 import org.testng.annotations.BeforeMethod;
  73 import org.testng.annotations.DataProvider;
  74 import org.testng.annotations.Test;
  75 
  76 /**
  77  * Test OffsetDateTime.
  78  *
  79  * @bug 8211990
  80  */
  81 @Test
  82 public class TestOffsetDateTime extends AbstractTest {
  83 
  84     private static final ZoneOffset OFFSET_PONE = ZoneOffset.ofHours(1);
  85     private static final ZoneOffset OFFSET_PTWO = ZoneOffset.ofHours(2);
  86     private OffsetDateTime TEST_2008_6_30_11_30_59_000000500;
  87 
  88     @BeforeMethod
  89     public void setUp() {
  90         TEST_2008_6_30_11_30_59_000000500 = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59, 500), OFFSET_PONE);
  91     }
  92 
  93     @Test
  94     public void test_immutable() {
  95         assertImmutable(OffsetDateTime.class);
  96     }
  97 
  98     //-----------------------------------------------------------------------
  99     // basics


 307     public void test_minusMinutes_zero() {
 308         OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE);
 309         OffsetDateTime test = base.minusMinutes(0);
 310         assertSame(test, base);
 311     }
 312 
 313     @Test
 314     public void test_minusSeconds_zero() {
 315         OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE);
 316         OffsetDateTime test = base.minusSeconds(0);
 317         assertSame(test, base);
 318     }
 319 
 320     @Test
 321     public void test_minusNanos_zero() {
 322         OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE);
 323         OffsetDateTime test = base.minusNanos(0);
 324         assertSame(test, base);
 325     }
 326 
 327     @Test
 328     public void test_duration() {
 329         OffsetDateTime start = OffsetDateTime.MAX
 330                                 .withOffsetSameLocal(ZoneOffset.ofHours(-17));
 331         OffsetDateTime end = OffsetDateTime.MAX;
 332         assertEquals(Duration.between(start, end), Duration.ofHours(1));
 333     }
 334 }
< prev index next >