diff --git a/infer/tests/utils/matchers/ResultContainsLineNumbers.java b/infer/tests/utils/matchers/ResultContainsLineNumbers.java index 0090cbabb..7b68fcefe 100644 --- a/infer/tests/utils/matchers/ResultContainsLineNumbers.java +++ b/infer/tests/utils/matchers/ResultContainsLineNumbers.java @@ -14,6 +14,7 @@ import org.hamcrest.Description; import org.hamcrest.Matcher; import java.util.Arrays; +import java.util.Optional; import java.util.Vector; import utils.InferError; @@ -23,12 +24,15 @@ public class ResultContainsLineNumbers extends BaseMatcher { private int[] lines; private boolean strict; + private Optional bugType; public ResultContainsLineNumbers( int[] lines, - boolean strict) { + boolean strict, + String bugType) { this.lines = lines; this.strict = strict; + this.bugType = Optional.ofNullable(bugType); } @Override @@ -41,7 +45,9 @@ public class ResultContainsLineNumbers extends BaseMatcher { for (int line : lines) { boolean isContained = false; for (InferError error : errors) { - isContained = isContained || line == error.getErrorLine(); + String bugType = this.bugType.orElse(error.getErrorType()); + boolean isSameErrType = bugType.equals(error.getErrorType()); + isContained = isContained || (line == error.getErrorLine() && isSameErrType); } allContained = allContained && isContained; } @@ -65,11 +71,19 @@ public class ResultContainsLineNumbers extends BaseMatcher { } public static Matcher containsLines(int[] lines) { - return new ResultContainsLineNumbers(lines, false); + return new ResultContainsLineNumbers(lines, false, null); } public static Matcher containsOnlyLines(int[] lines) { - return new ResultContainsLineNumbers(lines, true); + return new ResultContainsLineNumbers(lines, true, null); + } + + public static Matcher containsLinesOfError(int[] lines, String bugType) { + return new ResultContainsLineNumbers(lines, false, bugType); + } + + public static Matcher containsOnlyLinesOfError(int[] lines, String bugType) { + return new ResultContainsLineNumbers(lines, true, bugType); } private int[] findLineNumbersInReport(InferResults results) {