Mockito.when(cursor.hasNext()).thenReturn(true).thenReturn(true).thenReturn(false);
Mockito.when(cursor.next()).thenReturn(new BasicDBObject("_id", Integer.valueOf(0)))
.thenReturn(new BasicDBObject("_id", Integer.valueOf(1)));
ArgumentCaptor<DBObject> queryCaptor = ArgumentCaptor.forClass(DBObject.class);
BasicQuery query = new BasicQuery("{'foo':'bar'}");
template.findAllAndRemove(query, VersionedEntity.class);
verify(collection, times(1)).remove(queryCaptor.capture());
DBObject idField = DBObjectTestUtils.getAsDBObject(queryCaptor.getValue(), "_id");