### Question:
InMemoryCursor extends Cursor { @Override public List<Document> takeDocuments(int numberToReturn) { Assert.isTrue(numberToReturn > 0, () -> "Illegal number to return: " + numberToReturn); int toIndex = Math.min(remainingDocuments.size(), numberToReturn); List<Document> documents = remainingDocuments.subList(0, toIndex); remainingDocuments = remainingDocuments.subList(documents.size(), remainingDocuments.size()); return documents; } InMemoryCursor(long cursorId, List<Document> remainingDocuments); @Override boolean isEmpty(); @Override List<Document> takeDocuments(int numberToReturn);  }### Answer:
@Test void testTakeDocuments() { List<Document> documents = IntStream.range(0, 22) .mapToObj(idx -> new Document("number", idx + 1)) .collect(Collectors.toList()); InMemoryCursor cursor = new InMemoryCursor(1L, documents); assertThat(cursor.takeDocuments(1)).containsExactly(documents.get(0)); assertThat(cursor.takeDocuments(2)).containsExactly(documents.get(1), documents.get(2)); assertThat(cursor.takeDocuments(1)).containsExactly(documents.get(3)); assertThat(cursor.takeDocuments(6)).containsExactlyElementsOf(documents.subList(4, 10)); assertThat(cursor.takeDocuments(10)).containsExactlyElementsOf(documents.subList(10, 20)); assertThat(cursor.takeDocuments(10)).containsExactly(documents.get(20), documents.get(21)); assertThat(cursor.takeDocuments(10)).isEmpty(); assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> cursor.takeDocuments(0)) .withMessage("Illegal number to return: 0"); }
@Test void testTakeDocuments_returnsUnmodifiableList() { InMemoryCursor cursor = new InMemoryCursor(123L, Arrays.asList(new Document(), new Document())); List<Document> documents = cursor.takeDocuments(5); assertThatExceptionOfType(UnsupportedOperationException.class) .isThrownBy(() -> documents.remove(0)); }