1 /*
   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 it
   5  * under the terms of the GNU General Public License version 2 only, as
   6  * published by the Free Software Foundation.
   7  *
   8  * This code is distributed in the hope that it will be useful, but WITHOUT
   9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  11  * version 2 for more details (a copy is included in the LICENSE file that
  12  * accompanied this code).
  13  *
  14  * You should have received a copy of the GNU General Public License version
  15  * 2 along with this work; if not, write to the Free Software Foundation,
  16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  17  *
  18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  19  * or visit www.oracle.com if you need additional information or have any
  20  * questions.
  21  */
  22 
  23 /*
  24  * This file is available under and governed by the GNU General Public
  25  * License version 2 only, as published by the Free Software Foundation.
  26  * However, the following notice accompanied the original version of this
  27  * file:
  28  *
  29  * Copyright (c) 2011-2012, Stephen Colebourne & Michael Nascimento Santos
  30  *
  31  * All rights reserved.
  32  *
  33  * Redistribution and use in source and binary forms, with or without
  34  * modification, are permitted provided that the following conditions are met:
  35  *
  36  *  * Redistributions of source code must retain the above copyright notice,
  37  *    this list of conditions and the following disclaimer.
  38  *
  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 }