ClassloadRules { public boolean canLoad(String className) { return unmaskSize(className) > maskSize(className); } ClassloadRules(Set<String> maskRules, Set<String> unmaskRules); boolean canLoad(String className);  }
@Test public void testUnmask() { unmaskRules.add("org.apache.ant."); rules = new ClassloadRules(maskRules, unmaskRules); assertThat(rules.canLoad("org.sonar.runner.Foo")).isFalse(); assertThat(rules.canLoad("org.objectweb.asm.ClassVisitor")).isFalse(); assertThat(rules.canLoad("org.apache")).isFalse(); assertThat(rules.canLoad("org.apache.ant.Foo")).isTrue(); assertThat(rules.canLoad("org.apache.ant.project.Project")).isTrue(); }
@Test public void testUnmaskAll() { unmaskRules.add(""); rules = new ClassloadRules(maskRules, unmaskRules); assertThat(rules.canLoad("org.sonar.runner.Foo")).isTrue(); assertThat(rules.canLoad("org.objectweb.asm.ClassVisitor")).isTrue(); assertThat(rules.canLoad("org.apache")).isTrue(); assertThat(rules.canLoad("org.apache.ant.Foo")).isTrue(); assertThat(rules.canLoad("org.apache.ant.project.Project")).isTrue(); }
@Test public void testDefault() { rules = new ClassloadRules(maskRules, unmaskRules); assertThat(rules.canLoad("org.sonar.runner.Foo")).isFalse(); }
@Test public void testMaskAndUnmask() throws ClassNotFoundException { unmaskRules.add("org.apache.ant."); maskRules.add("org.apache.ant.foo."); rules = new ClassloadRules(maskRules, unmaskRules); assertThat(rules.canLoad("org.apache.ant.something")).isTrue(); assertThat(rules.canLoad("org.apache.ant.foo.something")).isFalse(); assertThat(rules.canLoad("org.apache")).isFalse(); }
@Test public void testUsedByMaven() { maskRules.add( "org.slf4j.LoggerFactory" ); unmaskRules.add( "org.slf4j.Logger" ); unmaskRules.add( "org.slf4j.ILoggerFactory" ); maskRules.add( "org.slf4j." ); maskRules.add( "ch.qos.logback." ); maskRules.add( "org.sonar." ); unmaskRules.add("org.sonar.runner.batch."); maskRules.add( "com.google.common" ); unmaskRules.add( "" ); rules = new ClassloadRules(maskRules, unmaskRules); assertThat(rules.canLoad("org.sonar.runner.batch.IsolatedLauncher")).isTrue(); }