From 94d76416cdecb1789b359358118c2de092d07d0c Mon Sep 17 00:00:00 2001 From: Konstantin Date: Tue, 25 Jul 2017 11:06:08 +0300 Subject: [PATCH] Fix NPE for GenericContainer::isRunning (#411) (#412) * Fix NPE for GenericContainer::isRunning (#411) * Add test for GenericContainer::isRunning (#411) * Fix not stopped container in test (#411) * Added comment to CHANGELOG.md (#411) --- CHANGELOG.md | 1 + .../org/testcontainers/containers/GenericContainer.java | 2 +- .../testcontainers/junit/GenericContainerRuleTest.java | 9 +++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd614aece03..276646e5081 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file. ### Fixed - Worked around incompatibility between Netty's Unix socket support and OS X 10.11. Reinstated use of TCP-Unix Socket proxy when running on OS X prior to v10.12. (Fixes #402) - Changed to use version 2.0 of the Visible Assertions library for startup pre-flight checks. This no longer has a dependency on Jansi, and is intended to resolve a JVM crash issue apparently caused by native lib version conflicts (#395). Please note that the newer ANSI code is less mature and thus has had less testing, particularly in interesting terminal environments such as Windows. If issues are encountered, coloured assertion output may be disabled by setting the system property `visibleassertions.ansi.enabled` to `true`. +- Fixed NullPointerException when calling GenericContainer#isRunning on not started container (#411) ### Changed - Removed Guava usage from `jdbc` module (#401) diff --git a/core/src/main/java/org/testcontainers/containers/GenericContainer.java b/core/src/main/java/org/testcontainers/containers/GenericContainer.java index 6b055860256..a4276a09c9a 100644 --- a/core/src/main/java/org/testcontainers/containers/GenericContainer.java +++ b/core/src/main/java/org/testcontainers/containers/GenericContainer.java @@ -723,7 +723,7 @@ public String getIpAddress() { @Override public Boolean isRunning() { try { - return dockerClient.inspectContainerCmd(containerId).exec().getState().getRunning(); + return containerId != null && dockerClient.inspectContainerCmd(containerId).exec().getState().getRunning(); } catch (DockerException e) { return false; } diff --git a/core/src/test/java/org/testcontainers/junit/GenericContainerRuleTest.java b/core/src/test/java/org/testcontainers/junit/GenericContainerRuleTest.java index b71cef1f7b4..b2a4d753b2d 100644 --- a/core/src/test/java/org/testcontainers/junit/GenericContainerRuleTest.java +++ b/core/src/test/java/org/testcontainers/junit/GenericContainerRuleTest.java @@ -144,6 +144,15 @@ public static void setupContent() throws FileNotFoundException { // assertTrue("The list contains an item that was put in (redis is working!)", testList2.contains("baz")); // } + @Test + public void testIsRunning() { + try (GenericContainer container = new GenericContainer()) { + assertFalse("Container is not started and not running", container.isRunning()); + container.start(); + assertTrue("Container is started and running", container.isRunning()); + } + } + @Test public void simpleRabbitMqTest() throws IOException, TimeoutException { ConnectionFactory factory = new ConnectionFactory();