### Question:
DockerClient { public void save( ImageReference imageReference, Path outputPath, Consumer<Long> writtenByteCountListener) throws InterruptedException, IOException { Process dockerProcess = docker("save", imageReference.toString()); try (InputStream stdout = new BufferedInputStream(dockerProcess.getInputStream()); OutputStream fileStream = new BufferedOutputStream(Files.newOutputStream(outputPath)); NotifyingOutputStream notifyingFileStream = new NotifyingOutputStream(fileStream, writtenByteCountListener)) { ByteStreams.copy(stdout, notifyingFileStream); } if (dockerProcess.waitFor() != 0) { throw new IOException( "'docker save' command failed with error: " + getStderrOutput(dockerProcess)); } } DockerClient(Path dockerExecutable, Map<String, String> dockerEnvironment); @VisibleForTesting  DockerClient(Function<List<String>, ProcessBuilder> processBuilderFactory); static boolean isDefaultDockerInstalled(); static boolean isDockerInstalled(Path dockerExecutable); String load(ImageTarball imageTarball, Consumer<Long> writtenByteCountListener); void save(
      ImageReference imageReference, Path outputPath, Consumer<Long> writtenByteCountListener); DockerImageDetails inspect(ImageReference imageReference); static final Path DEFAULT_DOCKER_CLIENT; }### Answer:
@Test public void testSave() throws InterruptedException, IOException { DockerClient testDockerClient = makeDockerSaveClient(); Mockito.when(mockProcess.waitFor()).thenReturn(0); long[] counter = new long[1]; testDockerClient.save( ImageReference.of(null, "testimage", null), temporaryFolder.getRoot().toPath().resolve("out.tar"), bytes -> counter[0] += bytes); Assert.assertEquals(3, counter[0]); }
@Test public void testSave_fail() throws InterruptedException { DockerClient testDockerClient = makeDockerSaveClient(); Mockito.when(mockProcess.waitFor()).thenReturn(1); Mockito.when(mockProcess.getErrorStream()) .thenReturn(new ByteArrayInputStream("error".getBytes(StandardCharsets.UTF_8))); try { testDockerClient.save( ImageReference.of(null, "testimage", null), temporaryFolder.getRoot().toPath().resolve("out.tar"), ignored -> {}); Assert.fail("docker save should have failed"); } catch (IOException ex) { Assert.assertEquals("'docker save' command failed with error: error", ex.getMessage()); } }