UpdateOperation implements MongoDbOperation { @Override public void execute(final MongoDatabase connection, final Document data) { for (final String collectionName : data.keySet()) { @SuppressWarnings("unchecked") final List<Document> documents = data.get(collectionName, List.class); final MongoCollection<Document> collection = connection.getCollection(collectionName); documents.forEach(d -> collection.replaceOne(Filters.eq(d.get("_id")), d)); } }  @Override void execute(final MongoDatabase connection, final Document data);  }
@Test public void testOperationExecution() { final Document data = new Document().append(USER_DEFINED_COLLECTION_NAME_2, Arrays.asList(DOCUMENT_1)) .append(USER_DEFINED_COLLECTION_NAME_1, Arrays.asList(DOCUMENT_2)); operation.execute(connection, data); final ArgumentCaptor<Document> documentCaptor = ArgumentCaptor.forClass(Document.class); verify(collection, times(2)).replaceOne(any(Bson.class), documentCaptor.capture()); final List<Document> capturedDocuments = documentCaptor.getAllValues(); assertThat(capturedDocuments.size(), equalTo(2)); assertThat(capturedDocuments, hasItems(DOCUMENT_1, DOCUMENT_2)); }