(MAINT) Added fix/test for java coerceBodyType

This commit is contained in:
Joe Pinsonault 2015-04-24 09:54:40 -07:00
parent 08ca923e69
commit c5489e0e43
2 changed files with 15 additions and 2 deletions

View file

@ -425,12 +425,19 @@ public class JavaClient {
charset = contentType.getCharset().name(); charset = contentType.getCharset().name();
} }
try { try {
response = IOUtils.toString(body, charset); if (body == null){
response = "";
}
else{
response = IOUtils.toString(body, charset);
}
} catch (IOException e) { } catch (IOException e) {
throw new HttpClientException("Unable to read body as string", e); throw new HttpClientException("Unable to read body as string", e);
} }
try { try {
body.close(); if (body != null){
body.close();
}
} catch (IOException e) { } catch (IOException e) {
throw new HttpClientException( throw new HttpClientException(
"Unable to close response stream", e); "Unable to close response stream", e);

View file

@ -52,3 +52,9 @@
(let [body "foo"] (let [body "foo"]
(is (= (compute-content-type body "text/html") (is (= (compute-content-type body "text/html")
"text/html; charset=UTF-8"))))))) "text/html; charset=UTF-8")))))))
(deftest null-response-body-coerced-as-text
(testing "a null response body is coerced into a string by JavaClient.coerceBodyType"
(let [body nil]
(is (= "" (JavaClient/coerceBodyType body ResponseBodyType/TEXT nil))))))