Skip to content

Commit

Permalink
task-3546: task-3548 error message re worded to be more understandable
Browse files Browse the repository at this point in the history
  • Loading branch information
PayalKhanna committed Oct 25, 2023
1 parent 11f3cf2 commit 30bb696
Showing 1 changed file with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,14 @@ public static <T> MapperC<T> distinct(Mapper<T> o) {

public static ComparisonResult checkCardinality(String msgPrefix, int actual, int min, int max) {
if (actual < min) {
return ComparisonResult
.failure("Minimum of " + min + " '" + msgPrefix + "' is expected but found " + actual + ".");
if(actual == 0){
return ComparisonResult
.failure("'" + msgPrefix + "' is a required field but does not exist.");
}
else {
return ComparisonResult
.failure("Minimum of " + min + " '" + msgPrefix + "' is expected but found " + actual + ".");
}
} else if (max > 0 && actual > max) {
return ComparisonResult
.failure("Maximum of " + max + " '" + msgPrefix + "' are expected but found " + actual + ".");
Expand All @@ -274,19 +280,25 @@ public static ComparisonResult checkString(String msgPrefix, String value, int m
}
List<String> failures = new ArrayList<>();
if (value.length() < minLength) {
failures.add("Expected a minimum of " + minLength + " characters for '" + msgPrefix + "', but found '" + value + "' (" + value.length() + " characters).");
// failures.add("Expected a minimum of " + minLength + " characters for '" + msgPrefix + "', but found '" + value + "' (" + value.length() + " characters).");
failures.add("Field '" + msgPrefix + " must have a value with minimum length of '" + minLength + " characters but value '" + value + "' is length of " + value.length() + " characters.");

}
if (maxLength.isPresent()) {
int m = maxLength.get();
if (value.length() > m) {
failures.add("Expected a maximum of " + m + " characters for '" + msgPrefix + "', but found '" + value + "' (" + value.length() + " characters).");
failures.add("Field '" + msgPrefix + " must have a value with maximum length of '" + m + " characters but value '" + value + "' is length of " + value.length() + " characters.");

//failures.add("Expected a maximum of " + m + " characters for '" + msgPrefix + "', but found '" + value + "' (" + value.length() + " characters).");
}
}
if (pattern.isPresent()) {
Pattern p = pattern.get();
Matcher match = p.matcher(value);
if (!match.matches()) {
failures.add("'" + value + "' does not match the pattern /" + p.toString() + "/ of '" + msgPrefix + "'.");
//failures.add("'" + value + "' does not match the pattern /" + p.toString() + "/ of '" + msgPrefix + "'.");
failures.add("Field '" + msgPrefix + "' with value "+ value + "' does not match the pattern / " + p.toString() + " /.");

}
}
if (failures.isEmpty()) {
Expand Down

0 comments on commit 30bb696

Please sign in to comment.