Skip to content

Commit

Permalink
read empty list of frozen violations correctly #457
Browse files Browse the repository at this point in the history
By default `Splitter.on(..).splitToList("")` returns a list containing one element (the empty string). This leads to an inconsistent behavior, because saving no lines will in turn return one line on read. Configuring `Splitter` via `omitEmptyStrings()` we can fix this behavior by skipping all empty lines, which makes sense in general.

Resolves: #456

Signed-off-by: Manfred Hanke <Manfred.Hanke@tngtech.com>
  • Loading branch information
codecholeric authored Dec 14, 2020
2 parents 94080bc + e545bfe commit e5c6b75
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public List<String> getViolations(ArchRule rule) {

private List<String> readLines(String ruleDetailsFileName) {
String violationsText = readStoreFile(ruleDetailsFileName);
List<String> lines = Splitter.on(UNESCAPED_LINE_BREAK_PATTERN).splitToList(violationsText);
List<String> lines = Splitter.on(UNESCAPED_LINE_BREAK_PATTERN).omitEmptyStrings().splitToList(violationsText);
return unescape(lines);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ public void reads_violations_of_single_rule_from_configured_folder() {
assertThat(storedViolations).containsOnly("first violation", "second violation");
}

@Test
public void reads_empty_list_of_violations() {
store.save(defaultRule(), ImmutableList.<String>of());

List<String> storedViolations = store.getViolations(defaultRule());

assertThat(storedViolations).isEmpty();
}

@Test
public void stores_violations_of_multiple_rules() {
ArchRule firstRule = rule("first rule");
Expand Down

0 comments on commit e5c6b75

Please sign in to comment.