From 225d841212f727f52566ca060bed77690e01a03c Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Mon, 24 Feb 2020 10:22:48 +0100 Subject: [PATCH] Improve watcher test by preventing a npe when closing the http client. --- .../xpack/watcher/common/http/HttpClientTests.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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 {