diff --git a/jest-common/src/main/java/io/searchbox/client/JestResult.java b/jest-common/src/main/java/io/searchbox/client/JestResult.java index 1061ef56c..0f7307f68 100644 --- a/jest-common/src/main/java/io/searchbox/client/JestResult.java +++ b/jest-common/src/main/java/io/searchbox/client/JestResult.java @@ -367,4 +367,11 @@ protected String[] getKeys() { return pathToResult == null ? null : pathToResult.split("/"); } + @Override + public String toString() { + return "Result: " + getJsonString() + + ", isSucceeded: " + isSucceeded() + + ", response code: " + getResponseCode() + + ", error message: " + getErrorMessage(); + } } diff --git a/jest-common/src/test/java/io/searchbox/indices/script/CreateIndexedScriptTest.java b/jest-common/src/test/java/io/searchbox/indices/script/CreateIndexedScriptTest.java index 38b5c4be1..75bba13a8 100644 --- a/jest-common/src/test/java/io/searchbox/indices/script/CreateIndexedScriptTest.java +++ b/jest-common/src/test/java/io/searchbox/indices/script/CreateIndexedScriptTest.java @@ -78,10 +78,10 @@ public void fileSourceIsValidJsonString() throws Exception { private File createTempGroovySnippetFile() throws IOException { File file = File.createTempFile("test", ".groovy"); file.deleteOnExit(); - FileWriter writer = new FileWriter(file); - writer.write(groovysnippet); - writer.close(); - return file; + try (FileWriter writer = new FileWriter(file)) { + writer.write(groovysnippet); + return file; + } } private JsonObject parseAsGson(String data) { diff --git a/jest/src/test/java/io/searchbox/client/http/FailingProxy.java b/jest/src/test/java/io/searchbox/client/http/FailingProxy.java index a45808674..025f7ca5b 100644 --- a/jest/src/test/java/io/searchbox/client/http/FailingProxy.java +++ b/jest/src/test/java/io/searchbox/client/http/FailingProxy.java @@ -68,11 +68,11 @@ public void stop() { } private static int getUnusedPort() throws IOException { - final Socket deadSocket = new Socket(); - deadSocket.bind(null); - final int port = deadSocket.getLocalPort(); - deadSocket.close(); - return port; + try (Socket deadSocket = new Socket()) { + deadSocket.bind(null); + final int port = deadSocket.getLocalPort(); + return port; + } } private class FailingSourceAdapter extends HttpFiltersSourceAdapter {