Skip to content

Commit

Permalink
Combine prefix and regex for constraint error
Browse files Browse the repository at this point in the history
  • Loading branch information
domi-b committed Dec 18, 2023
1 parent 293c673 commit c8a1da7
Showing 1 changed file with 2 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

public final class InterlisValidator implements Validator {
private static final Logger LOGGER = LogManager.getLogger();
private static final String CONSTRAINT_ERROR_PREFIX = "Error: ";

private final TestOptions options;

Expand Down Expand Up @@ -51,11 +50,11 @@ public boolean validate(Path filePath, Path logFile) throws ValidatorException {

@Override
public boolean containsConstraintError(Path logFile, String constraintName) throws ValidatorException {
var constraintNameWithWordBoundaries = Pattern.compile("\\b" + Pattern.quote(constraintName) + "\\b");
var constraintPattern = Pattern.compile("^Error: .*\\b" + Pattern.quote(constraintName) + "\\b");

try (var lines = Files.lines(logFile)) {
return lines.anyMatch(line -> {
if (line.startsWith(CONSTRAINT_ERROR_PREFIX) && constraintNameWithWordBoundaries.matcher(line).find()) {
if (constraintPattern.matcher(line).find()) {
LOGGER.info("Found expected error for constraint " + constraintName + " in log file: " + line);
return true;
}
Expand Down

0 comments on commit c8a1da7

Please sign in to comment.