Path: blob/master/test/jdk/java/time/tck/java/time/chrono/TCKIsoEra.java
41128 views
/*1* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/*26* Copyright (c) 2008-2012, Stephen Colebourne & Michael Nascimento Santos27*28* All rights reserved.29*30* Redistribution and use in source and binary forms, with or without31* modification, are permitted provided that the following conditions are met:32*33* * Redistributions of source code must retain the above copyright notice,34* this list of conditions and the following disclaimer.35*36* * Redistributions in binary form must reproduce the above copyright notice,37* this list of conditions and the following disclaimer in the documentation38* and/or other materials provided with the distribution.39*40* * Neither the name of JSR-310 nor the names of its contributors41* may be used to endorse or promote products derived from this software42* without specific prior written permission.43*44* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS45* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT46* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR47* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR48* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,49* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,50* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR51* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF52* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING53* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS54* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.55*/56package tck.java.time.chrono;5758import static java.time.temporal.ChronoField.ERA;59import static org.testng.Assert.assertEquals;60import static org.testng.Assert.assertTrue;6162import java.time.chrono.Era;63import java.time.chrono.IsoChronology;64import java.time.chrono.IsoEra;65import java.time.temporal.ValueRange;66import java.util.List;6768import org.testng.annotations.DataProvider;69import org.testng.annotations.Test;7071/**72* Test.73*/74@Test75public class TCKIsoEra {7677@DataProvider(name = "IsoEras")78Object[][] data_of_eras() {79return new Object[][] {80{IsoEra.BCE, "BCE", 0},81{IsoEra.CE, "CE", 1},82};83}8485@Test(dataProvider="IsoEras")86public void test_valueOf(IsoEra era , String eraName, int eraValue) {87assertEquals(era.getValue(), eraValue);88assertEquals(IsoEra.of(eraValue), era);89assertEquals(IsoEra.valueOf(eraName), era);90}9192//-----------------------------------------------------------------------93// values()94//-----------------------------------------------------------------------95@Test96public void test_values() {97List<Era> eraList = IsoChronology.INSTANCE.eras();98IsoEra[] eras = IsoEra.values();99assertEquals(eraList.size(), eras.length);100for (IsoEra era : eras) {101assertTrue(eraList.contains(era));102}103}104105//-----------------------------------------------------------------------106// range()107//-----------------------------------------------------------------------108@Test109public void test_range() {110for (IsoEra era : IsoEra.values()) {111assertEquals(era.range(ERA), ValueRange.of(0, 1));112}113}114115}116117118