Skip to content

Commit d026ca2

Browse files
committed
Cleaned up exception dumps in unit tests
1 parent 0ddf275 commit d026ca2

File tree

14 files changed

+26
-30
lines changed

14 files changed

+26
-30
lines changed

aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/servlet/AwsAsyncContext.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ public void complete() {
8484
notifyListeners(NotificationType.COMPLETE, null);
8585
res.flushBuffer();
8686
} catch (IOException e) {
87-
e.printStackTrace();
87+
log.error("Could not flush response buffer", e);
88+
throw new RuntimeException(e);
8889
}
8990
}
9091

aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/testutils/AwsProxyRequestBuilder.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ public AwsProxyRequestBuilder queryString(String key, String value) {
209209
);
210210
//}
211211
} catch (UnsupportedEncodingException e) {
212-
e.printStackTrace();
213212
throw new RuntimeException(e);
214213
}
215214

aws-serverless-java-container-core/src/test/java/com/amazonaws/serverless/proxy/internal/servlet/AwsAsyncContextTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ protected void doFilter(HttpServletRequest request, HttpServletResponse response
110110
this.response.setStatus(desiredStatus);
111111
this.response.flushBuffer();
112112
} catch (Exception e) {
113-
e.printStackTrace();
114113
throw new ServletException(e);
115114
}
116115
}

aws-serverless-java-container-core/src/test/java/com/amazonaws/serverless/proxy/internal/servlet/AwsFilterChainManagerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,11 @@ public void filerChain_executeMultipleFilters_expectRunEachTime() {
193193
try {
194194
fcHolder2.doFilter(req2, resp2);
195195
} catch (IOException e) {
196-
fail("IO Exception while executing filters");
197196
e.printStackTrace();
197+
fail("IO Exception while executing filters");
198198
} catch (ServletException e) {
199-
fail("Servlet exception while executing filters");
200199
e.printStackTrace();
200+
fail("Servlet exception while executing filters");
201201
}
202202

203203
assertTrue(req2.getAttribute(REQUEST_CUSTOM_ATTRIBUTE_NAME) != null);

aws-serverless-java-container-core/src/test/java/com/amazonaws/serverless/proxy/internal/servlet/AwsProxyHttpServletRequestReaderTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ public void readRequest_validEventEmptyPath_expectException() {
117117
AwsProxyHttpServletRequest servletReq = reader.readRequest(req, null, null, ContainerConfig.defaultConfig());
118118
assertNotNull(servletReq);
119119
} catch (InvalidRequestEventException e) {
120-
fail("Could not read a request with a null path");
121120
e.printStackTrace();
121+
fail("Could not read a request with a null path");
122122
}
123123
}
124124

@@ -130,7 +130,6 @@ public void readRequest_invalidEventEmptyMethod_expectException() {
130130
fail("Expected InvalidRequestEventException");
131131
} catch (InvalidRequestEventException e) {
132132
assertEquals(AwsProxyHttpServletRequestReader.INVALID_REQUEST_ERROR, e.getMessage());
133-
e.printStackTrace();
134133
}
135134
}
136135

@@ -143,7 +142,6 @@ public void readRequest_invalidEventEmptyContext_expectException() {
143142
fail("Expected InvalidRequestEventException");
144143
} catch (InvalidRequestEventException e) {
145144
assertEquals(AwsProxyHttpServletRequestReader.INVALID_REQUEST_ERROR, e.getMessage());
146-
e.printStackTrace();
147145
}
148146
}
149147

aws-serverless-java-container-core/src/test/java/com/amazonaws/serverless/proxy/internal/servlet/AwsProxyHttpServletRequestTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -274,19 +274,20 @@ public void charEncoding_getEncoding_expectNoEncodingWithoutContentType() {
274274
try {
275275
request.setCharacterEncoding(StandardCharsets.UTF_8.name());
276276
// we have not specified a content type so the encoding will not be set
277-
assertEquals(null, request.getCharacterEncoding());
278-
assertEquals(null, request.getContentType());
277+
assertNull(request.getCharacterEncoding());
278+
assertNull(request.getContentType());
279279
} catch (UnsupportedEncodingException e) {
280-
fail("Unsupported encoding");
281280
e.printStackTrace();
281+
fail("Unsupported encoding");
282+
282283
}
283284
}
284285

285286
@Test
286287
public void charEncoding_getEncoding_expectContentTypeOnly() {
287288
HttpServletRequest request = getRequest(getRequestWithHeaders(), null, null);
288289
// we have not specified a content type so the encoding will not be set
289-
assertEquals(null, request.getCharacterEncoding());
290+
assertNull(request.getCharacterEncoding());
290291
assertEquals(MediaType.APPLICATION_JSON, request.getContentType());
291292
try {
292293
request.setCharacterEncoding(StandardCharsets.UTF_8.name());
@@ -295,8 +296,8 @@ public void charEncoding_getEncoding_expectContentTypeOnly() {
295296
assertEquals(newHeaderValue, request.getContentType());
296297
assertEquals(StandardCharsets.UTF_8.name(), request.getCharacterEncoding());
297298
} catch (UnsupportedEncodingException e) {
298-
fail("Unsupported encoding");
299299
e.printStackTrace();
300+
fail("Unsupported encoding");
300301
}
301302
}
302303

@@ -321,8 +322,8 @@ public void charEncoding_addCharEncodingTwice_expectSingleMediaTypeAndEncoding()
321322
assertEquals(newHeaderValue, request.getContentType());
322323
assertEquals(StandardCharsets.ISO_8859_1.name(), request.getCharacterEncoding());
323324
} catch (UnsupportedEncodingException e) {
324-
fail("Unsupported encoding");
325325
e.printStackTrace();
326+
fail("Unsupported encoding");
326327
}
327328
}
328329

