public void testAutomaticModule() { ModuleDescriptor descriptor = ModuleDescriptor.newAutomaticModule("foo") .packages(Set.of("p")) .provides("p.Service", List.of("q.ServiceImpl")) .build(); // modifiers assertTrue(descriptor.modifiers().contains(ModuleDescriptor.Modifier.AUTOMATIC)); assertTrue(descriptor.isAutomatic()); // requires assertTrue(descriptor.requires().size() == 1); Set<String> names = descriptor.requires() .stream() .map(Requires::name) .collect(Collectors.toSet()); assertEquals(names, Set.of("java.base")); // packages assertEquals(descriptor.packages(), Set.of("p", "q")); assertTrue(descriptor.exports().isEmpty()); assertTrue(descriptor.opens().isEmpty()); }
private ModuleSorter addModule(ResourcePoolModule module) { addNode(module); readModuleDescriptor(module).requires().forEach(req -> { ResourcePoolModule dep = moduleView.findModule(req.name()).orElse(null); if (dep != null) { addNode(dep); edges.get(module.name()).add(dep); } else if (!req.modifiers().contains(Modifier.STATIC)) { throw new PluginException(req.name() + " not found"); } }); return this; }
public void testRequiresWithNoModifiers() { Requires r = requires(EnumSet.noneOf(Requires.Modifier.class), "foo"); assertEquals(r, r); assertTrue(r.compareTo(r) == 0); assertTrue(r.modifiers().isEmpty()); assertEquals(r.name(), "foo"); assertFalse(r.compiledVersion().isPresent()); }
public void testRequiresWithAllModifiers() { Requires r = requires(EnumSet.allOf(Modifier.class), "foo"); assertEquals(r, r); assertTrue(r.compareTo(r) == 0); assertEquals(r.modifiers(), EnumSet.of(TRANSITIVE, STATIC, SYNTHETIC, MANDATED)); assertEquals(r.name(), "foo"); assertFalse(r.compiledVersion().isPresent()); }
public void testRequiresCompare() { Requires r1 = requires(EnumSet.noneOf(Modifier.class), "foo"); Requires r2 = requires(EnumSet.noneOf(Modifier.class), "bar"); int n = "foo".compareTo("bar"); assertTrue(r1.compareTo(r2) == n); assertTrue(r2.compareTo(r1) == -n); }
public void testRequiresEqualsAndHashCode() { Requires r1 = requires("foo"); Requires r2 = requires("foo"); assertEquals(r1, r2); assertTrue(r1.hashCode() == r2.hashCode()); r1 = requires(EnumSet.allOf(Requires.Modifier.class), "foo"); r2 = requires(EnumSet.allOf(Requires.Modifier.class), "foo"); assertEquals(r1, r2); assertTrue(r1.hashCode() == r2.hashCode()); r1 = requires("foo"); r2 = requires("bar"); assertNotEquals(r1, r2); r1 = requires(EnumSet.allOf(Requires.Modifier.class), "foo"); r2 = requires(Set.of(), "foo"); assertNotEquals(r1, r2); Version v1 = Version.parse("1.0"); r1 = requires(EnumSet.allOf(Requires.Modifier.class), "foo", v1); r2 = requires(EnumSet.allOf(Requires.Modifier.class), "foo", v1); assertEquals(r1, r2); assertTrue(r1.hashCode() == r2.hashCode()); Version v2 = Version.parse("2.0"); r1 = requires(EnumSet.allOf(Requires.Modifier.class), "foo", v1); r2 = requires(EnumSet.allOf(Requires.Modifier.class), "foo", v2); assertNotEquals(r1, r2); }
private Exports exports(Set<Exports.Modifier> mods, String pn) { return ModuleDescriptor.newModule("foo") .exports(mods, pn) .build() .exports() .iterator() .next(); }
private Exports exports(Set<Exports.Modifier> mods, String pn, String target) { return ModuleDescriptor.newModule("foo") .exports(mods, pn, Set.of(target)) .build() .exports() .iterator() .next(); }
public void testExportsToAllWithModifier() { Exports e = exports(Set.of(Exports.Modifier.SYNTHETIC), "p"); assertEquals(e, e); assertTrue(e.modifiers().size() == 1); assertTrue(e.modifiers().contains(Exports.Modifier.SYNTHETIC)); assertEquals(e.source(), "p"); assertFalse(e.isQualified()); assertTrue(e.targets().isEmpty()); }
public void testExportsToTargetWithModifier() { Exports e = exports(Set.of(Exports.Modifier.SYNTHETIC), "p", "bar"); assertEquals(e, e); assertTrue(e.modifiers().size() == 1); assertTrue(e.modifiers().contains(Exports.Modifier.SYNTHETIC)); assertEquals(e.source(), "p"); assertTrue(e.isQualified()); assertTrue(e.targets().size() == 1); assertTrue(e.targets().contains("bar")); }
public void testExportsCompareWithSameModifiers() { Exports e1 = exports(Set.of(Exports.Modifier.SYNTHETIC), "p"); Exports e2 = exports(Set.of(Exports.Modifier.SYNTHETIC), "p"); assertEquals(e1, e2); assertTrue(e1.hashCode() == e2.hashCode()); assertTrue(e1.compareTo(e2) == 0); assertTrue(e2.compareTo(e1) == 0); }
public void testExportsCompareWithDifferentModifiers() { Exports e1 = exports(Set.of(Exports.Modifier.SYNTHETIC), "p"); Exports e2 = exports("p"); assertNotEquals(e1, e2); assertTrue(e1.compareTo(e2) == 1); assertTrue(e2.compareTo(e1) == -1); }
private Opens opens(Set<Opens.Modifier> mods, String pn) { return ModuleDescriptor.newModule("foo") .opens(mods, pn) .build() .opens() .iterator() .next(); }
private Opens opens(Set<Opens.Modifier> mods, String pn, String target) { return ModuleDescriptor.newModule("foo") .opens(mods, pn, Set.of(target)) .build() .opens() .iterator() .next(); }
public void testOpensCompareWithSameModifiers() { Opens o1 = opens(Set.of(Opens.Modifier.SYNTHETIC), "p"); Opens o2 = opens(Set.of(Opens.Modifier.SYNTHETIC), "p"); assertEquals(o1, o2); assertTrue(o1.hashCode() == o2.hashCode()); assertTrue(o1.compareTo(o2) == 0); assertTrue(o2.compareTo(o1) == 0); }
public void testOpensCompareWithDifferentModifiers() { Opens o1 = opens(Set.of(Opens.Modifier.SYNTHETIC), "p"); Opens o2 = opens("p"); assertNotEquals(o1, o2); assertTrue(o1.compareTo(o2) == 1); assertTrue(o2.compareTo(o1) == -1); }
public void testOpenModule() { ModuleDescriptor descriptor = ModuleDescriptor.newOpenModule("foo") .requires("bar") .exports("p") .provides("p.Service", List.of("q.ServiceImpl")) .build(); // modifiers assertTrue(descriptor.modifiers().contains(ModuleDescriptor.Modifier.OPEN)); assertTrue(descriptor.isOpen()); // requires assertTrue(descriptor.requires().size() == 2); Set<String> names = descriptor.requires() .stream() .map(Requires::name) .collect(Collectors.toSet()); assertEquals(names, Set.of("bar", "java.base")); // packages assertEquals(descriptor.packages(), Set.of("p", "q")); // exports assertTrue(descriptor.exports().size() == 1); names = descriptor.exports() .stream() .map(Exports::source) .collect(Collectors.toSet()); assertEquals(names, Set.of("p")); // opens assertTrue(descriptor.opens().isEmpty()); }
public void testNewModuleToBuildOpenModule() { Set<ModuleDescriptor.Modifier> ms = Set.of(ModuleDescriptor.Modifier.OPEN); ModuleDescriptor descriptor = ModuleDescriptor.newModule("foo", ms).build(); assertTrue(descriptor.modifiers().equals(ms)); assertTrue(descriptor.isOpen()); ms = Set.of(ModuleDescriptor.Modifier.OPEN, ModuleDescriptor.Modifier.SYNTHETIC); descriptor = ModuleDescriptor.newModule("foo", ms).build(); assertTrue(descriptor.modifiers().equals(ms)); assertTrue(descriptor.isOpen()); }
/** * Test miscellaneous methods. */ public void testMisc() throws IOException { Path dir = Files.createTempDirectory(USER_DIR, "mods"); Path m_jar = createDummyJarFile(dir.resolve("m.jar"), "p/T.class"); ModuleFinder finder = ModuleFinder.of(m_jar); assertTrue(finder.find("m").isPresent()); ModuleDescriptor m = finder.find("m").get().descriptor(); // test miscellaneous methods assertTrue(m.isAutomatic()); assertFalse(m.modifiers().contains(ModuleDescriptor.Modifier.SYNTHETIC)); }
/** * Lookup the class in the exported packages of this module. "public * requires" modules are looked up. NB: static module readability can be * different at execution time. * * @param callerModule Name of calling module. * @param binaryName The class to lookup. * @return The reader or null if not found */ @Override public ClassReader getExportedClassReader(String callerModule, String binaryName) { Objects.requireNonNull(callerModule); Objects.requireNonNull(binaryName); boolean exported = false; ClassReader clazz = null; for (Exports e : descriptor.exports()) { String pkg = e.source(); Set<String> targets = e.targets(); System.out.println("PKG " + pkg); if (targets.isEmpty() || targets.contains(callerModule)) { if (binaryName.startsWith(pkg)) { String className = binaryName.substring(pkg.length()); System.out.println("CLASS " + className); exported = !className.contains("."); } if (exported) { break; } } } // public requires (re-export) if (!exported) { for (Requires requires : descriptor.requires()) { if (requires.modifiers().contains(Modifier.PUBLIC)) { AsmModulePool pool = pools.getModulePool(requires.name()); clazz = pool.getExportedClassReader(moduleName, binaryName); if (clazz != null) { break; } } } } else { clazz = getClassReader(binaryName); } return clazz; }
private Requires requires(Set<Modifier> mods, String mn) { return new Builder("m") .requires(mods, mn) .build() .requires() .iterator() .next(); }
public void testRequiresWithNoModifiers() { Requires r = requires(EnumSet.noneOf(Requires.Modifier.class), "foo"); assertEquals(r, r); assertTrue(r.compareTo(r) == 0); assertTrue(r.modifiers().isEmpty()); assertEquals(r.name(), "foo"); }
public void testRequiresWithAllModifiers() { Requires r = requires(EnumSet.allOf(Modifier.class), "foo"); assertEquals(r, r); assertTrue(r.compareTo(r) == 0); assertEquals(r.modifiers(), EnumSet.allOf(Modifier.class)); assertEquals(r.name(), "foo"); }
private void testModuleDescriptor(ModuleDescriptor md) { assertUnmodifiable(md.conceals(), "conceal"); assertUnmodifiable(md.packages(), "package"); assertUnmodifiable(md.requires(), jlma.newRequires(EnumSet.allOf(Modifier.class), "require")); assertUnmodifiable(md.exports(), jlma.newExports("export")); assertUnmodifiable(md.uses(), "use"); assertUnmodifiable(md.provides(), "provide", jlma.newProvides("provide", Collections.singleton("provide"))); }
private Requires requires(Set<Modifier> mods, String mn) { return requires(mods, mn, null); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testRequiresSelfWithAllModifiers() { ModuleDescriptor.newModule("m").requires(EnumSet.allOf(Modifier.class), "m"); }
@Test(dataProvider = "invalidNames", expectedExceptions = IllegalArgumentException.class ) public void testRequiresWithBadModuleName(String mn, String ignore) { requires(EnumSet.noneOf(Modifier.class), mn); }
public void testRequiresToString() { Requires r = requires(EnumSet.noneOf(Modifier.class), "foo"); assertTrue(r.toString().contains("foo")); }
public void testNewModuleToBuildAutomaticModule() { Set<ModuleDescriptor.Modifier> ms = Set.of(ModuleDescriptor.Modifier.AUTOMATIC); ModuleDescriptor descriptor = ModuleDescriptor.newModule("foo", ms).build(); assertTrue(descriptor.modifiers().equals(ms)); assertTrue(descriptor.isAutomatic()); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNewModuleToBuildAutomaticAndOpenModule() { Set<ModuleDescriptor.Modifier> ms = Set.of(ModuleDescriptor.Modifier.AUTOMATIC, ModuleDescriptor.Modifier.OPEN); ModuleDescriptor.newModule("foo", ms); }
/** * Basic test of a configuration created with automatic modules * a requires b * b requires transitive c* * c* * d* */ public void testInConfiguration3() throws IOException { ModuleDescriptor descriptor1 = ModuleDescriptor.newModule("a") .requires("b") .requires("java.base") .build(); ModuleDescriptor descriptor2 = ModuleDescriptor.newModule("b") .requires(Set.of(Modifier.TRANSITIVE), "c") .requires("java.base") .build(); // c and d are automatic modules Path dir = Files.createTempDirectory(USER_DIR, "mods"); createDummyJarFile(dir.resolve("c.jar"), "p/T.class"); createDummyJarFile(dir.resolve("d.jar"), "q/T.class"); // module finder locates a and the modules in the directory ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1, descriptor2); ModuleFinder finder2 = ModuleFinder.of(dir); ModuleFinder finder = ModuleFinder.compose(finder1, finder2); Configuration parent = ModuleLayer.boot().configuration(); Configuration cf = resolve(parent, finder, "a", "d"); assertTrue(cf.modules().size() == 4); assertTrue(cf.findModule("a").isPresent()); assertTrue(cf.findModule("b").isPresent()); assertTrue(cf.findModule("c").isPresent()); assertTrue(cf.findModule("d").isPresent()); ResolvedModule base = cf.findModule("java.base").get(); assertTrue(base.configuration() == ModuleLayer.boot().configuration()); ResolvedModule a = cf.findModule("a").get(); ResolvedModule b = cf.findModule("b").get(); ResolvedModule c = cf.findModule("c").get(); ResolvedModule d = cf.findModule("d").get(); // c && d should only require java.base assertTrue(findDescriptor(cf, "c").requires().size() == 1); assertTrue(findDescriptor(cf, "d").requires().size() == 1); // readability assertTrue(a.reads().size() == 4); assertTrue(a.reads().contains(b)); assertTrue(a.reads().contains(c)); assertTrue(a.reads().contains(d)); assertTrue(a.reads().contains(base)); assertTrue(b.reads().size() == 3); assertTrue(b.reads().contains(c)); assertTrue(b.reads().contains(d)); assertTrue(b.reads().contains(base)); assertTrue(reads(cf, "b", "c")); assertTrue(reads(cf, "b", "d")); assertTrue(reads(cf, "b", "java.base")); assertTrue(c.reads().contains(a)); assertTrue(c.reads().contains(b)); assertTrue(c.reads().contains(d)); testReadAllBootModules(cf, "c"); // c reads all modules in boot layer assertTrue(d.reads().contains(a)); assertTrue(d.reads().contains(b)); assertTrue(d.reads().contains(c)); testReadAllBootModules(cf, "d"); // d reads all modules in boot layer }
/** * Basic test of "requires public": * m1 requires m2, m2 requires public m3 */ public void testRequiresPublic1() { // m1 requires m2, m2 requires public m3 ModuleDescriptor descriptor1 = new ModuleDescriptor.Builder("m1") .requires("m2") .build(); ModuleDescriptor descriptor2 = new ModuleDescriptor.Builder("m2") .requires(Modifier.PUBLIC, "m3") .build(); ModuleDescriptor descriptor3 = new ModuleDescriptor.Builder("m3") .build(); ModuleFinder finder = ModuleUtils.finderOf(descriptor1, descriptor2, descriptor3); Configuration cf = resolveRequires(finder, "m1"); assertTrue(cf.modules().size() == 3); assertTrue(cf.findModule("m1").isPresent()); assertTrue(cf.findModule("m2").isPresent()); assertTrue(cf.findModule("m3").isPresent()); assertTrue(cf.parent().get() == Configuration.empty()); ResolvedModule m1 = cf.findModule("m1").get(); ResolvedModule m2 = cf.findModule("m2").get(); ResolvedModule m3 = cf.findModule("m3").get(); // m1 reads m2 and m3 assertTrue(m1.reads().size() == 2); assertTrue(m1.reads().contains(m2)); assertTrue(m1.reads().contains(m3)); // m2 reads m3 assertTrue(m2.reads().size() == 1); assertTrue(m2.reads().contains(m3)); // m3 reads nothing assertTrue(m3.reads().size() == 0); }
/** * Basic test of "requires public" with configurations. * * The test consists of three configurations: * - Configuration cf1: m1, m2 requires public m1 * - Configuration cf2: m3 requires m1 */ public void testRequiresPublic2() { // cf1: m1 and m2, m2 requires public m1 ModuleDescriptor descriptor1 = new ModuleDescriptor.Builder("m1") .build(); ModuleDescriptor descriptor2 = new ModuleDescriptor.Builder("m2") .requires(Modifier.PUBLIC, "m1") .build(); ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1, descriptor2); Configuration cf1 = resolveRequires(finder1, "m2"); assertTrue(cf1.modules().size() == 2); assertTrue(cf1.findModule("m1").isPresent()); assertTrue(cf1.findModule("m2").isPresent()); assertTrue(cf1.parent().get() == Configuration.empty()); ResolvedModule m1 = cf1.findModule("m1").get(); ResolvedModule m2 = cf1.findModule("m2").get(); assertTrue(m1.reads().size() == 0); assertTrue(m2.reads().size() == 1); assertTrue(m2.reads().contains(m1)); // cf2: m3, m3 requires m2 ModuleDescriptor descriptor3 = new ModuleDescriptor.Builder("m3") .requires("m2") .build(); ModuleFinder finder2 = ModuleUtils.finderOf(descriptor3); Configuration cf2 = resolveRequires(cf1, finder2, "m3"); assertTrue(cf2.modules().size() == 1); assertTrue(cf2.findModule("m1").isPresent()); // in parent assertTrue(cf2.findModule("m2").isPresent()); // in parent assertTrue(cf2.findModule("m3").isPresent()); assertTrue(cf2.parent().get() == cf1); ResolvedModule m3 = cf2.findModule("m3").get(); assertTrue(m3.configuration() == cf2); assertTrue(m3.reads().size() == 2); assertTrue(m3.reads().contains(m1)); assertTrue(m3.reads().contains(m2)); }
/** * Basic test of "requires public" with configurations. * * The test consists of three configurations: * - Configuration cf1: m1 * - Configuration cf2: m2 requires public m3, m3 requires m2 */ public void testRequiresPublic3() { // cf1: m1 ModuleDescriptor descriptor1 = new ModuleDescriptor.Builder("m1") .build(); ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1); Configuration cf1 = resolveRequires(finder1, "m1"); assertTrue(cf1.modules().size() == 1); assertTrue(cf1.findModule("m1").isPresent()); assertTrue(cf1.parent().get() == Configuration.empty()); ResolvedModule m1 = cf1.findModule("m1").get(); assertTrue(m1.reads().size() == 0); // cf2: m2, m3: m2 requires public m1, m3 requires m2 ModuleDescriptor descriptor2 = new ModuleDescriptor.Builder("m2") .requires(Modifier.PUBLIC, "m1") .build(); ModuleDescriptor descriptor3 = new ModuleDescriptor.Builder("m3") .requires("m2") .build(); ModuleFinder finder2 = ModuleUtils.finderOf(descriptor2, descriptor3); Configuration cf2 = resolveRequires(cf1, finder2, "m3"); assertTrue(cf2.modules().size() == 2); assertTrue(cf2.findModule("m1").isPresent()); // in parent assertTrue(cf2.findModule("m2").isPresent()); assertTrue(cf2.findModule("m3").isPresent()); assertTrue(cf2.parent().get() == cf1); ResolvedModule m2 = cf2.findModule("m2").get(); ResolvedModule m3 = cf2.findModule("m3").get(); assertTrue(m2.configuration() == cf2); assertTrue(m2.reads().size() == 1); assertTrue(m2.reads().contains(m1)); assertTrue(m3.configuration() == cf2); assertTrue(m3.reads().size() == 2); assertTrue(m3.reads().contains(m1)); assertTrue(m3.reads().contains(m2)); }
/** * Basic test of "requires public" with configurations. * * The test consists of three configurations: * - Configuration cf1: m1 * - Configuration cf2: m2 requires public m1 * - Configuraiton cf3: m3 requires m3 */ public void testRequiresPublic4() { // cf1: m1 ModuleDescriptor descriptor1 = new ModuleDescriptor.Builder("m1") .build(); ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1); Configuration cf1 = resolveRequires(finder1, "m1"); assertTrue(cf1.modules().size() == 1); assertTrue(cf1.findModule("m1").isPresent()); assertTrue(cf1.parent().get() == Configuration.empty()); ResolvedModule m1 = cf1.findModule("m1").get(); assertTrue(m1.reads().size() == 0); // cf2: m2 requires public m1 ModuleDescriptor descriptor2 = new ModuleDescriptor.Builder("m2") .requires(Modifier.PUBLIC, "m1") .build(); ModuleFinder finder2 = ModuleUtils.finderOf(descriptor2); Configuration cf2 = resolveRequires(cf1, finder2, "m2"); assertTrue(cf2.modules().size() == 1); assertTrue(cf2.findModule("m1").isPresent()); // in parent assertTrue(cf2.findModule("m2").isPresent()); assertTrue(cf2.parent().get() == cf1); ResolvedModule m2 = cf2.findModule("m2").get(); assertTrue(m2.configuration() == cf2); assertTrue(m2.reads().size() == 1); assertTrue(m2.reads().contains(m1)); // cf3: m3 requires m2 ModuleDescriptor descriptor3 = new ModuleDescriptor.Builder("m3") .requires("m2") .build(); ModuleFinder finder3 = ModuleUtils.finderOf(descriptor3); Configuration cf3 = resolveRequires(cf2, finder3, "m3"); assertTrue(cf3.modules().size() == 1); assertTrue(cf3.findModule("m1").isPresent()); // in parent assertTrue(cf3.findModule("m2").isPresent()); // in parent assertTrue(cf3.findModule("m3").isPresent()); assertTrue(cf3.parent().get() == cf2); ResolvedModule m3 = cf3.findModule("m3").get(); assertTrue(m3.configuration() == cf3); assertTrue(m3.reads().size() == 2); assertTrue(m3.reads().contains(m1)); assertTrue(m3.reads().contains(m2)); }
/** * Basic test of "requires public" with configurations. * * The test consists of two configurations: * - Configuration cf1: m1, m2 requires public m1 * - Configuration cf2: m3 requires public m2, m4 requires m3 */ public void testRequiresPublic5() { // cf1: m1, m2 requires public m1 ModuleDescriptor descriptor1 = new ModuleDescriptor.Builder("m1") .build(); ModuleDescriptor descriptor2 = new ModuleDescriptor.Builder("m2") .requires(Modifier.PUBLIC, "m1") .build(); ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1, descriptor2); Configuration cf1 = resolveRequires(finder1, "m2"); assertTrue(cf1.modules().size() == 2); assertTrue(cf1.findModule("m1").isPresent()); assertTrue(cf1.findModule("m2").isPresent()); assertTrue(cf1.parent().get() == Configuration.empty()); ResolvedModule m1 = cf1.findModule("m1").get(); ResolvedModule m2 = cf1.findModule("m2").get(); assertTrue(m1.configuration() == cf1); assertTrue(m1.reads().size() == 0); assertTrue(m2.configuration() == cf1); assertTrue(m2.reads().size() == 1); assertTrue(m2.reads().contains(m1)); // cf2: m3 requires public m2, m4 requires m3 ModuleDescriptor descriptor3 = new ModuleDescriptor.Builder("m3") .requires(Modifier.PUBLIC, "m2") .build(); ModuleDescriptor descriptor4 = new ModuleDescriptor.Builder("m4") .requires("m3") .build(); ModuleFinder finder2 = ModuleUtils.finderOf(descriptor3, descriptor4); Configuration cf2 = resolveRequires(cf1, finder2, "m3", "m4"); assertTrue(cf2.modules().size() == 2); assertTrue(cf2.findModule("m1").isPresent()); // in parent assertTrue(cf2.findModule("m2").isPresent()); // in parent assertTrue(cf2.findModule("m3").isPresent()); assertTrue(cf2.findModule("m4").isPresent()); assertTrue(cf2.parent().get() == cf1); ResolvedModule m3 = cf2.findModule("m3").get(); ResolvedModule m4 = cf2.findModule("m4").get(); assertTrue(m3.configuration() == cf2); assertTrue(m3.reads().size() == 2); assertTrue(m3.reads().contains(m1)); assertTrue(m3.reads().contains(m2)); assertTrue(m4.configuration() == cf2); assertTrue(m4.reads().size() == 3); assertTrue(m4.reads().contains(m1)); assertTrue(m4.reads().contains(m2)); assertTrue(m4.reads().contains(m3)); }
/** * Basic test of using the beforeFinder to override a module in the parent * configuration but where implied readability in the picture so that the * module in the parent is read. * * The test consists of two configurations: * - Configuration cf1: m1, m2 requires public m1 * - Configuration cf2: m1, m3 requires m2 */ public void testOverriding2() { ModuleDescriptor descriptor1 = new ModuleDescriptor.Builder("m1") .build(); ModuleDescriptor descriptor2 = new ModuleDescriptor.Builder("m2") .requires(Modifier.PUBLIC, "m1") .build(); ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1, descriptor2); Configuration cf1 = resolveRequires(finder1, "m2"); assertTrue(cf1.modules().size() == 2); assertTrue(cf1.findModule("m1").isPresent()); assertTrue(cf1.findModule("m2").isPresent()); // cf2: m3 requires m2, m1 ModuleDescriptor descriptor3 = new ModuleDescriptor.Builder("m3") .requires("m2") .build(); ModuleFinder finder2 = ModuleUtils.finderOf(descriptor1, descriptor3); Configuration cf2 = resolveRequires(cf1, finder2, "m1", "m3"); assertTrue(cf2.parent().get() == cf1); assertTrue(cf2.modules().size() == 2); assertTrue(cf2.findModule("m1").isPresent()); assertTrue(cf2.findModule("m3").isPresent()); ResolvedModule m1_1 = cf1.findModule("m1").get(); ResolvedModule m1_2 = cf2.findModule("m1").get(); ResolvedModule m2 = cf1.findModule("m2").get(); ResolvedModule m3 = cf2.findModule("m3").get(); assertTrue(m1_1.configuration() == cf1); assertTrue(m1_2.configuration() == cf2); assertTrue(m3.configuration() == cf2); // check that m3 reads cf1/m1 and cf2/m2 assertTrue(m3.reads().size() == 2); assertTrue(m3.reads().contains(m1_1)); assertTrue(m3.reads().contains(m2)); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testRequiresSelfWithAllModifiers() { new Builder("m").requires(EnumSet.allOf(Modifier.class), "m"); }
@Test(dataProvider = "invalidjavaidentifiers", expectedExceptions = IllegalArgumentException.class ) public void testRequiresWithBadModuleName(String mn, String ignore) { requires(EnumSet.noneOf(Modifier.class), mn); }