@Test public void openWriteCanOpenFileThatExists() throws IOException { // Arrange: final TEntityFileDescriptor descriptor = this.createDescriptor(TEST_FILE); // Act: try (final OutputStream os = descriptor.openWrite()) { // Assert: Assert.assertThat(os, IsNull.notNullValue()); } }
@Test public void openWriteCanOpenFileThatDoesNotExist() throws IOException { // Arrange: final File file = new File(TEST_FILE_DIRECTORY, "imaginary-write.bar"); final TEntityFileDescriptor descriptor = this.createDescriptor(file); // Act: try (final OutputStream os = descriptor.openWrite()) { // Assert: Assert.assertThat(os, IsNull.notNullValue()); } }
@Test public void openWriteCannotOpenFileThatIsInvalid() { // Arrange: final File file = Mockito.mock(File.class); Mockito.when(file.getName()).thenReturn("fo\0o.bar"); Mockito.when(file.getAbsolutePath()).thenReturn("fo\0o.bar"); final TEntityFileDescriptor descriptor = this.createDescriptor(file); // Act: ExceptionAssert.assertThrowsStorageException( v -> descriptor.openWrite(), this.getExceptionClass(), this.getExceptionValue( StorableEntityStorageException.Code.STORABLE_ENTITY_COULD_NOT_BE_SAVED.value())); }