Skip to content

Commit

Permalink
Fix sonar indicated smells
Browse files Browse the repository at this point in the history
  • Loading branch information
stijn-dejongh committed Nov 22, 2024
1 parent 63a282e commit 329db50
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public record CsvRuleSpec(
Function<String, RuleSpecificationAppender<CsvFile>> ruleBuilder
) {

public static final String DEFAULT_PARAMETER_SEPARATOR = ",";

public Optional<RuleSpecificationAppender<CsvFile>> toRule(String line) {
return accepts(line) ? ofNullable(ruleBuilder().apply(line)) : empty();
}
Expand All @@ -27,7 +29,7 @@ static List<String> parametersFrom(String line) {
String[] rawParameters = line.substring(line.indexOf('(') + 1, line.indexOf(')'))
.trim()
.replace("'", "")
.split(CsvValidationRules.DEFAULT_PARAMETER_SEPARATOR);
.split(DEFAULT_PARAMETER_SEPARATOR);
return Stream.of(rawParameters).map(String::trim).toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

public final class CsvValidationRules {

public static final String DEFAULT_PARAMETER_SEPARATOR = ",";
private static final List<CsvRuleSpec> BASE_RULE_SPECIFICATIONS = List.of(
new CsvRuleSpec("Field", CsvValidationRules::createFieldExistsRule),
new CsvRuleSpec("Distinct", CsvValidationRules::createFieldDistinctnessRule),
Expand Down Expand Up @@ -113,7 +112,7 @@ public static CsvValidationRules defaultRules() {
}

public void addRuleSpecification(CsvRuleSpec csvRuleSpec) {
if(isKnownSpecification(csvRuleSpec.ruleName())) {
if (isKnownSpecification(csvRuleSpec.ruleName())) {
throw new IllegalStateException("Rule specification '%s' is already registered".formatted(csvRuleSpec.ruleName()));
}
this.knownRuleSpecifications.add(csvRuleSpec);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void containsFileNameAfterParsing() throws Exception {

var result = CsvFile.fromFile(dataFile);

assertThat(result).satisfies(CsvFile::isNotEmpty);
assertThat(result).matches(CsvFile::isNotEmpty);
assertThat(result.fileIdentifier()).contains("STARWARS_INPUT_DATA.csv");
}

Expand Down Expand Up @@ -169,7 +169,7 @@ void passesWhenExpectedRecordsArePresent() throws Exception {
assertThat(dataFile).exists().isRegularFile().hasExtension("csv");

var fileToValidate = CsvFile.fromFile(dataFile);
assertThat(fileToValidate).isNotNull().satisfies(CsvFile::isNotEmpty);
assertThat(fileToValidate).isNotNull().matches(CsvFile::isNotEmpty);

var result = THE_DROIDS_WE_ARE_LOOKING_FOR.constrain(fileToValidate);

Expand All @@ -194,7 +194,7 @@ void failsWhenExpectedRecordsAreNotPresent() throws Exception {
Han Solo,180,80,brown,fair,brown,29BBY,male,Corellia,Human
""".lines().toList()
);
assertThat(fileToValidate).isNotNull().satisfies(CsvFile::isNotEmpty);
assertThat(fileToValidate).isNotNull().matches(CsvFile::isNotEmpty);

var result = THE_DROIDS_WE_ARE_LOOKING_FOR.constrain(fileToValidate);
assertThatExceptionOfType(InvalidObjectException.class)
Expand Down

0 comments on commit 329db50

Please sign in to comment.