use of org.sonar.java.se.xproc.MethodBehavior in project sonar-java by SonarSource.
the class BytecodeEGWalkerTest method test_enqueueing_of_exit_block2.
@Test
public void test_enqueueing_of_exit_block2() {
MethodBehavior mb = getMethodBehavior(ExceptionEnqueue.class, "enqueueExitBlock2(Lorg/sonar/java/bytecode/se/testdata/ExceptionEnqueue;)Z");
List<HappyPathYield> happyPathYields = mb.happyPathYields().collect(Collectors.toList());
assertThat(happyPathYields).hasSize(1);
assertThat(happyPathYields.get(0).resultConstraint()).isNull();
List<ExceptionalYield> exceptionalYields = mb.exceptionalPathYields().collect(Collectors.toList());
assertThat(exceptionalYields).hasSize(1);
assertThat(exceptionalYields.get(0).exceptionType(semanticModel).is("java.io.IOException")).isTrue();
}
use of org.sonar.java.se.xproc.MethodBehavior in project sonar-java by SonarSource.
the class BytecodeEGWalkerTest method test_int_comparator.
@Test
public void test_int_comparator() throws Exception {
MethodBehavior methodBehavior = getMethodBehavior("int_comparison(II)Ljava/lang/Object;");
assertThat(methodBehavior.yields()).hasSize(1);
HappyPathYield methodYield = ((HappyPathYield) methodBehavior.yields().get(0));
assertThat(methodYield.resultConstraint().get(ObjectConstraint.class)).isSameAs(ObjectConstraint.NULL);
}
use of org.sonar.java.se.xproc.MethodBehavior in project sonar-java by SonarSource.
the class BytecodeEGWalkerTest method method_array.
@Test
public void method_array() throws Exception {
BytecodeEGWalker walker = getBytecodeEGWalker(squidClassLoader);
MethodBehavior behavior = walker.getMethodBehavior("java.lang.Class[]#clone()Ljava/lang/Object;", squidClassLoader);
assertThat(behavior).isNull();
}
use of org.sonar.java.se.xproc.MethodBehavior in project sonar-java by SonarSource.
the class BytecodeEGWalkerTest method unchecked_exceptions_should_be_enqueued.
@Test
public void unchecked_exceptions_should_be_enqueued() {
MethodBehavior mb = getMethodBehavior(ExceptionEnqueue.class, "test(Lorg/sonar/java/bytecode/se/testdata/ExceptionEnqueue;)Ljava/lang/Object;");
List<Constraint> resultConstraint = mb.happyPathYields().map(y -> y.resultConstraint().get(ObjectConstraint.class)).collect(Collectors.toList());
assertThat(resultConstraint).contains(ObjectConstraint.NOT_NULL, ObjectConstraint.NULL);
List<String> exceptions = mb.exceptionalPathYields().map(y -> y.exceptionType(semanticModel).fullyQualifiedName()).collect(Collectors.toList());
assertThat(exceptions).contains("org.sonar.java.bytecode.se.testdata.ExceptionEnqueue$ExceptionCatch", "org.sonar.java.bytecode.se.testdata.ExceptionEnqueue$ThrowableCatch", "org.sonar.java.bytecode.se.testdata.ExceptionEnqueue$ErrorCatch");
}
use of org.sonar.java.se.xproc.MethodBehavior in project sonar-java by SonarSource.
the class BytecodeEGWalkerTest method test_enqueueing_of_exit_block4.
@Test
public void test_enqueueing_of_exit_block4() {
MethodBehavior mb = getMethodBehavior(ExceptionEnqueue.class, "enqueueExitBlock4()Z");
List<HappyPathYield> happyPathYields = mb.happyPathYields().collect(Collectors.toList());
assertThat(happyPathYields.get(0).resultConstraint().hasConstraint(BooleanConstraint.TRUE)).isTrue();
assertThat(mb.exceptionalPathYields().findFirst().isPresent()).isFalse();
}
Aggregations