-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
71746a1
commit 30788ad
Showing
2 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package se.bjurr.violations.lib.util; | ||
|
||
import static se.bjurr.violations.lib.model.SEVERITY.ERROR; | ||
import static se.bjurr.violations.lib.model.SEVERITY.INFO; | ||
import static se.bjurr.violations.lib.model.SEVERITY.WARN; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import se.bjurr.violations.lib.model.SEVERITY; | ||
import se.bjurr.violations.lib.model.Violation; | ||
|
||
public final class Filtering { | ||
private Filtering() { | ||
} | ||
public static List<Violation> withAtLEastSeverity(List<Violation> unfiltered, final SEVERITY severity) { | ||
List<Violation> filtered = new ArrayList<>(); | ||
for (Violation candidate : unfiltered) { | ||
if (isSeverer(candidate.getSeverity(),severity)) { | ||
filtered.add(candidate); | ||
} | ||
} | ||
return filtered ; | ||
} | ||
|
||
private static boolean isSeverer(SEVERITY candiate,SEVERITY atLeast) { | ||
return candiate == ERROR// | ||
|| atLeast == INFO// | ||
|| candiate == WARN && atLeast == WARN; | ||
} | ||
|
||
} |
79 changes: 79 additions & 0 deletions
79
src/test/java/se/bjurr/violations/lib/util/FilteringTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package se.bjurr.violations.lib.util; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.util.Lists.newArrayList; | ||
import static se.bjurr.violations.lib.model.SEVERITY.ERROR; | ||
import static se.bjurr.violations.lib.model.SEVERITY.INFO; | ||
import static se.bjurr.violations.lib.model.SEVERITY.WARN; | ||
import static se.bjurr.violations.lib.model.Violation.violationBuilder; | ||
import static se.bjurr.violations.lib.reports.Reporter.CHECKSTYLE; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.Test; | ||
|
||
import se.bjurr.violations.lib.model.Violation; | ||
|
||
public class FilteringTest { | ||
|
||
@Test | ||
public void testFilteringINFO() { | ||
List<Violation> unfiltered = newArrayList(// | ||
violationBuilder()// | ||
.setFile("file")// | ||
.setStartLine(2)// | ||
.setMessage("message")// | ||
.setReporter(CHECKSTYLE)// | ||
.setSeverity(INFO)// | ||
.build()// | ||
); | ||
|
||
assertThat(Filtering.withAtLEastSeverity(unfiltered, ERROR))// | ||
.hasSize(0); | ||
assertThat(Filtering.withAtLEastSeverity(unfiltered, WARN))// | ||
.hasSize(0); | ||
assertThat(Filtering.withAtLEastSeverity(unfiltered, INFO))// | ||
.hasSize(1); | ||
} | ||
|
||
@Test | ||
public void testFilteringWARN() { | ||
List<Violation> unfiltered = newArrayList(// | ||
violationBuilder()// | ||
.setFile("file")// | ||
.setStartLine(2)// | ||
.setMessage("message")// | ||
.setReporter(CHECKSTYLE)// | ||
.setSeverity(WARN)// | ||
.build()// | ||
); | ||
|
||
assertThat(Filtering.withAtLEastSeverity(unfiltered, ERROR))// | ||
.hasSize(0); | ||
assertThat(Filtering.withAtLEastSeverity(unfiltered, WARN))// | ||
.hasSize(1); | ||
assertThat(Filtering.withAtLEastSeverity(unfiltered, INFO))// | ||
.hasSize(1); | ||
} | ||
|
||
@Test | ||
public void testFilteringERROR() { | ||
List<Violation> unfiltered = newArrayList(// | ||
violationBuilder()// | ||
.setFile("file")// | ||
.setStartLine(2)// | ||
.setMessage("message")// | ||
.setReporter(CHECKSTYLE)// | ||
.setSeverity(ERROR)// | ||
.build()// | ||
); | ||
|
||
assertThat(Filtering.withAtLEastSeverity(unfiltered, ERROR))// | ||
.hasSize(1); | ||
assertThat(Filtering.withAtLEastSeverity(unfiltered, WARN))// | ||
.hasSize(1); | ||
assertThat(Filtering.withAtLEastSeverity(unfiltered, INFO))// | ||
.hasSize(1); | ||
} | ||
|
||
} |