|
22 | 22 | import com.github.javaparser.ast.body.MethodDeclaration;
|
23 | 23 | import com.github.javaparser.ast.body.Parameter;
|
24 | 24 | import com.github.javaparser.ast.body.VariableDeclarator;
|
| 25 | +import com.github.javaparser.ast.expr.AnnotationExpr; |
25 | 26 | import com.github.javaparser.ast.expr.Expression;
|
26 | 27 | import com.github.javaparser.ast.type.ClassOrInterfaceType;
|
27 | 28 | import com.github.javaparser.ast.type.Type;
|
@@ -216,6 +217,15 @@ void shouldGenerateValidations(boolean useLombok, boolean bigDecimalsAsStrings)
|
216 | 217 | assertHasCollectionParamWithType(getPaymentsMethod, "status", "List", "String");
|
217 | 218 | assertHasCollectionParamWithType(getPaymentsMethod, "headerParams", "List", "String");
|
218 | 219 |
|
| 220 | + MethodDeclaration createPaymentsMethod = StaticJavaParser.parse(paymentsApiFile) |
| 221 | + .findAll(MethodDeclaration.class) |
| 222 | + .stream() |
| 223 | + .filter(it -> "createPayments".equals(it.getName().toString())) |
| 224 | + .findFirst().orElseThrow(); |
| 225 | + AnnotationExpr sizeAnnotation = createPaymentsMethod.getParameterByName("multiLinePaymentRequest").orElseThrow() |
| 226 | + .getAnnotationByName("Size").orElseThrow(); |
| 227 | + assertEquals("@Size(min = 1, max = 55)", sizeAnnotation.toString()); |
| 228 | + |
219 | 229 | File paymentRequestLine = files.stream().filter(file -> file.getName().equals("PaymentRequestLine.java"))
|
220 | 230 | .findFirst()
|
221 | 231 | .get();
|
@@ -249,6 +259,7 @@ void shouldGenerateValidations(boolean useLombok, boolean bigDecimalsAsStrings)
|
249 | 259 | assertFieldValueAssignment(
|
250 | 260 | multiLinePaymentRequestUnit, "arrangementIds", "new ArrayList<>()");
|
251 | 261 | assertFieldAnnotation(multiLinePaymentRequestUnit, "uniqueLines", "NotNull");
|
| 262 | + assertFieldAnnotation(multiLinePaymentRequestUnit, "name", "Pattern", "@Pattern(regexp = \"^[^\\\\r\\\\n]{1,64}$\")"); |
252 | 263 | assertFieldValueAssignment(
|
253 | 264 | multiLinePaymentRequestUnit, "uniqueArrangementIds", null);
|
254 | 265 |
|
@@ -440,6 +451,15 @@ private static void assertFieldAnnotation(
|
440 | 451 | fieldDeclaration.getAnnotationByName(annotationName).isPresent(), is(true));
|
441 | 452 | }
|
442 | 453 |
|
| 454 | + private static void assertFieldAnnotation( |
| 455 | + CompilationUnit unit, String fieldName, String annotationName, String value) throws FileNotFoundException { |
| 456 | + FieldDeclaration fieldDeclaration = findFieldDeclaration(unit, fieldName); |
| 457 | + AnnotationExpr annotation = fieldDeclaration.getAnnotationByName(annotationName) |
| 458 | + .orElseThrow(() -> new AssertionError( |
| 459 | + "Expect annotation to be present on field: " + annotationName + " " + fieldName)); |
| 460 | + assertThat(annotation.toString(), equalTo(value)); |
| 461 | + } |
| 462 | + |
443 | 463 | private static void assertFieldValueAssignment(
|
444 | 464 | CompilationUnit unit, String fieldName, String valueAssignment) throws FileNotFoundException {
|
445 | 465 | FieldDeclaration fieldDeclaration = findFieldDeclaration(unit, fieldName);
|
|
0 commit comments