Skip to content

Commit ddbb2a1

Browse files
author
Pascal Romanens
committed
#1298 updated tests in pt-examples-validation + sonar qaulity fixes
1 parent f311722 commit ddbb2a1

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

examples/powertools-examples-validation/src/test/java/org/demo/validation/InboundValidationTest.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,15 @@ public void shouldReturnOkStatusWhenInputIsValid() {
5353
}
5454

5555
@Test
56-
public void shouldThrowExceptionWhenRequestInInvalid() {
56+
public void shouldReturnBadRequestWhenRequestInInvalid() {
5757
String bodyWithMissedId = "{\n" +
5858
" \"name\": \"FooBar XY\",\n" +
5959
" \"price\": 258\n" +
6060
" }";
6161
APIGatewayProxyRequestEvent request = new APIGatewayProxyRequestEvent().withBody(bodyWithMissedId);
6262

63-
assertThrows(ValidationException.class, () -> inboundValidation.handleRequest(request, context));
63+
APIGatewayProxyResponseEvent response = inboundValidation.handleRequest(request, context);
64+
65+
assertEquals(400, response.getStatusCode());
6466
}
6567
}

powertools-validation/src/test/java/software/amazon/lambda/powertools/validation/internal/ValidationAspectTest.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ void setUp() {
106106

107107
@ParameterizedTest
108108
@ArgumentsSource(ResponseEventsArgumentsProvider.class)
109-
public void testValidateOutboundJsonSchemaWithExceptions(Object object) throws Throwable {
109+
void testValidateOutboundJsonSchemaWithExceptions(Object object) throws Throwable {
110110
when(validation.schemaVersion()).thenReturn(SpecVersion.VersionFlag.V7);
111111
when(pjp.getSignature()).thenReturn(signature);
112112
when(pjp.getSignature().getDeclaringType()).thenReturn(RequestHandler.class);
@@ -124,7 +124,7 @@ public void testValidateOutboundJsonSchemaWithExceptions(Object object) throws T
124124

125125
@ParameterizedTest
126126
@ArgumentsSource(HandledResponseEventsArgumentsProvider.class)
127-
public void testValidateOutboundJsonSchemaWithHandledExceptions(Object object) throws Throwable {
127+
void testValidateOutboundJsonSchemaWithHandledExceptions(Object object) throws Throwable {
128128
when(validation.schemaVersion()).thenReturn(SpecVersion.VersionFlag.V7);
129129
when(pjp.getSignature()).thenReturn(signature);
130130
when(pjp.getSignature().getDeclaringType()).thenReturn(RequestHandler.class);
@@ -139,13 +139,13 @@ public void testValidateOutboundJsonSchemaWithHandledExceptions(Object object) t
139139
if (response instanceof APIGatewayProxyResponseEvent) {
140140
assertThat(response).isInstanceOfSatisfying(APIGatewayProxyResponseEvent.class, t -> {
141141
assertThat(t.getStatusCode()).isEqualTo(400);
142-
assertThat(t.getBody()).satisfies(x -> StringUtils.isNotBlank(x));
142+
assertThat(t.getBody()).isNotBlank();
143143
assertThat(t.getIsBase64Encoded()).isFalse();
144144
});
145145
} else if (response instanceof APIGatewayV2HTTPResponse) {
146146
assertThat(response).isInstanceOfSatisfying(APIGatewayV2HTTPResponse.class, t -> {
147147
assertThat(t.getStatusCode()).isEqualTo(400);
148-
assertThat(t.getBody()).satisfies(x -> StringUtils.isNotBlank(x));
148+
assertThat(t.getBody()).isNotBlank();
149149
assertThat(t.getIsBase64Encoded()).isFalse();
150150
});
151151
} else {
@@ -199,7 +199,7 @@ public void validate_inputKO_schemaInClasspath_shouldThrowValidationException()
199199
"}");
200200
// price is negative
201201
APIGatewayProxyResponseEvent response = handler.handleRequest(event, context);
202-
assertThat(response.getBody()).satisfies(x -> StringUtils.isNotBlank(x));
202+
assertThat(response.getBody()).isNotBlank();
203203
assertThat(response.getStatusCode()).isEqualTo(400);
204204
}
205205

@@ -229,7 +229,7 @@ public void validate_inputKO_schemaInString_shouldThrowValidationException() {
229229
"}");
230230

231231
APIGatewayV2HTTPResponse response = handler.handleRequest(event, context);
232-
assertThat(response.getBody()).satisfies(x -> StringUtils.isNotBlank(x));
232+
assertThat(response.getBody()).isNotBlank();
233233
assertThat(response.getStatusCode()).isEqualTo(400);
234234
}
235235

0 commit comments

Comments
 (0)