DockerSteps { @Then("^start container \"([^\"]+)\"$") public void startContainer(String containerId) { runner.then(docker().client(dockerClient) .start(containerId) .validateCommandResult((result, context) -> Assert.isTrue(!result.isErrorIndicated(), String.format("Failed to start container '%s' - %s", containerId, result.getErrorDetail())))); }  @Before void before(); @Given("^docker-client \"([^\"]+)\"$") void setClient(String id); @When("^create container \"([^\"]+)\" from \"([^\"]+)\"$") void createContainer(String containerName, String imageTag); @When("^build image \"([^\"]+)\" from file \"([^\"]+)\"$") void buildImage(String imageTag, String fileName); @Then("^start container \"([^\"]+)\"$") void startContainer(String containerId); @Then("^stop container \"([^\"]+)\"$") void stopContainer(String containerId); @Then("^(?:the )?container \"([^\"]+)\" should be running$") void containerIsRunning(String containerId); @Then("^(?:the )?container \"([^\"]+)\" should be stopped") void containerIsStopped(String containerId);  }
@Test public void testStartContainer() { com.github.dockerjava.api.DockerClient dockerJavaClient = Mockito.mock(com.github.dockerjava.api.DockerClient.class); StartContainerCmd startCmd = Mockito.mock(StartContainerCmd.class); DockerEndpointConfiguration endpointConfiguration = new DockerEndpointConfiguration(); endpointConfiguration.setDockerClient(dockerJavaClient); when(dockerClient.getEndpointConfiguration()).thenReturn(endpointConfiguration); when(dockerJavaClient.startContainerCmd("foo")).thenReturn(startCmd); when(startCmd.withContainerId("foo")).thenReturn(startCmd); steps.setClient("dockerClient"); steps.startContainer("foo"); Assert.assertEquals(runner.getTestCase().getActionCount(), 1L); Assert.assertTrue(runner.getTestCase().getTestAction(0) instanceof DockerExecuteAction); DockerExecuteAction action = (DockerExecuteAction) runner.getTestCase().getTestAction(0); Assert.assertEquals(action.getDockerClient(), dockerClient); Assert.assertTrue(action.getCommand() instanceof ContainerStart); Assert.assertEquals(action.getCommand().getParameters().get(AbstractDockerCommand.CONTAINER_ID), "foo"); }