Skip to content

Commit

Permalink
#1045: tests as black box
Browse files Browse the repository at this point in the history
  • Loading branch information
danhaywood committed Feb 5, 2023
1 parent 4c5f1be commit 43156af
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.tngtech.archunit.PublicAPI;
Expand Down Expand Up @@ -153,18 +152,13 @@ private String ensureRuleFileName(ArchRule rule) {
ruleFileName = storedRules.getProperty(ruleDescription);
log.debug("Rule '{}' is already stored in file {}", ruleDescription, ruleFileName);
} else {
ruleFileName = newRuleFileName(ruleDescription);
ruleFileName = this.ruleFileNameStrategy.apply(ruleDescription);
log.debug("Assigning new file {} to rule '{}'", ruleFileName, ruleDescription);
storedRules.setProperty(ruleDescription, ruleFileName);
}
return ruleFileName;
}

@VisibleForTesting()
String newRuleFileName(String description) {
return this.ruleFileNameStrategy.apply(description);
}

@Override
public List<String> getViolations(ArchRule rule) {
String ruleDetailsFileName = storedRules.getProperty(rule.getDescription());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,25 @@ public void stores_violations_with_line_breaks() {

@Test
public void class_can_be_overridden_and_rule_file_name_strategy_supplied() {

// given
class MySubclassOfTextFileBasedViolationStore extends TextFileBasedViolationStore {
public MySubclassOfTextFileBasedViolationStore() {
super(s -> s + " xxx");
}
};
TextFileBasedViolationStore store = new MySubclassOfTextFileBasedViolationStore();
store.initialize(propertiesOf(
"default.path", configuredFolder.getAbsolutePath(),
"default.allowStoreCreation", String.valueOf(true)));

// when
ArchRule firstRule = rule("first rule");
store.save(firstRule, ImmutableList.of("first violation1", "first violation2"));

assertThat(store.newRuleFileName("abc")).isEqualTo("abc xxx");
// then
String fileName = configuredFolder.listFiles()[0].getName();
assertThat(fileName).isEqualTo("first rule xxx");
}

private Properties readProperties(File file) throws IOException {
Expand Down

0 comments on commit 43156af

Please sign in to comment.