Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

Commit

Permalink
Merge pull request #351 from sbtqa/bugfix/no-field
Browse files Browse the repository at this point in the history
Fix no field exception
  • Loading branch information
clicman authored Jun 21, 2021
2 parents 268a7da + e281388 commit cbaa437
Showing 1 changed file with 8 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@ public static String replaceTemplatePlaceholders(EndpointEntry entry, String str
Object parameterValue = parameter.getValue();

if (isFieldExists(entry, parameterName)) {
try {
string = replacePlaceholder(string, entry.getClass()
.getDeclaredField(parameterName), parameterName, parameterValue);
} catch (NoSuchFieldException e) {
throw new AutotestError("This error should never appear", e);
}
Field declaredField = FieldUtils.getAllFieldsList(entry.getClass())
.stream().filter(field -> field.getName().equals(parameterName))
.findFirst().orElseThrow(() -> new AutotestError("This error should never appear"));
string = replacePlaceholder(string, declaredField, parameterName, parameterValue);
} else {
string = replacePlaceholder(string, null, parameterName, parameterValue);
}
Expand All @@ -63,12 +61,9 @@ public static String replaceJsonTemplatePlaceholders(EndpointEntry entry, String
Object parameterValue = parameter.getValue();

if (isFieldExists(entry, parameterName)) {
Field declaredField;
try {
declaredField = entry.getClass().getDeclaredField(parameterName);
} catch (NoSuchFieldException e) {
throw new AutotestError("This error should never appear", e);
}
Field declaredField = FieldUtils.getAllFieldsList(entry.getClass())
.stream().filter(field -> field.getName().equals(parameterName))
.findFirst().orElseThrow(() -> new AutotestError("This error should never appear"));
jsonString = replacePlaceholder(jsonString, declaredField, parameterName, parameterValue);
} else {
jsonString = replacePlaceholder(jsonString, null, parameterName, parameterValue);
Expand All @@ -80,7 +75,7 @@ public static String replaceJsonTemplatePlaceholders(EndpointEntry entry, String
}

private static boolean isFieldExists(EndpointEntry entry, String fieldName) {
return Arrays.stream(FieldUtils.getAllFields(entry.getClass()))
return FieldUtils.getAllFieldsList(entry.getClass()).stream()
.anyMatch(field -> field.getName().equals(fieldName));
}

Expand Down

0 comments on commit cbaa437

Please sign in to comment.