Skip to content

Commit

Permalink
Add test for IO exception
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyeh committed Apr 11, 2024
1 parent 0adaf95 commit 916d9ef
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
Expand Down Expand Up @@ -122,13 +123,24 @@ void saveInvalidBlockToFile_shouldNotSaveToFileWhenDisabled(@TempDir Path tempDi
}

@Test
void saveBytesToFile_shouldNotThrowExceptionWhenUnableToSave(@TempDir Path tempDir) {
void saveBytesToFile_shouldNotThrowExceptionWhenNoDirectory(@TempDir Path tempDir) {
final DebugDataDumper manager = new DebugDataDumper(tempDir, true);
assertDoesNotThrow(
() ->
manager.saveBytesToFile("object", Path.of("invalid").resolve("file.ssz"), Bytes.EMPTY));
}

@Test
void saveBytesToFile_shouldNotEscalateWhenIOException(@TempDir Path tempDir) {
final DebugDataDumper manager = new DebugDataDumper(tempDir, true);
final File invalidPath = tempDir.resolve("invalid").toFile();
assertThat(invalidPath.mkdirs()).isTrue();
assertThat(invalidPath.setWritable(false)).isTrue();
assertDoesNotThrow(
() ->
manager.saveBytesToFile("object", Path.of("invalid").resolve("file.ssz"), Bytes.EMPTY));
}

private void checkBytesSavedToFile(final Path path, final Bytes expectedBytes) {
try {
final Bytes bytes = Bytes.wrap(Files.readAllBytes(path));
Expand Down

0 comments on commit 916d9ef

Please sign in to comment.