Search in sources :

Example 11 with SECheck

use of org.sonar.java.se.checks.SECheck in project sonar-java by SonarSource.

the class ExceptionalCheckBasedYieldTest method exceptionType_is_required.

@Test
public void exceptionType_is_required() {
    thrown.expect(IllegalArgumentException.class);
    final Class<? extends SECheck> seCheckClass = new SECheck() {
    }.getClass();
    String exceptionType = null;
    new ExceptionalCheckBasedYield(SV_CAUSING_EXCEPTION, exceptionType, seCheckClass, null, mockMethodBehavior());
}
Also used : SECheck(org.sonar.java.se.checks.SECheck) Test(org.junit.Test)

Example 12 with SECheck

use of org.sonar.java.se.checks.SECheck in project sonar-java by SonarSource.

the class ExceptionalCheckBasedYieldTest method test_equals.

@Test
public void test_equals() {
    final Class<? extends SECheck> seCheckClass1 = new SECheck() {
    }.getClass();
    final Class<? extends SECheck> seCheckClass2 = (new SECheck() {
    }).getClass();
    MethodBehavior mb = mockMethodBehavior();
    String mockedExceptionType1 = "SomeException";
    ExceptionalCheckBasedYield yield = new ExceptionalCheckBasedYield(SV_CAUSING_EXCEPTION, mockedExceptionType1, seCheckClass1, null, mb);
    ExceptionalYield otherYield = new ExceptionalCheckBasedYield(SV_CAUSING_EXCEPTION, mockedExceptionType1, seCheckClass1, null, mb);
    assertThat(yield).isNotEqualTo(null);
    assertThat(yield).isEqualTo(yield);
    assertThat(yield).isEqualTo(otherYield);
    // same exception, but simple exceptional yield
    otherYield = new ExceptionalYield(null, mb);
    otherYield.setExceptionType(mockedExceptionType1);
    assertThat(yield).isNotEqualTo(otherYield);
    // same exception, different SV
    otherYield = new ExceptionalCheckBasedYield(new SymbolicValue(), mockedExceptionType1, seCheckClass2, null, mb);
    assertThat(yield).isNotEqualTo(otherYield);
    // same exception, different check
    otherYield = new ExceptionalCheckBasedYield(SV_CAUSING_EXCEPTION, mockedExceptionType1, seCheckClass2, null, mb);
    assertThat(yield).isNotEqualTo(otherYield);
    // different exception, same check
    otherYield = new ExceptionalCheckBasedYield(SV_CAUSING_EXCEPTION, "SomeOtherException", seCheckClass1, null, mb);
    assertThat(yield).isNotEqualTo(otherYield);
}
Also used : SECheck(org.sonar.java.se.checks.SECheck) SETestUtils.mockMethodBehavior(org.sonar.java.se.SETestUtils.mockMethodBehavior) SETestUtils.getMethodBehavior(org.sonar.java.se.SETestUtils.getMethodBehavior) SymbolicValue(org.sonar.java.se.symbolicvalues.SymbolicValue) Test(org.junit.Test)

Aggregations

SECheck (org.sonar.java.se.checks.SECheck)12 Test (org.junit.Test)11 SETestUtils.getMethodBehavior (org.sonar.java.se.SETestUtils.getMethodBehavior)4 MethodTree (org.sonar.plugins.java.api.tree.MethodTree)4 Tree (org.sonar.plugins.java.api.tree.Tree)4 ArrayList (java.util.ArrayList)3 SETestUtils.createSymbolicExecutionVisitor (org.sonar.java.se.SETestUtils.createSymbolicExecutionVisitor)3 SETestUtils.mockMethodBehavior (org.sonar.java.se.SETestUtils.mockMethodBehavior)3 SymbolicValue (org.sonar.java.se.symbolicvalues.SymbolicValue)3 MethodInvocationTree (org.sonar.plugins.java.api.tree.MethodInvocationTree)3 File (java.io.File)2 CFG (org.sonar.java.cfg.CFG)2 SemanticModel (org.sonar.java.resolve.SemanticModel)2 SymbolicExecutionVisitor (org.sonar.java.se.SymbolicExecutionVisitor)2 ImmutableList (com.google.common.collect.ImmutableList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)1 SonarComponents (org.sonar.java.SonarComponents)1