### Question:
Dumper { public void dump( Path dbPath, Path transactionalLogsPath, Path archive, CompressionFormat format, Predicate<Path> exclude ) throws IOException { checkWritableDirectory( archive.getParent() ); operations.clear(); visitPath( dbPath, exclude ); if ( !Util.isSameOrChildPath( dbPath, transactionalLogsPath ) ) { visitPath( transactionalLogsPath, exclude ); } progressPrinter.reset(); for ( ArchiveOperation operation : operations ) { progressPrinter.maxBytes += operation.size; progressPrinter.maxFiles += operation.isFile ? 1 : 0; } try ( ArchiveOutputStream stream = openArchiveOut( archive, format ); Resource ignore = progressPrinter.startPrinting() ) { for ( ArchiveOperation operation : operations ) { operation.addToArchive( stream ); } } } @VisibleForTesting  Dumper();  Dumper( PrintStream output ); void dump( Path dbPath, Path transactionalLogsPath, Path archive, CompressionFormat format, Predicate<Path> exclude );  }### Answer:
@Test void shouldGiveAClearErrorIfTheArchiveAlreadyExists() throws IOException { Path directory = testDirectory.directory( "a-directory" ).toPath(); Path archive = testDirectory.file( "the-archive.dump" ).toPath(); Files.write( archive, new byte[0] ); FileAlreadyExistsException exception = assertThrows( FileAlreadyExistsException.class, () -> new Dumper().dump( directory, directory, archive, GZIP, Predicates.alwaysFalse() ) ); assertEquals( archive.toString(), exception.getMessage() ); }
@Test void shouldGiveAClearErrorMessageIfTheDirectoryDoesntExist() { Path directory = testDirectory.file( "a-directory" ).toPath(); Path archive = testDirectory.file( "the-archive.dump" ).toPath(); NoSuchFileException exception = assertThrows( NoSuchFileException.class, () -> new Dumper().dump( directory, directory, archive, GZIP, Predicates.alwaysFalse() ) ); assertEquals( directory.toString(), exception.getMessage() ); }
@Test void shouldGiveAClearErrorMessageIfTheArchivesParentDirectoryDoesntExist() { Path directory = testDirectory.directory( "a-directory" ).toPath(); Path archive = testDirectory.file( "subdir/the-archive.dump" ).toPath(); NoSuchFileException exception = assertThrows( NoSuchFileException.class, () -> new Dumper().dump( directory, directory, archive, GZIP, Predicates.alwaysFalse() ) ); assertEquals( archive.getParent().toString(), exception.getMessage() ); }
@Test void shouldGiveAClearErrorMessageIfTheArchivesParentDirectoryIsAFile() throws IOException { Path directory = testDirectory.directory( "a-directory" ).toPath(); Path archive = testDirectory.file( "subdir/the-archive.dump" ).toPath(); Files.write( archive.getParent(), new byte[0] ); FileSystemException exception = assertThrows( FileSystemException.class, () -> new Dumper().dump( directory, directory, archive, GZIP, Predicates.alwaysFalse() ) ); assertEquals( archive.getParent().toString() + ": Not a directory", exception.getMessage() ); }
@Test @DisabledOnOs( OS.WINDOWS ) void shouldGiveAClearErrorMessageIfTheArchivesParentDirectoryIsNotWritable() throws IOException { Path directory = testDirectory.directory( "a-directory" ).toPath(); Path archive = testDirectory.file( "subdir/the-archive.dump" ).toPath(); Files.createDirectories( archive.getParent() ); try ( Closeable ignored = TestUtils.withPermissions( archive.getParent(), emptySet() ) ) { assumeFalse( archive.getParent().toFile().canWrite() ); AccessDeniedException exception = assertThrows( AccessDeniedException.class, () -> new Dumper().dump( directory, directory, archive, GZIP, Predicates.alwaysFalse() ) ); assertEquals( archive.getParent().toString(), exception.getMessage() ); } }