Skip to content

Commit

Permalink
Testing Spotbugs
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Sep 12, 2018
1 parent 4b6c5c0 commit 4577803
Show file tree
Hide file tree
Showing 3 changed files with 242 additions and 34 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ It supports:
* [_CSSLint_](https://github.com/CSSLint/csslint)
* [_DocFX_](http://dotnet.github.io/docfx/)
* [_Findbugs_](http://findbugs.sourceforge.net/)
* [_Spotbugs_](https://spotbugs.github.io/)
* [_Flake8_](http://flake8.readthedocs.org/en/latest/)
* [_AnsibleLint_](https://github.com/willthames/ansible-lint) with `-p`
* [_Mccabe_](https://pypi.python.org/pypi/mccabe)
Expand Down
90 changes: 56 additions & 34 deletions src/test/java/se/bjurr/violations/lib/FindbugsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,17 @@
import static se.bjurr.violations.lib.TestUtils.getRootFolder;
import static se.bjurr.violations.lib.ViolationsApi.violationsApi;
import static se.bjurr.violations.lib.model.SEVERITY.ERROR;
import static se.bjurr.violations.lib.model.SEVERITY.INFO;
import static se.bjurr.violations.lib.parsers.FindbugsParser.FINDBUGS_SPECIFIC_RANK;
import static se.bjurr.violations.lib.reports.Parser.FINDBUGS;

import java.util.List;
import org.junit.Before;
import org.junit.Test;
import se.bjurr.violations.lib.model.SEVERITY;
import se.bjurr.violations.lib.model.Violation;

public class FindbugsTest {

private List<Violation> actual;

@Before
public void before() {
final String rootFolder = getRootFolder();
actual =
violationsApi() //
.withPattern(".*/findbugs/main\\.xml$") //
.inFolder(rootFolder) //
.findAll(FINDBUGS) //
.violations();

assertThat(actual) //
.hasSize(5);
}

@Test
public void testMavenGeneratedFindbugs() {
final String rootFolder = getRootFolder();
Expand All @@ -46,37 +31,74 @@ public void testMavenGeneratedFindbugs() {
}

@Test
public void testThatEqualsUseHashCodeCanBeParsed() {
final Iterable<Violation> equalsUseHashCode = filterRule(actual, "HE_EQUALS_USE_HASHCODE");
public void testThatViolationsCanBeParsed() {
final String rootFolder = getRootFolder();
final List<Violation> actual =
violationsApi() //
.withPattern(".*/findbugs/main\\.xml$") //
.inFolder(rootFolder) //
.findAll(FINDBUGS) //
.violations();

Iterable<Violation> equalsUseHashCode = filterRule(actual, "NM_FIELD_NAMING_CONVENTION");
assertThat(equalsUseHashCode) //
.hasSize(1);
}

@Test
public void testThatNamingConventionCanBeParsed() {
final Iterable<Violation> equalsUseHashCode = filterRule(actual, "NM_FIELD_NAMING_CONVENTION");
equalsUseHashCode = filterRule(actual, "HE_EQUALS_USE_HASHCODE");
assertThat(equalsUseHashCode) //
.hasSize(1);
}

@Test
public void testThatViolationsCanBeParsed() {
assertThat(actual.get(0).getFile()) //
assertThat(actual) //
.hasSize(5);
final Violation violation0 = actual.get(0);
assertThat(violation0.getFile()) //
.isEqualTo("se/bjurr/violations/lib/example/MyClass.java");
assertThat(actual.get(0).getMessage()) //
assertThat(violation0.getMessage()) //
.startsWith("equals method always returns true") //
.doesNotContain("CDATA");
assertThat(actual.get(0).getStartLine()) //
assertThat(violation0.getStartLine()) //
.isEqualTo(17);
assertThat(actual.get(0).getEndLine()) //
assertThat(violation0.getEndLine()) //
.isEqualTo(17);
assertThat(actual.get(0).getRule()) //
assertThat(violation0.getRule()) //
.isEqualTo("EQ_ALWAYS_TRUE");
assertThat(actual.get(0).getSeverity()) //
assertThat(violation0.getSeverity()) //
.isEqualTo(ERROR);
assertThat(actual.get(0).getSource()) //
assertThat(violation0.getSource()) //
.isEqualTo("se.bjurr.violations.lib.example.MyClass");
assertThat(actual.get(0).getSpecifics().get(FINDBUGS_SPECIFIC_RANK)) //
assertThat(violation0.getSpecifics().get(FINDBUGS_SPECIFIC_RANK)) //
.isEqualTo("7");
}

@Test
public void testThatViolationsCanBeParsedFromSpotbugs() {
final String rootFolder = getRootFolder();
final List<Violation> actual =
violationsApi() //
.withPattern(".*/findbugs/spotbugs\\.xml$") //
.inFolder(rootFolder) //
.findAll(FINDBUGS) //
.violations();

assertThat(actual) //
.hasSize(3);
final Violation violation0 = actual.get(0);
assertThat(violation0.getFile()) //
.isEqualTo("se/bjurr/violations/lib/parsers/FindbugsParser.java");
assertThat(violation0.getMessage()) //
.startsWith("Method invokes toString") //
.doesNotContain("CDATA");
assertThat(violation0.getStartLine()) //
.isEqualTo(125);
assertThat(violation0.getEndLine()) //
.isEqualTo(125);
assertThat(violation0.getRule()) //
.isEqualTo("DM_STRING_TOSTRING");
assertThat(violation0.getSeverity()) //
.isEqualTo(INFO);
assertThat(violation0.getSource()) //
.isEqualTo("se.bjurr.violations.lib.parsers.FindbugsParser");
assertThat(violation0.getSpecifics().get(FINDBUGS_SPECIFIC_RANK)) //
.isEqualTo("20");
}
}
Loading

0 comments on commit 4577803

Please sign in to comment.