Skip to content

Instantly share code, notes, and snippets.

@pvardanega
Last active August 29, 2015 13:56
Show Gist options
  • Save pvardanega/9d82f8b977a4f332627a to your computer and use it in GitHub Desktop.
Save pvardanega/9d82f8b977a4f332627a to your computer and use it in GitHub Desktop.
Fongo Jongo Junit rule
import com.github.fakemongo.Fongo;
import org.jongo.Jongo;
import org.jongo.MongoCollection;
import org.junit.rules.ExternalResource;
public class FongoJongo extends ExternalResource {
private final Jongo jongo;
private FongoJongo() {
jongo = new Jongo(new Fongo("Test").getDB("Database"));
}
@Override
protected void after() {
super.after();
for (String collectionName : jongo.getDatabase().getCollectionNames()) {
getCollection(collectionName).drop();
}
}
public MongoCollection getCollection(String collectionName) {
return jongo.getCollection(collectionName);
}
[...]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment