Skip to content

Commit

Permalink
Merge pull request searchbox-io#559 from btrajkovski/code-polish
Browse files Browse the repository at this point in the history
Add toString in JestResult and use auto-closable
  • Loading branch information
ferhatsb authored Nov 28, 2017
2 parents 88848d7 + 8ae435f commit 96335b3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
7 changes: 7 additions & 0 deletions jest-common/src/main/java/io/searchbox/client/JestResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions jest/src/test/java/io/searchbox/client/http/FailingProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 96335b3

Please sign in to comment.