8178323: Add negative tests for bind services Jlink feature
authoranazarov
Thu, 20 Apr 2017 22:46:07 -0700
changeset 44783 1b4068aea6df
parent 44781 5a43cca8fc10
child 44784 f2e3396a6a6b
8178323: Add negative tests for bind services Jlink feature Reviewed-by: mchung
jdk/test/tools/jlink/bindservices/BindServices.java
jdk/test/tools/jlink/bindservices/SuggestProviders.java
--- a/jdk/test/tools/jlink/bindservices/BindServices.java	Thu Apr 20 15:06:40 2017 -0700
+++ b/jdk/test/tools/jlink/bindservices/BindServices.java	Thu Apr 20 22:46:07 2017 -0700
@@ -149,6 +149,23 @@
         testImage(dir, "m1", "m2", "m3");
     }
 
+    @Test
+    public void testVerboseAndNoBindServices() throws Throwable {
+        if (!hasJmods()) return;
+
+        Path dir = Paths.get("verboseNoBind");
+
+        List<String> output =
+            JLink.run("--output", dir.toString(),
+                      "--module-path", MODULE_PATH,
+                      "--verbose",
+                      "--add-modules", "m1").output();
+
+        assertTrue(output.contains("m1 provides p1.S used by m1"));
+
+        testImage(dir, "m1");
+    }
+
     /*
      * Tests the given ${java.home} to only contain the specified modules
      */
--- a/jdk/test/tools/jlink/bindservices/SuggestProviders.java	Thu Apr 20 15:06:40 2017 -0700
+++ b/jdk/test/tools/jlink/bindservices/SuggestProviders.java	Thu Apr 20 22:46:07 2017 -0700
@@ -247,6 +247,42 @@
 
     }
 
+    @Test
+    public void suggestTypeNotRealProvider() throws Throwable {
+        if (!hasJmods()) return;
+
+        List<String> output =
+            JLink.run("--module-path", MODULE_PATH,
+                      "--add-modules", "m1",
+                      "--suggest-providers",
+                      "java.util.List").output();
+
+        System.out.println(output);
+        List<String> expected = List.of(
+            "No provider found for service specified to --suggest-providers: java.util.List"
+        );
+
+        assertTrue(output.containsAll(expected));
+    }
+
+    @Test
+    public void addNonObservableModule() throws Throwable {
+        if (!hasJmods()) return;
+
+        List<String> output =
+            JLink.run("--module-path", MODULE_PATH,
+                      "--add-modules", "nonExistentModule",
+                      "--suggest-providers",
+                      "java.nio.charset.spi.CharsetProvider").output();
+
+        System.out.println(output);
+        List<String> expected = List.of(
+            "jdk.charsets provides java.nio.charset.spi.CharsetProvider used by java.base"
+        );
+
+        assertTrue(output.containsAll(expected));
+    }
+
     static class JLink {
         static final ToolProvider JLINK_TOOL = ToolProvider.findFirst("jlink")
             .orElseThrow(() ->