Home | History | Annotate | Download | only in chrono
      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 test.java.time.chrono;
     60 
     61 import static org.testng.Assert.assertNotNull;
     62 
     63 import java.time.chrono.Chronology;
     64 import java.util.HashMap;
     65 import java.util.Map;
     66 import java.util.ServiceLoader;
     67 
     68 import org.testng.annotations.Test;
     69 
     70 /**
     71  * Tests that a custom Chronology is available via the ServiceLoader.
     72  * The CopticChronology is configured via META-INF/services/java.time.chrono.Chronology.
     73  */
     74 @Test
     75 public class TestServiceLoader {
     76 
     77     @Test
     78     public void test_copticServiceLoader() {
     79         Map<String, Chronology> chronos = new HashMap<>();
     80         // Android-changed: This test assumes that the system classloader sees all test classes.
     81         // That assumption is untrue, when run in CTS. Use this class's classloader instead.
     82         ServiceLoader<Chronology> loader = ServiceLoader.load(Chronology.class,
     83                 getClass().getClassLoader());
     84         for (Chronology chrono : loader) {
     85             chronos.put(chrono.getId(), chrono);
     86         }
     87         assertNotNull(chronos.get("Coptic"), "CopticChronology not found");
     88     }
     89 
     90 }
     91