< prev index next >

test/tools/jlink/bindservices/SuggestProviders.java

Print this page

        

*** 58,68 **** private static final String MODULE_PATH = Paths.get(JAVA_HOME, "jmods").toString() + File.pathSeparator + MODS_DIR.toString(); // the names of the modules in this test ! private static String[] modules = new String[] {"m1", "m2", "m3"}; private static boolean hasJmods() { if (!Files.exists(Paths.get(JAVA_HOME, "jmods"))) { System.err.println("Test skipped. NO jmods directory"); --- 58,68 ---- private static final String MODULE_PATH = Paths.get(JAVA_HOME, "jmods").toString() + File.pathSeparator + MODS_DIR.toString(); // the names of the modules in this test ! private static String[] modules = new String[] {"m1", "m2", "m3", "m4"}; private static boolean hasJmods() { if (!Files.exists(Paths.get(JAVA_HOME, "jmods"))) { System.err.println("Test skipped. NO jmods directory");
*** 169,178 **** --- 169,233 ---- String expected = "--bind-services option is specified. No additional providers suggested."; assertTrue(output.contains(expected)); } + @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( + "Services specified in --suggest-providers not used: java.util.List" + ); + + assertTrue(output.containsAll(expected)); + } + + @Test + public void noOneUsesProvider() throws Throwable { + if (!hasJmods()) return; + + List<String> output = + JLink.run("--module-path", MODULE_PATH, + "--add-modules", "m4", + "--suggest-providers", + "p4.S").output(); + + System.out.println(output); + List<String> expected = List.of( + "module m4 provides p4.S, not used by any observable module" + ); + + assertTrue(output.containsAll(expected)); + } + + @Test + public void nonObservableModule() throws Throwable { + if (!hasJmods()) return; + + List<String> output = + JLink.runWithNonZeroExitCode( + "--module-path", MODULE_PATH, + "--add-modules", "nonExistentModule", + "--suggest-providers", + "java.nio.charset.spi.CharsetProvider").output(); + + System.out.println(output); + List<String> expected = List.of( + "Error: Module nonExistentModule not found" + ); + + assertTrue(output.containsAll(expected)); + } + static class JLink { static final ToolProvider JLINK_TOOL = ToolProvider.findFirst("jlink") .orElseThrow(() -> new RuntimeException("jlink tool not found") );
*** 181,190 **** --- 236,252 ---- JLink jlink = new JLink(); assertTrue(jlink.execute(options) == 0); return jlink; } + static JLink runWithNonZeroExitCode(String... options) { + JLink jlink = new JLink(); + assertNotEquals(jlink.execute(options), 0, + "Exit code should be not 0"); + return jlink; + } + final List<String> output = new ArrayList<>(); private int execute(String... options) { System.out.println("jlink " + Stream.of(options).collect(Collectors.joining(" ")));
< prev index next >