test/java/time/tck/java/time/chrono/TCKTestServiceLoader.java

Print this page




  39  *  * Redistributions in binary form must reproduce the above copyright notice,
  40  *    this list of conditions and the following disclaimer in the documentation
  41  *    and/or other materials provided with the distribution.
  42  *
  43  *  * Neither the name of JSR-310 nor the names of its contributors
  44  *    may be used to endorse or promote products derived from this software
  45  *    without specific prior written permission.
  46  *
  47  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  48  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  49  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  50  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  51  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  52  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  53  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  54  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  55  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  56  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  57  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  58  */
  59 package tck.java.time.calendar;
  60 
  61 import static org.testng.Assert.assertEquals;
  62 import static org.testng.Assert.assertNotNull;
  63 import static org.testng.Assert.fail;
  64 import static org.testng.Assert.assertSame;
  65 import static org.testng.Assert.assertTrue;
  66 
  67 import java.io.File;
  68 import java.io.IOException;
  69 import java.util.HashMap;
  70 import java.util.Map;
  71 import java.util.ServiceLoader;
  72 import java.time.LocalDate;
  73 import java.time.temporal.Chrono;
  74 import java.time.temporal.ChronoLocalDate;
  75 import java.time.temporal.ISOChrono;
  76 import java.time.DateTimeException;
  77 
  78 import org.testng.annotations.BeforeClass;
  79 import org.testng.annotations.Test;
  80 
  81 /**
  82  * Tests that a custom Chronology is available via the ServiceLoader.
  83  * The CopticChrono is configured via META-INF/services/java.time.temporal.Chrono.
  84  */
  85 @Test
  86 public class TestServiceLoader {
  87 
  88      @Test(groups={"tck"})
  89      public void test_CopticServiceLoader() {
  90         Chrono chrono = Chrono.of("Coptic");
  91         ChronoLocalDate<?> copticDate = chrono.date(1729, 4, 27);
  92         LocalDate ld = LocalDate.from(copticDate);
  93         assertEquals(ld, LocalDate.of(2013, 1, 5), "CopticDate does not match LocalDate");
  94     }
  95 
  96     @Test(groups="implementation")
  97     public void test_copticServiceLoader() {
  98         Map<String, Chrono> chronos = new HashMap<>();
  99         ServiceLoader<Chrono> loader = ServiceLoader.load(Chrono.class, null);
 100         for (Chrono<?> chrono : loader) {
 101             chronos.put(chrono.getId(), chrono);
 102         }
 103         assertNotNull(chronos.get("Coptic"), "CopticChrono not found");
 104     }
 105 
 106 }


  39  *  * Redistributions in binary form must reproduce the above copyright notice,
  40  *    this list of conditions and the following disclaimer in the documentation
  41  *    and/or other materials provided with the distribution.
  42  *
  43  *  * Neither the name of JSR-310 nor the names of its contributors
  44  *    may be used to endorse or promote products derived from this software
  45  *    without specific prior written permission.
  46  *
  47  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  48  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  49  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  50  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  51  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  52  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  53  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  54  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  55  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  56  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  57  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  58  */
  59 package tck.java.time.chrono;
  60 
  61 import static org.testng.Assert.assertEquals;
  62 









  63 import java.time.LocalDate;
  64 import java.time.chrono.Chronology;
  65 import java.time.chrono.ChronoLocalDate;


  66 

  67 import org.testng.annotations.Test;
  68 
  69 /**
  70  * Tests that a custom Chronology is available via the ServiceLoader.
  71  * The CopticChronology is configured via META-INF/services/java.time.chrono.Chronology.
  72  */
  73 @Test
  74 public class TCKTestServiceLoader {
  75 
  76      @Test(groups={"tck"})
  77      public void test_CopticServiceLoader() {
  78         Chronology chrono = Chronology.of("Coptic");
  79         ChronoLocalDate copticDate = chrono.date(1729, 4, 27);
  80         LocalDate ld = LocalDate.from(copticDate);
  81         assertEquals(ld, LocalDate.of(2013, 1, 5), "CopticDate does not match LocalDate");
  82     }
  83 










  84 }