|
31 | 31 |
|
32 | 32 | import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; |
33 | 33 | import static org.junit.jupiter.api.Assertions.assertEquals; |
| 34 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
34 | 35 | import static org.junit.jupiter.api.Assertions.assertNull; |
35 | 36 | import static org.junit.jupiter.api.Assertions.assertThrows; |
36 | 37 | import static org.junit.jupiter.api.Assertions.assertTrue; |
| 38 | +import static org.mockito.ArgumentMatchers.any; |
| 39 | +import static org.mockito.ArgumentMatchers.eq; |
| 40 | +import static org.mockito.Mockito.mock; |
| 41 | +import static org.mockito.Mockito.never; |
| 42 | +import static org.mockito.Mockito.times; |
| 43 | +import static org.mockito.Mockito.verify; |
| 44 | +import static org.mockito.Mockito.when; |
37 | 45 |
|
38 | 46 | class JCloudsObjectStoreFileStorageTest { |
39 | 47 |
|
@@ -368,4 +376,47 @@ protected void assertFileExists(boolean expectedFileExist, FileEntry actualFile) |
368 | 376 | assertEquals(expectedFileExist, blobExists); |
369 | 377 | } |
370 | 378 |
|
| 379 | + @Test |
| 380 | + void existsInObjectStoreWithMockedBlobStoreVerifiesBlobExistsCalled() { |
| 381 | + BlobStore mockBlobStore = mock(BlobStore.class); |
| 382 | + FileEntry fileEntry = createFileEntry(); |
| 383 | + JCloudsObjectStoreFileStorage testFileStorage = new JCloudsObjectStoreFileStorage(mockBlobStore, CONTAINER); |
| 384 | + |
| 385 | + when(mockBlobStore.blobExists(CONTAINER, fileEntry.getId())).thenReturn(true); |
| 386 | + |
| 387 | + boolean result = testFileStorage.existsInObjectStore(fileEntry); |
| 388 | + |
| 389 | + verify(mockBlobStore, times(1)).blobExists(CONTAINER, fileEntry.getId()); |
| 390 | + assertTrue(result); |
| 391 | + } |
| 392 | + |
| 393 | + @Test |
| 394 | + void existsInObjectStoreWithMockedBlobStoreFileNotFound() { |
| 395 | + BlobStore mockBlobStore = mock(BlobStore.class); |
| 396 | + FileEntry fileEntry = createFileEntry(); |
| 397 | + JCloudsObjectStoreFileStorage testFileStorage = new JCloudsObjectStoreFileStorage(mockBlobStore, CONTAINER); |
| 398 | + |
| 399 | + when(mockBlobStore.blobExists(CONTAINER, fileEntry.getId())).thenReturn(false); |
| 400 | + |
| 401 | + boolean result = testFileStorage.existsInObjectStore(fileEntry); |
| 402 | + |
| 403 | + verify(mockBlobStore, times(1)).blobExists(CONTAINER, fileEntry.getId()); |
| 404 | + assertFalse(result); |
| 405 | + } |
| 406 | + |
| 407 | + @Test |
| 408 | + void existsInObjectStoreWithMockedBlobStoreVerifiesCorrectContainer() { |
| 409 | + BlobStore mockBlobStore = mock(BlobStore.class); |
| 410 | + String testContainer = "test-container"; |
| 411 | + FileEntry fileEntry = createFileEntry(); |
| 412 | + JCloudsObjectStoreFileStorage testFileStorage = new JCloudsObjectStoreFileStorage(mockBlobStore, testContainer); |
| 413 | + |
| 414 | + when(mockBlobStore.blobExists(testContainer, fileEntry.getId())).thenReturn(true); |
| 415 | + |
| 416 | + boolean result = testFileStorage.existsInObjectStore(fileEntry); |
| 417 | + |
| 418 | + verify(mockBlobStore, times(1)).blobExists(testContainer, fileEntry.getId()); |
| 419 | + verify(mockBlobStore, never()).blobExists(eq("wrong-container"), any()); |
| 420 | + assertTrue(result); |
| 421 | + } |
371 | 422 | } |
0 commit comments