@Test public void deleteDeletesUnderlyingStorableEntityFile() throws IOException { // Arrange: final File file = new File(TEST_FILE_DIRECTORY, "to-be-deleted.bar"); final TEntityFileDescriptor descriptor = this.createDescriptor(file); Assert.assertThat(file.createNewFile(), IsEqual.equalTo(true)); // Act: descriptor.delete(); // Assert: Assert.assertThat(file.exists(), IsEqual.equalTo(false)); }
@Test public void deleteRaisesExceptionIfFileCannotBeDeleted() { // Arrange: final File file = Mockito.mock(File.class); Mockito.when(file.getName()).thenReturn("foo.bar"); Mockito.when(file.getAbsolutePath()).thenReturn("foo.bar"); final TEntityFileDescriptor descriptor = this.createDescriptor(file); Mockito.when(file.delete()).thenReturn(false); // Act: ExceptionAssert.assertThrowsStorageException( v -> descriptor.delete(), this.getExceptionClass(), this.getExceptionValue( StorableEntityStorageException.Code.STORABLE_ENTITY_COULD_NOT_BE_DELETED.value())); }