Skip to content

Commit

Permalink
Merge gbranchaud pull request #29
Browse files Browse the repository at this point in the history
  • Loading branch information
testinfected committed Mar 4, 2015
2 parents 5fba70a + e9c4953 commit e3d7f60
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.GeneralSecurityException;
Expand Down Expand Up @@ -177,7 +178,8 @@ private HttpURLConnection openSecureConnection() throws IOException {
}

private byte[] readResponseBody(HttpURLConnection connection) throws IOException {
return Streams.toBytes(successful(connection) ? connection.getInputStream() : connection.getErrorStream());
InputStream bodyStream = successful(connection) ? connection.getInputStream() : connection.getErrorStream();
return bodyStream != null ? Streams.toBytes(bodyStream) : new byte[0];
}

private boolean successful(HttpURLConnection connection) throws IOException {
Expand Down Expand Up @@ -205,7 +207,6 @@ private void writeContent(HttpURLConnection connection) throws IOException {
if (content.contentLength() > 0) {
connection.setDoOutput(true);
content.writeTo(connection.getOutputStream());
// connection.getOutputStream().write(body);
}
}
}
3 changes: 0 additions & 3 deletions src/test/java/examples/rest/RESTExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public void handle(Request request, Response response) throws Exception {
response.body(album.info());
} else {
response.statusCode(404);
response.body("No such album");
}
}
});
Expand All @@ -72,7 +71,6 @@ public void handle(Request request, Response response) throws Exception {
response.body(album.info());
} else {
response.statusCode(404);
response.body("No such album");
}
}
});
Expand All @@ -86,7 +84,6 @@ public void handle(Request request, Response response) throws Exception {
response.body(album.info());
} else {
response.statusCode(404);
response.body("No such album");
}
}
});
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/examples/rest/RESTTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,10 @@ public void makingAPostActLikeAnUpdateOrDelete() throws IOException {
assertThat(response).isOK()
.hasBodyText("Your music library is empty");
}

@Test
public void askingForAMissingAlbum() throws IOException {
response = request.get("/albums/9999");
assertThat(response).hasStatusCode(404);
}
}

0 comments on commit e3d7f60

Please sign in to comment.