Skip to content

Commit

Permalink
Fixed entity comparison (DB proxy case bug) and improved tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
nmihajlovski committed May 30, 2015
1 parent b219f7e commit 66223f8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
Expand Up @@ -32,7 +32,9 @@ public class DbClassEqualityTest extends DbTestCommons {


@Test @Test
public void testEntityEquality() { public void testEntityEquality() {
neq(post(0L), post(0L)); neq(post(null), post(null));
neq(post(null), post(123L));
neq(post(12L), post(null));
eq(post(123L), post(123L)); eq(post(123L), post(123L));
neq(post(123L), post(547L)); neq(post(123L), post(547L));
} }
Expand Down
Expand Up @@ -32,12 +32,14 @@ public class DbInterfaceEqualityTest extends DbTestCommons {


@Test @Test
public void testEntityEquality() { public void testEntityEquality() {
eq(XDB.entity(IPost.class, "id", 1L), XDB.entity(IPost.class, "id", 1)); eq(XDB.entity(IPost.class, "id", 12), XDB.entity(IPost.class, "id", "12"));
eq(XDB.entity(IPost.class, "id", 123L), XDB.entity(IPost.class, "id", 123)); eq(XDB.entity(IPost.class, "id", 123L), XDB.entity(IPost.class, "id", 123));
neq(XDB.entity(IPost.class, "id", 12345L), XDB.entity(IPost.class)); neq(XDB.entity(IPost.class, "id", 12345L), XDB.entity(IPost.class));
neq(XDB.entity(IPost.class), XDB.entity(IPost.class, "id", 5432)); neq(XDB.entity(IPost.class), XDB.entity(IPost.class, "id", 5432));
neq(XDB.entity(IPost.class), XDB.entity(IPost.class)); neq(XDB.entity(IPost.class), XDB.entity(IPost.class));
neq(XDB.entity(IPost.class, "id", 0L), XDB.entity(IPost.class, "id", 0)); neq(XDB.entity(IPost.class, "id", null), XDB.entity(IPost.class, "id", null));
neq(XDB.entity(IPost.class, "id", null), XDB.entity(IPost.class, "id", 12));
neq(XDB.entity(IPost.class, "id", 123), XDB.entity(IPost.class, "id", null));
} }


} }
Expand Up @@ -148,15 +148,18 @@ public boolean equals(Object obj) {
return true; return true;
if (obj == null) if (obj == null)
return false; return false;
if (getClass() != obj.getClass())
if (!(obj instanceof IEntity)) {
return false; return false;
AbstractRichEntity other = (AbstractRichEntity) obj; }
if (id == null) {
if (other.id != null) IEntity other = (IEntity) obj;
return false;
} else if (!id.equals(other.id)) if (id == null || other.id() == null) {
return false; return false;
return true; }

return id.equals(other.id());
} }


@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Expand Down

0 comments on commit 66223f8

Please sign in to comment.