@Test public void shouldFetchAllItemsRespectingMaxItems() throws Exception { when(fetcher.getItemsForDataType(SMS, null, 5)).thenReturn(cursor(5)); BackupCursors cursors = bulkFetcher.fetch(EnumSet.of(SMS, MMS), null, 5); assertThat(cursors.count()).isEqualTo(5); assertThat(cursors.count(SMS)).isEqualTo(5); verify(fetcher, never()).getItemsForDataType(eq(DataType.MMS), any(ContactGroupIds.class), anyInt()); }
@Test public void shouldReportTotalCountOfAllCursors() throws Exception { assertThat(cursors.count()).isEqualTo(5); }
@Test public void shouldFetchAllItems() throws Exception { when(fetcher.getItemsForDataType(SMS, null, 50)).thenReturn(cursor(3)); when(fetcher.getItemsForDataType(MMS, null, 47)).thenReturn(cursor(5)); BackupCursors cursors = bulkFetcher.fetch(EnumSet.of(SMS, MMS), null, 50); assertThat(cursors.count()).isEqualTo(8); assertThat(cursors.count(SMS)).isEqualTo(3); assertThat(cursors.count(MMS)).isEqualTo(5); }
@Test public void shouldFetchAllItemsEmptyList() throws Exception { BackupCursors cursors = bulkFetcher.fetch(EnumSet.noneOf(DataType.class), null, 50); assertThat(cursors.count()).isEqualTo(0); }
@Test public void testEmptyCursor() { BackupCursors empty = new BackupCursors(); assertThat(empty.count()).isEqualTo(0); assertThat(empty.hasNext()).isFalse(); }
@Test public void shouldIterateOverAllContainedCursors() throws Exception { for (int i=0; i<cursors.count(); i++) { assertThat(cursors.hasNext()).isTrue(); BackupCursors.CursorAndType cursorAndType = cursors.next(); assertThat(cursorAndType).isNotNull(); assertThat(cursorAndType.cursor).isNotNull(); assertThat(cursorAndType.type).isNotNull(); } assertThat(cursors.hasNext()).isFalse(); try { cursors.next(); fail("expected exception"); } catch (NoSuchElementException e) { } }