Browse Source

Improve watcher test by preventing a npe when closing the http client.

Martijn van Groningen 5 years ago
parent
commit
d3abe16a1c

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

@@ -75,9 +75,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 {
@@ -91,7 +92,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 {