Skip to content

Instantly share code, notes, and snippets.

@dgageot
Created February 25, 2014 11:22
Show Gist options
  • Save dgageot/9207145 to your computer and use it in GitHub Desktop.
Save dgageot/9207145 to your computer and use it in GitHub Desktop.
import org.jongo.Jongo;
import org.jongo.MongoCollection;
import org.junit.Test;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.github.fakemongo.Fongo;
import com.mongodb.DB;
import static org.assertj.core.api.Assertions.assertThat;
public class MongoJongoFongoTest {
@Test
public void test_in_memory_mongodb() {
DB db = new Fongo("Test").getDB("Database");
Jongo jongo = new Jongo(db);
MongoCollection friends = jongo.getCollection("friends");
friends.insert(
new Friend("Sheldon"),
new Friend("Leonard"),
new Friend("Penny"),
new Friend("Howard"),
new Friend("Rajesh"),
new Friend("Bernadette"),
new Friend("Amy"));
assertThat(friends.count()).isEqualTo(7);
assertThat(friends.findOne("{name: #}", "Sheldon").as(Friend.class)).isNotNull();
assertThat(friends.findOne("{name: #}", "Ross").as(Friend.class)).isNull();
}
static class Friend {
String name;
@JsonCreator
Friend(@JsonProperty("name") String name) {
this.name = name;
}
}
}
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>2.11.4</version>
</dependency>
<dependency>
<groupId>org.jongo</groupId>
<artifactId>jongo</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.github.fakemongo</groupId>
<artifactId>fongo</artifactId>
<version>1.3.6</version>
</dependency>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment