### Question:
MongoDBDriftServer implements DriftServerPluginFacet, ServerPluginComponent { public void purgeOrphanedContent() { for (DBObject object : fileDAO.getFileListCursor()) { String id = (String) object.get("_id"); Query<MongoDBChangeSet> query = ds.createQuery(MongoDBChangeSet.class); query.or(query.criteria("files.newFileHash").equal(id), query.criteria("files.oldFileHash").equal(id)); query.limit(1); if (query.get() == null) { fileDAO.delete(id); } } }  Mongo getConnection(); void setConnection(Mongo connection); Morphia getMorphia(); void setMorphia(Morphia morphia); Datastore getDatastore(); void setDatastore(Datastore ds); ChangeSetDAO getChangeSetDAO(); void setChangeSetDAO(ChangeSetDAO changeSetDAO); FileDAO getFileDAO(); void setFileDAO(FileDAO fileDAO); @Override void initialize(ServerPluginContext context); @Override void start(); @Override void stop(); @Override void shutdown(); @Override DriftChangeSetSummary saveChangeSet(final Subject subject, final int resourceId, final File changeSetZip); @Override void saveChangeSetFiles(final Subject subject, final File changeSetFilesZip); @Override PageList<? extends DriftChangeSet<?>> findDriftChangeSetsByCriteria(Subject subject,
        DriftChangeSetCriteria criteria); @Override PageList<? extends Drift<?, ?>> findDriftsByCriteria(Subject subject, DriftCriteria criteria); @Override PageList<DriftComposite> findDriftCompositesByCriteria(Subject subject, DriftCriteria criteria); @Override DriftFile getDriftFile(Subject subject, String hashId); @Override void purgeByDriftDefinitionName(Subject subject, int resourceId, String driftDefName); @Override int purgeOrphanedDriftFiles(Subject subject, long purgeMillis); void purgeOrphanedContent(); @Override String getDriftFileBits(Subject subject, String hash); String persistChangeSet(Subject subject, DriftChangeSet<?> changeSet); @Override String copyChangeSet(Subject subject, String changeSetId, int driftDefId, int resourceId); @Override byte[] getDriftFileAsByteArray(Subject subject, String hash);  }### Answer:
@Test public void purgeOrphanedContent() throws Exception { int size = 1024; File file1 = createRandomFile(getBaseDir(), size); File file2 = createRandomFile(getBaseDir(), size); driftServer.saveChangeSetFiles(null, createChangeSetContentZipFile(file1, file2)); MongoDBChangeSet changeSet = new MongoDBChangeSet(); changeSet.setDriftDefinitionId(1); changeSet.setResourceId(1); changeSet.setDriftDefinitionName("testdef"); changeSet.setCategory(COVERAGE); changeSet.setVersion(0); MongoDBChangeSetEntry entry = new MongoDBChangeSetEntry("./1.bin", FILE_ADDED); entry.setNewFileHash(file1.getName()); changeSet.add(entry); changeSetDAO.save(changeSet); driftServer.purgeOrphanedContent(); FileDAO fileDAO = new FileDAO(ds.getDB()); assertNull(fileDAO.findById(file2.getName()), "Expected unreferenced file to be deleted"); assertNotNull(fileDAO.findById(file1.getName()), "Referenced file should not be deleted"); }