use of org.sonar.java.bytecode.loader.SquidClassLoader in project sonar-java by SonarSource.
the class ExceptionalYieldTest method test_equals.
@Test
public void test_equals() {
MethodBehavior methodBehavior = mockMethodBehavior();
ExceptionalYield yield = new ExceptionalYield(methodBehavior);
ExceptionalYield otherYield = new ExceptionalYield(methodBehavior);
assertThat(yield).isNotEqualTo(null);
assertThat(yield).isEqualTo(yield);
assertThat(yield).isEqualTo(otherYield);
otherYield.setExceptionType("java.lang.Exception");
assertThat(yield).isNotEqualTo(otherYield);
yield.setExceptionType("java.lang.Exception");
assertThat(yield).isEqualTo(otherYield);
SemanticModel semanticModel = SemanticModel.createFor((CompilationUnitTree) JavaParser.createParser().parse("class A{}"), new SquidClassLoader(new ArrayList<>()));
assertThat(yield.exceptionType(semanticModel)).isEqualTo(otherYield.exceptionType(semanticModel));
// same arity and parameters but happy yield
assertThat(yield).isNotEqualTo(new HappyPathYield(methodBehavior));
}
use of org.sonar.java.bytecode.loader.SquidClassLoader in project sonar-java by SonarSource.
the class UCFGJavaVisitorTest method setUp.
@BeforeClass
public static void setUp() {
File testJarsDir = new File("target/test-jars/");
squidClassLoader = new SquidClassLoader(Arrays.asList(testJarsDir.listFiles()));
}
use of org.sonar.java.bytecode.loader.SquidClassLoader in project sonar-java by SonarSource.
the class BytecodeCFGBuilderTest method getBytecodeCFG.
public static BytecodeCFG getBytecodeCFG(String methodName, String filename) {
SquidClassLoader squidClassLoader = new SquidClassLoader(Lists.newArrayList(new File("target/test-classes"), new File("target/classes")));
File file = new File(filename);
CompilationUnitTree tree = (CompilationUnitTree) JavaParser.createParser().parse(file);
SemanticModel.createFor(tree, squidClassLoader);
List<Tree> classMembers = ((ClassTree) tree.types().get(0)).members();
Symbol.MethodSymbol symbol = classMembers.stream().filter(m -> m instanceof MethodTree).map(m -> ((MethodTree) m).symbol()).filter(s -> methodName.equals(s.name())).findFirst().orElseThrow(IllegalStateException::new);
return SETestUtils.bytecodeCFG(((JavaSymbol.MethodJavaSymbol) symbol).completeSignature(), squidClassLoader);
}
use of org.sonar.java.bytecode.loader.SquidClassLoader in project sonar-java by SonarSource.
the class BytecodeCFGBuilderTest method isNotBlank_goto_followed_by_label.
@Test
public void isNotBlank_goto_followed_by_label() throws Exception {
SquidClassLoader classLoader = new SquidClassLoader(Lists.newArrayList(new File("src/test/commons-lang-2.1")));
// apache commons 2.1 isNotBlank has a goto followed by an unreferenced label : see SONARJAVA-2461
BytecodeCFG bytecodeCFG = SETestUtils.bytecodeCFG("org.apache.commons.lang.StringUtils#isNotBlank(Ljava/lang/String;)Z", classLoader);
assertThat(bytecodeCFG).isNotNull();
assertThat(bytecodeCFG.blocks).hasSize(11);
assertThat(bytecodeCFG.blocks.get(4).successors).containsExactly(bytecodeCFG.blocks.get(6));
}
use of org.sonar.java.bytecode.loader.SquidClassLoader in project sonar-java by SonarSource.
the class BytecodeCFGBuilderTest method supportJSRandRET.
@Test
public void supportJSRandRET() throws Exception {
SquidClassLoader classLoader = new SquidClassLoader(Lists.newArrayList(new File("src/test/JsrRet")));
BytecodeCFG bytecodeCFG = SETestUtils.bytecodeCFG("jdk3.AllInstructions#jsrAndRetInstructions(I)I", classLoader);
assertThat(bytecodeCFG).isNotNull();
bytecodeCFG.blocks.stream().map(b -> b.terminator).filter(Objects::nonNull).forEach(t -> assertThat(t.opcode).isNotEqualTo(JSR));
}
Aggregations