use of org.sonar.java.se.xproc.ExceptionalYield in project sonar-java by SonarSource.
the class BehaviorCacheTest method clear_stack_when_taking_exceptional_path_from_method_invocation.
@Test
public void clear_stack_when_taking_exceptional_path_from_method_invocation() throws Exception {
Pair<SymbolicExecutionVisitor, SemanticModel> sevAndSemantic = createSymbolicExecutionVisitorAndSemantic("src/test/files/se/CleanStackWhenRaisingException.java");
SymbolicExecutionVisitor sev = sevAndSemantic.a;
SemanticModel semanticModel = sevAndSemantic.b;
MethodBehavior behavior = getMethodBehavior(sev, "foo");
assertThat(behavior.yields()).hasSize(4);
behavior.happyPathYields().forEach(y -> assertThat(y.resultConstraint()).isNull());
assertThat(behavior.happyPathYields().count()).isEqualTo(1);
List<ExceptionalYield> exceptionalYields = behavior.exceptionalPathYields().collect(Collectors.toList());
assertThat(exceptionalYields).hasSize(3);
assertThat(exceptionalYields.stream().filter(y -> y.exceptionType(semanticModel).isUnknown())).hasSize(1);
}
use of org.sonar.java.se.xproc.ExceptionalYield in project sonar-java by SonarSource.
the class BytecodeEGWalkerTest method test_enqueueing_of_catch_blocks.
@Test
public void test_enqueueing_of_catch_blocks() {
MethodBehavior mb = getMethodBehavior(ExceptionEnqueue.class, "testCatchBlockEnqueue(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.lang.RuntimeException")).isTrue();
}
use of org.sonar.java.se.xproc.ExceptionalYield in project sonar-java by SonarSource.
the class BytecodeEGWalkerTest method test_enqueueing_of_exit_block3.
@Test
public void test_enqueueing_of_exit_block3() {
MethodBehavior mb = getMethodBehavior(ExceptionEnqueue.class, "enqueueExitBlock3()Z");
assertThat(mb.happyPathYields().findFirst().isPresent()).isFalse();
List<ExceptionalYield> exceptionalYields = mb.exceptionalPathYields().collect(Collectors.toList());
assertThat(exceptionalYields).hasSize(1);
assertThat(exceptionalYields.get(0).exceptionType(semanticModel).is("java.io.FileNotFoundException")).isTrue();
}
use of org.sonar.java.se.xproc.ExceptionalYield in project sonar-java by SonarSource.
the class BytecodeEGWalkerTest method test_enqueueing_of_exit_block.
@Test
public void test_enqueueing_of_exit_block() {
MethodBehavior mb = getMethodBehavior(ExceptionEnqueue.class, "enqueueExitBlock()Z");
List<MethodYield> yields = mb.yields();
assertThat(yields).hasSize(1);
assertThat(mb.happyPathYields().findFirst().isPresent()).isFalse();
ExceptionalYield exceptionalYield = mb.exceptionalPathYields().findFirst().get();
Type exceptionType = exceptionalYield.exceptionType(semanticModel);
assertThat(exceptionType.is("java.io.FileNotFoundException")).isTrue();
}
use of org.sonar.java.se.xproc.ExceptionalYield 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();
}
Aggregations