Search in sources :

Example 1 with ExceptionEnqueue

use of org.sonar.java.bytecode.se.testdata.ExceptionEnqueue 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");
}
Also used : BytecodeTestClass(org.sonar.java.bytecode.se.testdata.BytecodeTestClass) ObjectConstraint(org.sonar.java.se.constraint.ObjectConstraint) Iterables(com.google.common.collect.Iterables) BeforeClass(org.junit.BeforeClass) ProgramState(org.sonar.java.se.ProgramState) MethodYield(org.sonar.java.se.xproc.MethodYield) CompilationUnitTree(org.sonar.plugins.java.api.tree.CompilationUnitTree) ExceptionEnqueue(org.sonar.java.bytecode.se.testdata.ExceptionEnqueue) DivisionByZeroCheck(org.sonar.java.se.checks.DivisionByZeroCheck) Lists(com.google.common.collect.Lists) Assertions.assertThat(org.fest.assertions.Assertions.assertThat) FinalBytecodeTestClass(org.sonar.java.bytecode.se.testdata.FinalBytecodeTestClass) SymbolicValue(org.sonar.java.se.symbolicvalues.SymbolicValue) MethodBehavior(org.sonar.java.se.xproc.MethodBehavior) BooleanConstraint(org.sonar.java.se.constraint.BooleanConstraint) JavaParser(org.sonar.java.ast.parser.JavaParser) Collection(java.util.Collection) SquidClassLoader(org.sonar.java.bytecode.loader.SquidClassLoader) MaxRelationBytecode(org.sonar.java.bytecode.se.testdata.MaxRelationBytecode) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) Type(org.sonar.plugins.java.api.semantic.Type) Collectors(java.util.stream.Collectors) File(java.io.File) List(java.util.List) Rule(org.junit.Rule) LogTester(org.sonar.api.utils.log.LogTester) SemanticModel(org.sonar.java.resolve.SemanticModel) ByteStreams(com.google.common.io.ByteStreams) BehaviorCache(org.sonar.java.se.xproc.BehaviorCache) Constraint(org.sonar.java.se.constraint.Constraint) ExceptionalYield(org.sonar.java.se.xproc.ExceptionalYield) HappyPathYield(org.sonar.java.se.xproc.HappyPathYield) LoggerLevel(org.sonar.api.utils.log.LoggerLevel) ObjectConstraint(org.sonar.java.se.constraint.ObjectConstraint) BooleanConstraint(org.sonar.java.se.constraint.BooleanConstraint) Constraint(org.sonar.java.se.constraint.Constraint) MethodBehavior(org.sonar.java.se.xproc.MethodBehavior) Test(org.junit.Test)

Aggregations

Iterables (com.google.common.collect.Iterables)1 Lists (com.google.common.collect.Lists)1 ByteStreams (com.google.common.io.ByteStreams)1 File (java.io.File)1 Collection (java.util.Collection)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 FileUtils (org.apache.commons.io.FileUtils)1 Assertions.assertThat (org.fest.assertions.Assertions.assertThat)1 BeforeClass (org.junit.BeforeClass)1 Rule (org.junit.Rule)1 Test (org.junit.Test)1 LogTester (org.sonar.api.utils.log.LogTester)1 LoggerLevel (org.sonar.api.utils.log.LoggerLevel)1 JavaParser (org.sonar.java.ast.parser.JavaParser)1 SquidClassLoader (org.sonar.java.bytecode.loader.SquidClassLoader)1 BytecodeTestClass (org.sonar.java.bytecode.se.testdata.BytecodeTestClass)1 ExceptionEnqueue (org.sonar.java.bytecode.se.testdata.ExceptionEnqueue)1 FinalBytecodeTestClass (org.sonar.java.bytecode.se.testdata.FinalBytecodeTestClass)1 MaxRelationBytecode (org.sonar.java.bytecode.se.testdata.MaxRelationBytecode)1