Skip to content

Commit

Permalink
Merge pull request #154 from dickschoeller/cover-gedobject
Browse files Browse the repository at this point in the history
Issue 151 - cover gedobject
  • Loading branch information
dickschoeller committed Jan 25, 2017
2 parents 2a1bec9 + a2ac2f2 commit ddb9c95
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,6 @@ public final int hashCode() {
* @return return the string's hashCode
*/
private int stringHashCode() {
if (string == null) {
return 0;
}
return string.hashCode();
}

Expand Down Expand Up @@ -211,14 +208,7 @@ public final boolean equals(final Object obj) {
} else if (!parent.equals(other.parent)) {
return false;
}
if (string == null) {
if (other.string != null) {
return false;
}
} else if (!string.equals(other.string)) {
return false;
}
return true;
return string.equals(other.string);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
import org.junit.Before;
import org.junit.Test;
import org.schoellerfamily.gedbrowser.datamodel.Attribute;
import org.schoellerfamily.gedbrowser.datamodel.Family;
import org.schoellerfamily.gedbrowser.datamodel.FinderStrategy;
import org.schoellerfamily.gedbrowser.datamodel.GedObject;
import org.schoellerfamily.gedbrowser.datamodel.ObjectId;
import org.schoellerfamily.gedbrowser.datamodel.ParentFinder;
import org.schoellerfamily.gedbrowser.datamodel.Person;
import org.schoellerfamily.gedbrowser.datamodel.Root;

Expand All @@ -34,6 +37,9 @@ public final class GedObjectTest {
/** */
private transient GedObject gob;

/** */
private transient FinderStrategy finder = new ParentFinder();

/** */
private static class GedObjectWrapper extends GedObject {
/**
Expand All @@ -59,6 +65,7 @@ private static class GedObjectWrapper extends GedObject {
@Before
public void setUp() {
root = new Root(null, "Root");
root.setDbName("DBNAME");
}

/** */
Expand Down Expand Up @@ -129,6 +136,15 @@ public void testHashCode() {
assertEquals(HASH_CODE_1, gob.hashCode());
}

/** */
@Test
public void testInsertFamily() {
final Family family = new Family(root);
family.setString("F777");
root.insert(family);
assertEquals(family, finder.find(family, "F777", Family.class));
}

/**
* @return the new GedObject
*/
Expand Down Expand Up @@ -189,6 +205,44 @@ public void testHasAttribute() {
assertTrue(gob.hasAttribute(attribute));
}

/** */
@Test
public void testHasAttributes() {
gob = new GedObjectWrapper(root, GOB_TAG);

final Attribute attribute = new Attribute(gob, ATTR_TAG, ATTR_NAME);
gob.insert(attribute);
assertTrue(gob.hasAttributes());
}

/** */
@Test
public void testHasNoAttributes() {
gob = new GedObjectWrapper(root, GOB_TAG);
assertFalse(gob.hasAttributes());
}

/** */
@Test
public void testGetParentDbName() {
gob = new GedObjectWrapper(root, GOB_TAG);
assertEquals("DBNAME", finder.getDbName(gob));
}

/** */
@Test
public void testFindInParentBySurnameNullParent() {
gob = new GedObjectWrapper(null, GOB_TAG);
gob.findInParentBySurname("FOO");
}

/** */
@Test
public void testGetNullParentDbName() {
gob = new GedObjectWrapper(null, GOB_TAG);
assertNull(finder.getDbName(gob));
}

/** */
@Test
@SuppressWarnings("PMD.EqualsNull")
Expand Down

0 comments on commit ddb9c95

Please sign in to comment.