pjfanning commented on code in PR #6557:
URL: https://github.com/apache/hadoop/pull/6557#discussion_r1543349031
##########
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestHttpExceptionUtils.java:
##########
@@ -87,35 +89,31 @@ public void testValidateResponseOK() throws IOException {
HttpExceptionUtils.validateResponse(conn, HttpURLConnection.HTTP_CREATED);
}
- @Test(expected = IOException.class)
- public void testValidateResponseFailNoErrorMessage() throws IOException {
+ @Test
+ public void testValidateResponseFailNoErrorMessage() throws Exception {
HttpURLConnection conn = Mockito.mock(HttpURLConnection.class);
Mockito.when(conn.getResponseCode()).thenReturn(
HttpURLConnection.HTTP_BAD_REQUEST);
- HttpExceptionUtils.validateResponse(conn, HttpURLConnection.HTTP_CREATED);
+ LambdaTestUtils.intercept(IOException.class,
+ () -> HttpExceptionUtils.validateResponse(conn,
HttpURLConnection.HTTP_CREATED));
}
@Test
- public void testValidateResponseNonJsonErrorMessage() throws IOException {
+ public void testValidateResponseNonJsonErrorMessage() throws Exception {
String msg = "stream";
- InputStream is = new ByteArrayInputStream(msg.getBytes());
+ InputStream is = new
ByteArrayInputStream(msg.getBytes(StandardCharsets.UTF_8));
HttpURLConnection conn = Mockito.mock(HttpURLConnection.class);
Mockito.when(conn.getErrorStream()).thenReturn(is);
Mockito.when(conn.getResponseMessage()).thenReturn("msg");
Mockito.when(conn.getResponseCode()).thenReturn(
HttpURLConnection.HTTP_BAD_REQUEST);
- try {
- HttpExceptionUtils.validateResponse(conn,
HttpURLConnection.HTTP_CREATED);
- Assert.fail();
- } catch (IOException ex) {
- Assert.assertTrue(ex.getMessage().contains("msg"));
- Assert.assertTrue(ex.getMessage().contains("" +
- HttpURLConnection.HTTP_BAD_REQUEST));
- }
+ LambdaTestUtils.intercept(IOException.class,
Review Comment:
the test is not brittle - if someone changes the format of the exception
message, it could break but that would be sort of expected if you go changing
the format of exception messages
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]