DeleteOperation implements MongoDbOperation { @Override public void execute(final MongoDatabase connection, final Document data) { for (final String collectionName : data.keySet()) { @SuppressWarnings("unchecked") final List<Document> entry = data.get(collectionName, List.class); final MongoCollection<Document> collection = connection.getCollection(collectionName); entry.forEach(collection::deleteOne); } }  @Override void execute(final MongoDatabase connection, final Document data);  }
@Test public void testOperationExecution() { final List<Document> values1 = Arrays.asList(DOCUMENT_1); final List<Document> values2 = Arrays.asList(DOCUMENT_2); final Document data = new Document().append(COLLECTION_NAME_1, values1).append(COLLECTION_NAME_2, values2); operation.execute(connection, data); final ArgumentCaptor<String> collectionNameCaptor = ArgumentCaptor.forClass(String.class); verify(connection, times(2)).getCollection(collectionNameCaptor.capture()); final List<String> capturedCollectionNames = collectionNameCaptor.getAllValues(); assertThat(capturedCollectionNames.size(), equalTo(2)); assertThat(capturedCollectionNames, hasItems(COLLECTION_NAME_1, COLLECTION_NAME_2)); final ArgumentCaptor<Document> documentCaptor = ArgumentCaptor.forClass(Document.class); verify(collection, times(2)).deleteOne(documentCaptor.capture()); final List<Document> capturedDocuments = documentCaptor.getAllValues(); assertThat(capturedDocuments.size(), equalTo(2)); assertThat(capturedDocuments, hasItems(DOCUMENT_1, DOCUMENT_2)); }