@@ -335,10 +336,9 @@ public void contentType_lowerCaseHeaderKey_expectUpdatedMediaType() {
335336
assertEquals(newHeaderValue, request.getHeader(HttpHeaders.CONTENT_TYPE));
336337
assertEquals(newHeaderValue, request.getContentType());
337338
assertEquals(StandardCharsets.UTF_8.name(), request.getCharacterEncoding());
338-
339339
} catch (UnsupportedEncodingException e) {
340-
fail("Unsupported encoding");
341340
e.printStackTrace();
341+
fail("Unsupported encoding");
342342
}
343343
}
344344

@@ -352,8 +352,8 @@ public void contentType_duplicateCase_expectSingleContentTypeHeader() {
352352
assertNotNull(request.getHeader(HttpHeaders.CONTENT_TYPE));
353353
assertNotNull(request.getHeader(HttpHeaders.CONTENT_TYPE.toLowerCase(Locale.getDefault())));
354354
} catch (UnsupportedEncodingException e) {
355-
fail("Unsupported encoding");
356355
e.printStackTrace();
356+
fail("Unsupported encoding");
357357
}
358358
}
359359

aws-serverless-java-container-core/src/test/java/com/amazonaws/serverless/proxy/internal/servlet/AwsServletContextTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public static void setUp() {
3434
try {
3535
LambdaContainerHandler.getContainerConfig().addValidFilePath(tmpFile.getCanonicalPath());
3636
} catch (IOException e) {
37-
fail("Could not add tmp dir to valid paths");
3837
e.printStackTrace();
38+
fail("Could not add tmp dir to valid paths");
3939
}
4040
LambdaContainerHandler.getContainerConfig().addValidFilePath("C:\\MyTestFolder");
4141
}
@@ -48,8 +48,8 @@ public void getMimeType_disabledPath_expectException() {
4848
} catch (IllegalArgumentException e) {
4949
assertTrue(e.getMessage().startsWith("File path not allowed"));
5050
} catch (Exception e) {
51-
fail("Unrecognized exception");
5251
e.printStackTrace();
52+
fail("Unrecognized exception");
5353
}
5454
}
5555

aws-serverless-java-container-core/src/test/java/com/amazonaws/serverless/proxy/model/CognitoAuthorizerClaimsTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ public void claims_serialize_validJsonString() {
8585
assertEquals(EMAIL, req.getRequestContext().getAuthorizer().getClaims().getEmail());
8686
assertTrue(req.getRequestContext().getAuthorizer().getClaims().isEmailVerified());
8787
} catch (IOException e) {
88-
e.printStackTrace();
8988
fail();
9089
}
9190
}

aws-serverless-java-container-jersey/src/test/java/com/amazonaws/serverless/proxy/jersey/JerseyAwsProxyTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,8 @@ private void validateMapResponseModel(AwsProxyResponse output, String key, Strin
408408
assertNotNull(response.getValues().get(key));
409409
assertEquals(value, response.getValues().get(key));
410410
} catch (IOException e) {
411-
fail("Exception while parsing response body: " + e.getMessage());
412411
e.printStackTrace();
412+
fail("Exception while parsing response body: " + e.getMessage());
413413
}
414414
}
415415

@@ -419,8 +419,8 @@ private void validateSingleValueModel(AwsProxyResponse output, String value) {
419419
assertNotNull(response.getValue());
420420
assertEquals(value, response.getValue());
421421
} catch (IOException e) {
422-
fail("Exception while parsing response body: " + e.getMessage());
423422
e.printStackTrace();
423+
fail("Exception while parsing response body: " + e.getMessage());
424424
}
425425
}
426426
}

aws-serverless-java-container-jersey/src/test/java/com/amazonaws/serverless/proxy/jersey/JerseyParamEncodingTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ private void validateSingleValueModel(AwsProxyResponse output, String value) {
239239
assertNotNull(response.getValue());
240240
assertEquals(value, response.getValue());
241241
} catch (IOException e) {
242-
fail("Exception while parsing response body: " + e.getMessage());
243242
e.printStackTrace();
243+
fail("Exception while parsing response body: " + e.getMessage());
244244
}
245245
}
246246

@@ -250,8 +250,8 @@ private void validateMapResponseModel(AwsProxyResponse output, String key, Strin
250250
assertNotNull(response.getValues().get(key));
251251
assertEquals(value, response.getValues().get(key));
252252
} catch (IOException e) {
253-
fail("Exception while parsing response body: " + e.getMessage());
254253
e.printStackTrace();
254+
fail("Exception while parsing response body: " + e.getMessage());
255255
}
256256
}
257257
}

0 commit comments

Comments
 (0)