Skip to content

Commit

Permalink
TRIB-210: code coverage test storage service
Browse files Browse the repository at this point in the history
- deleteHappyPath
  • Loading branch information
mrsbluerose committed Jan 16, 2024
1 parent 05cfb85 commit badc0b5
Showing 1 changed file with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,40 @@ public void isFileExistingSadPath() throws IOException {

long result = storageService.isFileExisting(resourceType, filename);
assertTrue(result == 0);


}

@Test
public void deleteHappyPath() throws IOException {
String resourceType = "testResourceType";
String filename = "testFile.txt";
String directoryPath = System.getProperty("java.io.tmpdir") + File.separator + "testFiles";

// Create the directory if it doesn't exist
File directory = new File(directoryPath);
directory.mkdirs();

// Create a temporary file in the specified directory
File tempFile = new File(directory, filename);
tempFile.createNewFile();

when(resourceTypeService.getDirectoryForResourceType(anyString())).thenReturn(directoryPath);

try {
// confirm new temporary file exists
long result = storageService.isFileExisting(resourceType, filename);
if(result > 0) {
// delete file and confirm it is deleted
storageService.delete(resourceType, filename);
long resultAfterDelete = storageService.isFileExisting(resourceType, filename);
assertEquals(0, resultAfterDelete);
}
} finally {
// Clean up: Delete the temporary file
tempFile.delete();

// Clean up: Delete the temporary directory
directory.delete();
}
}
}

0 comments on commit badc0b5

Please sign in to comment.