DockerSteps { @When("^create container \"([^\"]+)\" from \"([^\"]+)\"$") public void createContainer(String containerName, String imageTag) { runner.when(docker().client(dockerClient) .create(imageTag) .name(containerName) .validateCommandResult((result, context) -> context.setVariable(DockerMessageHeaders.CONTAINER_ID, result.getId()))); }  @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 testCreateContainer() { com.github.dockerjava.api.DockerClient dockerJavaClient = Mockito.mock(com.github.dockerjava.api.DockerClient.class); CreateContainerCmd createCmd = Mockito.mock(CreateContainerCmd.class); DockerEndpointConfiguration endpointConfiguration = new DockerEndpointConfiguration(); endpointConfiguration.setDockerClient(dockerJavaClient); when(dockerClient.getEndpointConfiguration()).thenReturn(endpointConfiguration); CreateContainerResponse response = new CreateContainerResponse(); response.setId(UUID.randomUUID().toString()); when(dockerJavaClient.createContainerCmd("fooImage:latest")).thenReturn(createCmd); when(createCmd.withName("foo")).thenReturn(createCmd); when(createCmd.exec()).thenReturn(response); steps.setClient("dockerClient"); steps.createContainer("foo", "fooImage:latest"); 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 ContainerCreate); Assert.assertEquals(action.getCommand().getParameters().get("name"), "foo"); Assert.assertEquals(action.getCommand().getParameters().get(AbstractDockerCommand.IMAGE_ID), "fooImage:latest"); Assert.assertEquals(context.getVariable(DockerMessageHeaders.CONTAINER_ID), response.getId()); }