Untitled
vas
plain_text
10 months ago
952 B
4
Indexable
@Test
void testDeleteFile_Success() throws Exception {
// Arrange
AmazonS3 s3Client = Mockito.mock(AmazonS3.class); // Mock the s3Client
when(awsS3ClientBuilderService.createAwsS3Client(anyString(), anyString(), any(Regions.class)))
.thenReturn(s3Client);
// Mock listObjectsV2 to return an empty result (or provide whatever logic you need)
ListObjectsV2Result result = new ListObjectsV2Result();
when(s3Client.listObjectsV2(anyString())).thenReturn(result);
doNothing().when(s3Client).deleteObject(anyString(), anyString());
// Act
boolean result = fileMgmtService.delete(AppTestConstants.BUCKET, AppTestConstants.FILENAME);
// Assert
assertTrue(result, "File should be deleted successfully");
verify(s3Client, times(1)).deleteObject(AppTestConstants.BUCKET, AppTestConstants.FILENAME);
verify(awsS3ClientBuilderService, times(1)).shutdown(s3Client);
}
Editor is loading...
Leave a Comment