Skip to content
Browse files

create test for morphia

  • Loading branch information...
1 parent f5ff457 commit 147058bcd0146a3d84c9c3d8b23bef78a7b8a154 @sberan committed Mar 11, 2012
View
2 build.gradle
@@ -57,5 +57,7 @@ project(':fixy-morphia') {
dependencies {
compile project(':fixy-core'),
'com.google.code.morphia:morphia:0.99'
+
+ testCompile 'org.mockito:mockito-all:1.9.0'
}
}
View
2 fixy-morphia/src/main/java/com/fixy/MorphiaFixy.java
@@ -7,7 +7,7 @@ public static Fixy create(Datastore datastore, String defaultPackage) {
return new CoreFixy(new MorphiaPersister(datastore), defaultPackage);
}
- public Fixy create(Datastore datastore) {
+ public static Fixy create(Datastore datastore) {
return new CoreFixy(new MorphiaPersister(datastore));
}
}
View
36 fixy-morphia/src/test/java/com/fixy/MorphiaFixyTest.java
@@ -0,0 +1,36 @@
+package com.fixy;
+
+import com.google.code.morphia.Datastore;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+public class MorphiaFixyTest {
+ @Mock Datastore ds;
+
+ @Test public void testMorphia() {
+ Fixy fixtures = MorphiaFixy.create(ds);
+ fixtures.load("people.yaml");
+
+ Person expected = new Person();
+ expected.firstName = "Jerry";
+ expected.lastName = "Seinfeld";
+
+ Mockito.verify(ds).save(expected);
+ }
+
+ @Test public void testMorphiaNoPackage() {
+ Fixy fixtures = MorphiaFixy.create(ds, "com.fixy");
+ fixtures.load("people-nopackage.yaml");
+
+ Person expected = new Person();
+ expected.firstName = "Luke";
+ expected.lastName = "Skywalker";
+
+ Mockito.verify(ds).save(expected);
+ }
+}
View
54 fixy-morphia/src/test/java/com/fixy/Person.java
@@ -0,0 +1,54 @@
+package com.fixy;
+
+import com.google.code.morphia.annotations.Entity;
+import com.google.common.base.Objects;
+
+@Entity
+public class Person {
+ String firstName;
+ String lastName;
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ Person person = (Person) o;
+
+ if (firstName != null ? !firstName.equals(person.firstName) : person.firstName != null) return false;
+ if (lastName != null ? !lastName.equals(person.lastName) : person.lastName != null) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = firstName != null ? firstName.hashCode() : 0;
+ result = 31 * result + (lastName != null ? lastName.hashCode() : 0);
+ return result;
+ }
+
+
+ @Override
+ public String toString() {
+ return "Person{" +
+ "firstName='" + firstName + '\'' +
+ ", lastName='" + lastName + '\'' +
+ '}';
+ }
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+}
View
3 fixy-morphia/src/test/resources/people-nopackage.yaml
@@ -0,0 +1,3 @@
+ - Person(luke):
+ firstName: Luke
+ lastName: Skywalker
View
10 fixy-morphia/src/test/resources/people.yaml
@@ -0,0 +1,10 @@
+ - !package com.fixy
+
+ - Person(jerry):
+ firstName: Jerry
+ lastName: Seinfeld
+
+ - Person(george):
+ firstName: George
+ lastName: Costanza
+

0 comments on commit 147058b

Please sign in to comment.
Something went wrong with that request. Please try again.