Skip to content

Commit d3abe16

Browse files
committed
Improve watcher test by preventing a npe when closing the http client.
1 parent 68371b9 commit d3abe16

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/common/http/HttpClientTests.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,10 @@
7575

7676
public class HttpClientTests extends ESTestCase {
7777

78-
private MockWebServer webServer = new MockWebServer();
78+
private final MockWebServer webServer = new MockWebServer();
79+
private final Environment environment = TestEnvironment.newEnvironment(Settings.builder().put("path.home", createTempDir()).build());
80+
7981
private HttpClient httpClient;
80-
private Environment environment = TestEnvironment.newEnvironment(Settings.builder().put("path.home", createTempDir()).build());
8182

8283
@Before
8384
public void init() throws Exception {
@@ -91,7 +92,9 @@ public void init() throws Exception {
9192
@After
9293
public void shutdown() throws IOException {
9394
webServer.close();
94-
httpClient.close();
95+
if (httpClient != null) {
96+
httpClient.close();
97+
}
9598
}
9699

97100
public void testBasics() throws Exception {

0 commit comments

Comments
 (0)