Skip to content

Commit 257acad

Browse files
committed
TRIB-210: code coverage test for storage service
- isFileExistingHappyPath
1 parent a36d8f5 commit 257acad

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

src/test/java/com/savvato/tribeapp/services/StorageServiceImplTest.java

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,15 @@
1010
import org.springframework.test.context.junit.jupiter.SpringExtension;
1111
import org.springframework.web.multipart.MultipartFile;
1212

13-
import static org.junit.jupiter.api.Assertions.assertEquals;
13+
import org.apache.commons.logging.Log;
14+
import org.apache.commons.logging.LogFactory;
15+
16+
import java.io.File;
17+
import java.io.IOException;
18+
19+
import static org.junit.jupiter.api.Assertions.*;
1420
import static org.mockito.ArgumentMatchers.anyString;
21+
import static org.mockito.ArgumentMatchers.eq;
1522
import static org.mockito.Mockito.when;
1623

1724
@ExtendWith(SpringExtension.class)
@@ -49,4 +56,32 @@ public void storeHappyPath() {
4956
when(resourceTypeService.getDirectoryForResourceType(anyString())).thenReturn(dir);
5057
storageService.store(resourceType, file, filename);
5158
}
59+
60+
@Test
61+
public void isFileExistingHappyPath() throws IOException {
62+
String resourceType = "testResourceType";
63+
String filename = "testFile.txt";
64+
String directoryPath = System.getProperty("java.io.tmpdir") + File.separator + "testFiles";
65+
66+
// Create the directory if it doesn't exist
67+
File directory = new File(directoryPath);
68+
directory.mkdirs();
69+
70+
// Create a temporary file in the specified directory
71+
File tempFile = new File(directory, filename);
72+
tempFile.createNewFile();
73+
74+
when(resourceTypeService.getDirectoryForResourceType(anyString())).thenReturn(directoryPath);
75+
76+
try {
77+
long result = storageService.isFileExisting(resourceType, filename);
78+
assertTrue(result > 0);
79+
} finally {
80+
// Clean up: Delete the temporary file
81+
tempFile.delete();
82+
83+
// Clean up: Delete the temporary directory
84+
directory.delete();
85+
}
86+
}
5287
}

0 commit comments

Comments
 (0)