changeset 17683:906c46c2bcab

Improve tests for ServiceLoader
author alanb
date Tue, 06 Sep 2016 15:46:36 +0100
parents ab7f12d892bf
children e091dbf0d727
files test/java/util/ServiceLoader/modules/Basic.java test/java/util/ServiceLoader/modules/MiscTests.java test/java/util/ServiceLoader/modules/ServicesTest.java test/java/util/ServiceLoader/modules/modules/bananascript/module-info.java test/java/util/ServiceLoader/modules/modules/bananascript/org/banana/BananaScript.java test/java/util/ServiceLoader/modules/modules/bananascript/org/banana/BananaScriptEngineFactory.java test/java/util/ServiceLoader/modules/src/bananascript/module-info.java test/java/util/ServiceLoader/modules/src/bananascript/org/banana/BananaScript.java test/java/util/ServiceLoader/modules/src/bananascript/org/banana/BananaScriptEngineFactory.java test/java/util/ServiceLoader/modules/src/test/module-info.java test/java/util/ServiceLoader/modules/src/test/test/Main.java
diffstat 11 files changed, 542 insertions(+), 544 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/util/ServiceLoader/modules/Basic.java	Tue Sep 06 15:46:36 2016 +0100
@@ -0,0 +1,317 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @library modules
+ * @build bananascript/*
+ * @compile src/pearscript/org/pear/PearScriptEngineFactory.java
+ *          src/pearscript/org/pear/PearScript.java
+ * @run testng/othervm Basic
+ * @summary Basic test for ServiceLoader with a provider deployed as a module.
+ */
+
+import java.lang.module.Configuration;
+import java.lang.module.ModuleFinder;
+import java.lang.reflect.Layer;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
+import java.util.*;
+import java.util.ServiceLoader.Provider;
+import java.util.stream.Collectors;
+import javax.script.ScriptEngineFactory;
+
+import org.testng.annotations.Test;
+import org.testng.annotations.BeforeTest;
+import static org.testng.Assert.*;
+
+/**
+ * Basic test for ServiceLoader. The test make use of two service providers:
+ * 1. BananaScriptEngine - a ScriptEngineFactory deployed as a module on the
+ *    module path.
+ * 2. PearScriptEngine - a ScriptEngineFactory deployed on the class path
+ *    with a service configuration file.
+ */
+
+public class Basic {
+
+    // Copy the services configuration file for "pearscript" into place.
+    @BeforeTest
+    public void setup() throws Exception {
+        Path src = Paths.get(System.getProperty("test.src", ""));
+        Path classes = Paths.get(System.getProperty("test.classes", ""));
+        String st = ScriptEngineFactory.class.getName();
+        Path config = Paths.get("META-INF", "services", st);
+        Path source = src.resolve("src").resolve("pearscript").resolve(config);
+        Path target = classes.resolve(config);
+        Files.createDirectories(target.getParent());
+        Files.copy(source, target, StandardCopyOption.REPLACE_EXISTING);
+    }
+
+    /**
+     * Basic test of iterator() to ensure that providers located as modules
+     * and on the class path are found.
+     */
+    @Test
+    public void testIterator() {
+        ServiceLoader<ScriptEngineFactory> loader
+            = ServiceLoader.load(ScriptEngineFactory.class);
+        Set<String> names = collectAll(loader)
+                .stream()
+                .map(ScriptEngineFactory::getEngineName)
+                .collect(Collectors.toSet());
+        assertTrue(names.contains("BananaScriptEngine"));
+        assertTrue(names.contains("PearScriptEngine"));
+    }
+
+    /**
+     * Basic test of iterator() to test iteration order. Providers deployed
+     * as named modules should be found before providers deployed on the class
+     * path.
+     */
+    @Test
+    public void testIteratorOrder() {
+        ServiceLoader<ScriptEngineFactory> loader
+            = ServiceLoader.load(ScriptEngineFactory.class);
+        boolean foundUnnamed = false;
+        for (ScriptEngineFactory factory : collectAll(loader)) {
+            if (factory.getClass().getModule().isNamed()) {
+                if (foundUnnamed) {
+                    assertTrue(false, "Named module element after unnamed");
+                }
+            } else {
+                foundUnnamed = true;
+            }
+        }
+    }
+
+    /**
+     * Basic test of Provider::type
+     */
+    @Test
+    public void testProviderType() {
+        Set<String> types = ServiceLoader.load(ScriptEngineFactory.class)
+                .stream()
+                .map(Provider::type)
+                .map(Class::getName)
+                .collect(Collectors.toSet());
+        assertTrue(types.contains("org.banana.BananaScriptEngineFactory"));
+        assertTrue(types.contains("org.pear.PearScriptEngineFactory"));
+    }
+
+    /**
+     * Basic test of Provider::get
+     */
+    @Test
+    public void testProviderGet() {
+        Set<String> names = ServiceLoader.load(ScriptEngineFactory.class)
+                .stream()
+                .map(Provider::get)
+                .map(ScriptEngineFactory::getEngineName)
+                .collect(Collectors.toSet());
+        assertTrue(names.contains("BananaScriptEngine"));
+        assertTrue(names.contains("PearScriptEngine"));
+    }
+
+    /**
+     * Basic test of stream() to ensure that elements for providers in named
+     * modules come before elements for providers in unnamed modules.
+     */
+    @Test
+    public void testStreamOrder() {
+        List<Class<?>> types = ServiceLoader.load(ScriptEngineFactory.class)
+                .stream()
+                .map(Provider::type)
+                .collect(Collectors.toList());
+
+        boolean foundUnnamed = false;
+        for (Class<?> factoryClass : types) {
+            if (factoryClass.getModule().isNamed()) {
+                if (foundUnnamed) {
+                    assertTrue(false, "Named module element after unnamed");
+                }
+            } else {
+                foundUnnamed = true;
+            }
+        }
+    }
+
+    /**
+     * Basic test of ServiceLoader.findFirst()
+     */
+    @Test
+    public void testFindFirst() {
+        Optional<ScriptEngineFactory> ofactory
+            = ServiceLoader.load(ScriptEngineFactory.class).findFirst();
+        assertTrue(ofactory.isPresent());
+        ScriptEngineFactory factory = ofactory.get();
+        assertTrue(factory.getClass().getModule().isNamed());
+
+        class S { }
+        assertFalse(ServiceLoader.load(S.class).findFirst().isPresent());
+    }
+
+    /**
+     * Basic test ServiceLoader.load specifying the platform class loader.
+     * The providers on the module path and class path should not be located.
+     */
+    @Test
+    public void testWithPlatformClassLoader() {
+        ClassLoader pcl = ClassLoader.getPlatformClassLoader();
+
+        // iterator
+        ServiceLoader<ScriptEngineFactory> loader
+                = ServiceLoader.load(ScriptEngineFactory.class, pcl);
+        Set<String> names = collectAll(loader)
+                .stream()
+                .map(ScriptEngineFactory::getEngineName)
+                .collect(Collectors.toSet());
+        assertFalse(names.contains("BananaScriptEngine"));
+        assertFalse(names.contains("PearScriptEngine"));
+
+        // stream
+        names = ServiceLoader.load(ScriptEngineFactory.class, pcl)
+                .stream()
+                .map(Provider::get)
+                .map(ScriptEngineFactory::getEngineName)
+                .collect(Collectors.toSet());
+        assertFalse(names.contains("BananaScriptEngine"));
+        assertFalse(names.contains("PearScriptEngine"));
+    }
+
+    /**
+     * Basic test of ServiceLoader.load, using the class loader for
+     * a module in a custom layer as the context.
+     */
+    @Test
+    public void testWithCustomLayer1() {
+        Layer layer = createCustomLayer("bananascript");
+
+        ClassLoader loader = layer.findLoader("bananascript");
+        List<ScriptEngineFactory> providers
+            = collectAll(ServiceLoader.load(ScriptEngineFactory.class, loader));
+
+        // should have at least 2 x bananascript + pearscript
+        assertTrue(providers.size() >= 3);
+
+        // first element should be the provider in the custom layer
+        ScriptEngineFactory factory = providers.get(0);
+        assertTrue(factory.getClass().getClassLoader() == loader);
+        assertTrue(factory.getClass().getModule().getLayer() == layer);
+        assertTrue(factory.getEngineName().equals("BananaScriptEngine"));
+
+        // remainder should be the boot layer
+        providers.remove(0);
+        Set<String> names = providers.stream()
+                .map(ScriptEngineFactory::getEngineName)
+                .collect(Collectors.toSet());
+        assertTrue(names.contains("BananaScriptEngine"));
+        assertTrue(names.contains("PearScriptEngine"));
+    }
+
+    /**
+     * Basic test of ServiceLoader.load, using a custom Layer as the context.
+     */
+    @Test
+    public void testWithCustomLayer2() {
+        Layer layer = createCustomLayer("bananascript");
+
+        List <ScriptEngineFactory> providers
+            = collectAll(ServiceLoader.load(layer, ScriptEngineFactory.class));
+
+        // should have at least 2 x bananascript
+        assertTrue(providers.size() >= 2);
+
+        // first element should be the provider in the custom layer
+        ScriptEngineFactory factory = providers.get(0);
+        assertTrue(factory.getClass().getModule().getLayer() == layer);
+        assertTrue(factory.getEngineName().equals("BananaScriptEngine"));
+
+        // remainder should be the boot layer
+        providers.remove(0);
+        Set<String> names = providers.stream()
+                .map(ScriptEngineFactory::getEngineName)
+                .collect(Collectors.toSet());
+        assertTrue(names.contains("BananaScriptEngine"));
+        assertFalse(names.contains("PearScriptEngine"));
+    }
+
+
+    // -- nulls --
+
+    @Test(expectedExceptions = { NullPointerException.class })
+    public void testLoadNull1() {
+        ServiceLoader.load(null);
+    }
+
+    @Test(expectedExceptions = { NullPointerException.class })
+    public void testLoadNull2() {
+        ServiceLoader.load((Class<?>) null, ClassLoader.getSystemClassLoader());
+    }
+
+    @Test(expectedExceptions = { NullPointerException.class })
+    public void testLoadNull3() {
+        class S { }
+        ServiceLoader.load((Layer) null, S.class);
+    }
+
+    @Test(expectedExceptions = { NullPointerException.class })
+    public void testLoadNull4() {
+        ServiceLoader.load(Layer.empty(), null);
+    }
+
+    @Test(expectedExceptions = { NullPointerException.class })
+    public void testLoadNull5() {
+        ServiceLoader.loadInstalled(null);
+    }
+
+    /**
+     * Create a custom Layer by resolving the given module names. The modules
+     * are located in the {@code ${test.classes}/modules} directory.
+     */
+    private Layer createCustomLayer(String... modules) {
+        Path dir = Paths.get(System.getProperty("test.classes", "."), "modules");
+        ModuleFinder finder = ModuleFinder.of(dir);
+        Set<String> roots = new HashSet<>();
+        Collections.addAll(roots, modules);
+        Layer bootLayer = Layer.boot();
+        Configuration parent = bootLayer.configuration();
+        Configuration cf = parent.resolveRequires(finder, ModuleFinder.of(), roots);
+        ClassLoader scl = ClassLoader.getSystemClassLoader();
+        Layer layer = bootLayer.defineModulesWithOneLoader(cf, scl);
+        assertTrue(layer.modules().size() == 1);
+        return layer;
+    }
+
+    private <E> List<E> collectAll(ServiceLoader<E> loader) {
+        List<E> list = new ArrayList<>();
+        Iterator<E> iterator = loader.iterator();
+        while (iterator.hasNext()) {
+            list.add(iterator.next());
+        }
+        return list;
+    }
+}
+
--- a/test/java/util/ServiceLoader/modules/MiscTests.java	Fri Sep 02 10:31:49 2016 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,56 +0,0 @@
-/*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-import java.lang.reflect.Layer;
-import java.security.Provider;
-import java.util.ServiceLoader;
-
-import org.testng.annotations.Test;
-import static org.testng.Assert.*;
-
-/*
- * @test
- * @run testng MiscTests
- * @summary Basic test of ServiceLoader with modules
- */
-
-public class MiscTests {
-
-    @Test
-    public void testEmptyLayer() {
-        ServiceLoader<Provider> sl
-            = ServiceLoader.load(Layer.empty(), Provider.class);
-        assertFalse(sl.iterator().hasNext());
-    }
-
-    @Test(expectedExceptions = { NullPointerException.class })
-    public void testNullLayer() {
-        ServiceLoader.load(null, Provider.class);
-    }
-
-    @Test(expectedExceptions = { NullPointerException.class })
-    public void testNullService() {
-        ServiceLoader.load(Layer.empty(), null);
-    }
-
-}
--- a/test/java/util/ServiceLoader/modules/ServicesTest.java	Fri Sep 02 10:31:49 2016 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,190 +0,0 @@
-/*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-import java.io.File;
-import java.lang.module.Configuration;
-import java.lang.module.ModuleFinder;
-import java.lang.reflect.Layer;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.ServiceLoader;
-import java.util.Set;
-import javax.script.ScriptEngineFactory;
-
-import static jdk.testlibrary.ProcessTools.executeTestJava;
-
-import org.testng.annotations.BeforeTest;
-import org.testng.annotations.Test;
-import static org.testng.Assert.*;
-
-/**
- * @test
- * @library /lib/testlibrary
- * @modules java.scripting
-            jdk.compiler
- * @build ServicesTest CompilerUtils jdk.testlibrary.*
- * @run testng ServicesTest
- * @summary Tests ServiceLoader to locate service providers on the module path
- *          and class path. Also tests ServiceLoader with a custom Layer.
- */
-
-@Test
-public class ServicesTest {
-
-    private static final String TEST_SRC = System.getProperty("test.src");
-
-    private static final Path SRC_DIR = Paths.get(TEST_SRC, "src");
-    private static final Path CLASSES_DIR = Paths.get("classes");
-    private static final Path MODS_DIR = Paths.get("mods");
-
-    // modules to compile to the module path
-    private static final String MODULES[] = { "test", "bananascript" };
-
-    // directories of classes to compile to the class path
-    private static final String CLASSES[] = { "pearscript" };
-
-    // resources to copy to the class path
-    private static final String RESOURCES[] = {
-        "pearscript/META-INF/services/javax.script.ScriptEngineFactory"
-    };
-
-
-    /**
-     * Compiles all modules and classes used by the test
-     */
-    @BeforeTest
-    public void setup() throws Exception {
-
-        // modules
-        for (String mn : MODULES ) {
-            Path src = SRC_DIR.resolve(mn);
-            Path mods = MODS_DIR.resolve(mn);
-            assertTrue(CompilerUtils.compile(src, mods));
-        }
-
-        // classes
-        for (String dir : CLASSES) {
-            Path src = SRC_DIR.resolve(dir);
-            assertTrue(CompilerUtils.compile(src, CLASSES_DIR));
-        }
-
-        // copy resources
-        for (String rn : RESOURCES) {
-            Path file = Paths.get(rn.replace('/', File.separatorChar));
-            Path source = SRC_DIR.resolve(file);
-
-            // drop directory to get a target of classes/META-INF/...
-            Path target = CLASSES_DIR.resolve(file.subpath(1, file.getNameCount()));
-
-            Files.createDirectories(target.getParent());
-            Files.copy(source, target);
-        }
-
-    }
-
-
-    /**
-     * Run test with --module-path.
-     *
-     * BananaScriptEngine should be found.
-     */
-    public void runWithModulePath() throws Exception {
-        int exitValue
-            = executeTestJava("--module-path", MODS_DIR.toString(),
-                              "-m", "test/test.Main",
-                              "BananaScriptEngine")
-                .outputTo(System.out)
-                .errorTo(System.out)
-                .getExitValue();
-
-        assertTrue(exitValue == 0);
-    }
-
-
-    /**
-     * Run test with --module-path and -classpath.
-     *
-     * Both BananaScriptEngine and PearScriptEngine should be found
-     */
-    public void runWithModulePathAndClassPath() throws Exception {
-        int exitValue
-            = executeTestJava("--module-path", MODS_DIR.toString(),
-                              "-cp", CLASSES_DIR.toString(),
-                              "-m", "test/test.Main",
-                              "BananaScriptEngine", "PearScriptEngine")
-                .outputTo(System.out)
-                .errorTo(System.out)
-                .getExitValue();
-
-        assertTrue(exitValue == 0);
-    }
-
-
-    /**
-     * Exercise ServiceLoader.load(Layer, Class).
-     */
-    public void testWithCustomLayer() throws Exception {
-
-        ServiceLoader<ScriptEngineFactory> sl;
-
-        // BananaScriptEngine should not be in the boot Layer
-        sl = ServiceLoader.load(Layer.boot(), ScriptEngineFactory.class);
-        assertTrue(find("BananaScriptEngine", sl) == null);
-
-        // create a custom Layer
-        ModuleFinder finder = ModuleFinder.of(MODS_DIR);
-        Layer bootLayer = Layer.boot();
-        Configuration parent = bootLayer.configuration();
-        Configuration cf
-            = parent.resolveRequiresAndUses(finder, ModuleFinder.of(), Set.of());
-        ClassLoader scl = ClassLoader.getSystemClassLoader();
-        Layer layer = bootLayer.defineModulesWithOneLoader(cf, scl);
-
-        assertTrue(layer.findModule("bananascript").isPresent());
-        ClassLoader loader = layer.findLoader("bananascript");
-
-        sl = ServiceLoader.load(layer, ScriptEngineFactory.class);
-        ScriptEngineFactory factory = find("BananaScriptEngine", sl);
-        assertTrue(factory != null);
-        assertEquals(factory.getClass().getModule().getName(), "bananascript");
-        assertTrue(factory.getClass().getClassLoader() == loader);
-
-    }
-
-    /**
-     * Find the given scripting engine (by name) via the ScriptEngineFactory
-     * that ServiceLoader has found.
-     */
-    static ScriptEngineFactory find(String name,
-                                    ServiceLoader<ScriptEngineFactory> sl) {
-        for (ScriptEngineFactory factory : sl) {
-            if (factory.getEngineName().equals(name))
-                return factory;
-        }
-        return null;
-    }
-
-
-}
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/util/ServiceLoader/modules/modules/bananascript/module-info.java	Tue Sep 06 15:46:36 2016 +0100
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+module bananascript {
+    requires java.scripting;
+
+    provides javax.script.ScriptEngineFactory
+      with org.banana.BananaScriptEngineFactory;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/util/ServiceLoader/modules/modules/bananascript/org/banana/BananaScript.java	Tue Sep 06 15:46:36 2016 +0100
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package org.banana;
+
+import java.io.Reader;
+import javax.script.Bindings;
+import javax.script.ScriptContext;
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineFactory;
+
+public class BananaScript implements ScriptEngine {
+
+    @Override
+    public Object eval(String script, ScriptContext context) {
+        throw new RuntimeException();
+    }
+
+    @Override
+    public Object eval(Reader reader , ScriptContext context) {
+        throw new RuntimeException();
+    }
+
+    @Override
+    public Object eval(String script) {
+        throw new RuntimeException();
+    }
+
+    @Override
+    public Object eval(Reader reader) {
+        throw new RuntimeException();
+    }
+
+    @Override
+    public Object eval(String script, Bindings n) {
+        throw new RuntimeException();
+    }
+
+    @Override
+    public Object eval(Reader reader , Bindings n) {
+        throw new RuntimeException();
+    }
+    @Override
+    public void put(String key, Object value) {
+        throw new RuntimeException();
+    }
+
+    @Override
+    public Object get(String key) {
+        throw new RuntimeException();
+    }
+
+    @Override
+    public Bindings getBindings(int scope) {
+        throw new RuntimeException();
+    }
+
+    @Override
+    public void setBindings(Bindings bindings, int scope) {
+        throw new RuntimeException();
+    }
+
+    @Override
+    public Bindings createBindings() {
+        throw new RuntimeException();
+    }
+
+    @Override
+    public ScriptContext getContext() {
+        throw new RuntimeException();
+    }
+
+    @Override
+    public void setContext(ScriptContext context) {
+        throw new RuntimeException();
+    }
+
+    @Override
+    public ScriptEngineFactory getFactory() {
+        throw new RuntimeException();
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/util/ServiceLoader/modules/modules/bananascript/org/banana/BananaScriptEngineFactory.java	Tue Sep 06 15:46:36 2016 +0100
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package org.banana;
+
+import java.util.Arrays;
+import java.util.List;
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineFactory;
+
+public class BananaScriptEngineFactory implements ScriptEngineFactory {
+
+    @Override
+    public String getEngineName() {
+        return "BananaScriptEngine";
+    }
+
+    @Override
+    public String getEngineVersion() {
+        return "1.0";
+    }
+
+    @Override
+    public List<String> getExtensions() {
+        return Arrays.asList("banana");
+    }
+
+    @Override
+    public List<String> getMimeTypes() {
+        return Arrays.asList("application/x-bananascript");
+    }
+
+    @Override
+    public List<String> getNames() {
+        return Arrays.asList("BananaScript");
+    }
+
+    @Override
+    public String getLanguageName() {
+        return "BananaScript";
+    }
+
+    @Override
+    public String getLanguageVersion() {
+        return "1.0";
+    }
+
+    @Override
+    public Object getParameter(String key) {
+        return null;
+    }
+
+    @Override
+    public String getMethodCallSyntax(String obj, String m, String... args) {
+        throw new RuntimeException();
+    }
+
+    @Override
+    public String getOutputStatement(String toDisplay) {
+        throw new RuntimeException();
+    }
+
+    @Override
+    public String getProgram(String... statements) {
+        throw new RuntimeException();
+    }
+
+    @Override
+    public ScriptEngine getScriptEngine() {
+        return new BananaScript();
+    }
+}
--- a/test/java/util/ServiceLoader/modules/src/bananascript/module-info.java	Fri Sep 02 10:31:49 2016 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,30 +0,0 @@
-/*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-module bananascript {
-    requires java.scripting;
-
-    provides javax.script.ScriptEngineFactory
-      with org.banana.BananaScriptEngineFactory;
-}
-
--- a/test/java/util/ServiceLoader/modules/src/bananascript/org/banana/BananaScript.java	Fri Sep 02 10:31:49 2016 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,103 +0,0 @@
-/*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package org.banana;
-
-import java.io.Reader;
-import javax.script.Bindings;
-import javax.script.ScriptContext;
-import javax.script.ScriptEngine;
-import javax.script.ScriptEngineFactory;
-
-public class BananaScript implements ScriptEngine {
-
-    @Override
-    public Object eval(String script, ScriptContext context) {
-        throw new RuntimeException();
-    }
-
-    @Override
-    public Object eval(Reader reader , ScriptContext context) {
-        throw new RuntimeException();
-    }
-
-    @Override
-    public Object eval(String script) {
-        throw new RuntimeException();
-    }
-
-    @Override
-    public Object eval(Reader reader) {
-        throw new RuntimeException();
-    }
-
-    @Override
-    public Object eval(String script, Bindings n) {
-        throw new RuntimeException();
-    }
-
-    @Override
-    public Object eval(Reader reader , Bindings n) {
-        throw new RuntimeException();
-    }
-    @Override
-    public void put(String key, Object value) {
-        throw new RuntimeException();
-    }
-
-    @Override
-    public Object get(String key) {
-        throw new RuntimeException();
-    }
-
-    @Override
-    public Bindings getBindings(int scope) {
-        throw new RuntimeException();
-    }
-
-    @Override
-    public void setBindings(Bindings bindings, int scope) {
-        throw new RuntimeException();
-    }
-
-    @Override
-    public Bindings createBindings() {
-        throw new RuntimeException();
-    }
-
-    @Override
-    public ScriptContext getContext() {
-        throw new RuntimeException();
-    }
-
-    @Override
-    public void setContext(ScriptContext context) {
-        throw new RuntimeException();
-    }
-
-    @Override
-    public ScriptEngineFactory getFactory() {
-        throw new RuntimeException();
-    }
-}
-
--- a/test/java/util/ServiceLoader/modules/src/bananascript/org/banana/BananaScriptEngineFactory.java	Fri Sep 02 10:31:49 2016 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,92 +0,0 @@
-/*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package org.banana;
-
-import java.util.Arrays;
-import java.util.List;
-import javax.script.ScriptEngine;
-import javax.script.ScriptEngineFactory;
-
-public class BananaScriptEngineFactory implements ScriptEngineFactory {
-
-    @Override
-    public String getEngineName() {
-        return "BananaScriptEngine";
-    }
-
-    @Override
-    public String getEngineVersion() {
-        return "1.0";
-    }
-
-    @Override
-    public List<String> getExtensions() {
-        return Arrays.asList("banana");
-    }
-
-    @Override
-    public List<String> getMimeTypes() {
-        return Arrays.asList("application/x-bananascript");
-    }
-
-    @Override
-    public List<String> getNames() {
-        return Arrays.asList("BananaScript");
-    }
-
-    @Override
-    public String getLanguageName() {
-        return "BananaScript";
-    }
-
-    @Override
-    public String getLanguageVersion() {
-        return "1.0";
-    }
-
-    @Override
-    public Object getParameter(String key) {
-        return null;
-    }
-
-    @Override
-    public String getMethodCallSyntax(String obj, String m, String... args) {
-        throw new RuntimeException();
-    }
-
-    @Override
-    public String getOutputStatement(String toDisplay) {
-        throw new RuntimeException();
-    }
-
-    @Override
-    public String getProgram(String... statements) {
-        throw new RuntimeException();
-    }
-
-    @Override
-    public ScriptEngine getScriptEngine() {
-        return new BananaScript();
-    }
-}
--- a/test/java/util/ServiceLoader/modules/src/test/module-info.java	Fri Sep 02 10:31:49 2016 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,29 +0,0 @@
-/*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-module test {
-    requires java.scripting;
-
-    uses javax.script.ScriptEngineFactory;
-}
-
--- a/test/java/util/ServiceLoader/modules/src/test/test/Main.java	Fri Sep 02 10:31:49 2016 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,44 +0,0 @@
-/*
- * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package test;
-
-import java.util.HashSet;
-import java.util.ServiceLoader;
-import java.util.Set;
-import javax.script.ScriptEngineFactory;
-
-public class Main {
-    public static void main(String[] args) {
-        Set<String> engines = new HashSet<>();
-        for (ScriptEngineFactory factory: ServiceLoader.load(ScriptEngineFactory.class)) {
-            System.out.format("loaded: %s%n" , factory.getEngineName());
-            engines.add(factory.getEngineName());
-        }
-
-        for (String engine: args) {
-            if (!engines.contains(engine))
-                throw new RuntimeException(engine + " not found");
-        }
-    }
-}