@@ -107,6 +107,22 @@ public class ResponseTest {
107107 assertNull (response .getData ());
108108 }
109109
110+ @ Test public void testNoContent () throws IOException {
111+ when (connection .getResponseCode ()).thenReturn (204 );
112+ when (connection .getHeaderField ("Content-Type" )).thenReturn (
113+ "application/json" );
114+ when (connection .getInputStream ()).thenReturn (
115+ new ByteArrayInputStream ("" .getBytes ()));
116+
117+ response .parse (client );
118+
119+ assertEquals (response .getStatusCode (), 204 );
120+ assertEquals (response .getBody (), null );
121+ assertFalse (response .isParsed ());
122+ assertNull (response .getResult ());
123+ assertNull (response .getData ());
124+ }
125+
110126 @ Test public void testEmptyConnection () throws IOException {
111127 InputStream stream = mock (ByteArrayInputStream .class );
112128 when (connection .getResponseCode ()).thenThrow (new IOException ());
@@ -212,6 +228,16 @@ public void detectParserException() throws ResponseException, IOException {
212228 response .detectError (client );
213229 }
214230
231+ @ Test public void detectNoExceptionNoContent () throws ResponseException , IOException {
232+ when (connection .getResponseCode ()).thenReturn (204 );
233+ when (connection .getHeaderField ("Content-Type" )).thenReturn (
234+ "application/json" );
235+ when (connection .getInputStream ()).thenReturn (
236+ new ByteArrayInputStream ("{}" .getBytes ()));
237+ response .parse (client );
238+ response .detectError (client );
239+ }
240+
215241 @ Test public void testToString () {
216242 assertTrue (response .toString ().startsWith ("Response(" ));
217243 }
0 commit comments