Skip to content

Commit fa5b667

Browse files
committed
Update unit test
1 parent 5196329 commit fa5b667

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

core/src/test/java/com/scalar/db/storage/objectstorage/cloudstorage/CloudStorageWrapperTest.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,7 @@ public void deleteByPrefix_PrefixGiven_ShouldDeleteAllObjectsWithThePrefix() thr
345345
@SuppressWarnings("unchecked")
346346
Page<Blob> page = mock(Page.class);
347347
when(storage.list(eq(BUCKET), any(Storage.BlobListOption.class))).thenReturn(page);
348-
when(page.getValues()).thenReturn(Arrays.asList(blob1, blob2, blob3));
349-
when(page.getNextPage()).thenReturn(null);
348+
when(page.iterateAll()).thenReturn(Arrays.asList(blob1, blob2, blob3));
350349

351350
StorageBatch batch = mock(StorageBatch.class);
352351
when(storage.batch()).thenReturn(batch);
@@ -377,17 +376,11 @@ public void deleteByPrefix_MultiplePagesGiven_ShouldDeleteAllObjectsAcrossPages(
377376
when(blob2.getName()).thenReturn(objectKey2);
378377
when(blob3.getName()).thenReturn(objectKey3);
379378

380-
// Mock paginated responses with 2 pages
381-
@SuppressWarnings("unchecked")
382-
Page<Blob> page1 = mock(Page.class);
379+
// Mock with iterateAll() that returns all blobs across pages
383380
@SuppressWarnings("unchecked")
384-
Page<Blob> page2 = mock(Page.class);
385-
386-
when(storage.list(eq(BUCKET), any(Storage.BlobListOption.class))).thenReturn(page1);
387-
when(page1.getValues()).thenReturn(Arrays.asList(blob1, blob2));
388-
when(page1.getNextPage()).thenReturn(page2);
389-
when(page2.getValues()).thenReturn(Collections.singletonList(blob3));
390-
when(page2.getNextPage()).thenReturn(null);
381+
Page<Blob> page = mock(Page.class);
382+
when(storage.list(eq(BUCKET), any(Storage.BlobListOption.class))).thenReturn(page);
383+
when(page.iterateAll()).thenReturn(Arrays.asList(blob1, blob2, blob3));
391384

392385
StorageBatch batch = mock(StorageBatch.class);
393386
when(storage.batch()).thenReturn(batch);
@@ -399,8 +392,8 @@ public void deleteByPrefix_MultiplePagesGiven_ShouldDeleteAllObjectsAcrossPages(
399392
wrapper.deleteByPrefix(ANY_PREFIX);
400393

401394
// Assert
402-
verify(storage, org.mockito.Mockito.times(2)).batch();
403-
verify(batch, org.mockito.Mockito.times(2)).submit();
395+
verify(storage).batch();
396+
verify(batch).submit();
404397
}
405398

406399
@Test
@@ -409,8 +402,7 @@ public void deleteByPrefix_NoObjectsWithPrefix_ShouldDoNothing() throws Exceptio
409402
@SuppressWarnings("unchecked")
410403
Page<Blob> page = mock(Page.class);
411404
when(storage.list(eq(BUCKET), any(Storage.BlobListOption.class))).thenReturn(page);
412-
when(page.getValues()).thenReturn(Collections.emptyList());
413-
when(page.getNextPage()).thenReturn(null);
405+
when(page.iterateAll()).thenReturn(Collections.emptyList());
414406

415407
// Act
416408
wrapper.deleteByPrefix(ANY_PREFIX);

0 commit comments

Comments
 (0)