diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/common/http/HttpClientTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/common/http/HttpClientTests.java index 2e0c8d2df6e..f80a756340b 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/common/http/HttpClientTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/common/http/HttpClientTests.java @@ -76,9 +76,10 @@ import static org.mockito.Mockito.when; public class HttpClientTests extends ESTestCase { - private MockWebServer webServer = new MockWebServer(); + private final MockWebServer webServer = new MockWebServer(); + private final Environment environment = TestEnvironment.newEnvironment(Settings.builder().put("path.home", createTempDir()).build()); + private HttpClient httpClient; - private Environment environment = TestEnvironment.newEnvironment(Settings.builder().put("path.home", createTempDir()).build()); @Before public void init() throws Exception { @@ -92,7 +93,9 @@ public class HttpClientTests extends ESTestCase { @After public void shutdown() throws IOException { webServer.close(); - httpClient.close(); + if (httpClient != null) { + httpClient.close(); + } } public void testBasics() throws Exception {