mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-03 00:23:24 +00:00
#879 - Ebean not fetching complete list of attribute beans when equals(Object o) is implemented
This commit is contained in:
1 parent
259814f4d9
commit
442f24124c
2 files changed
+61
-2
No files matched your search
@@ -230,4 +230,51 @@ public class BeanListTest {
|
||||
assertThat(list.getModifyRemovals()).containsExactly(object1);
|
||||
}
|
||||
|
||||
}
|
||||
@Test
|
||||
public void internalAddWithCheck_when_interestingEquals_usesInstanceEquality() {
|
||||
|
||||
BeanList<Object> list = new BeanList<>();
|
||||
assertThat(list).hasSize(0);
|
||||
|
||||
SomeBean a = new SomeBean("A");
|
||||
list.internalAddWithCheck(a);
|
||||
list.internalAddWithCheck(a);
|
||||
assertThat(list).hasSize(1);
|
||||
|
||||
// expect to ignore equals and add as it is a diff instance (aka don't use equals())
|
||||
list.internalAddWithCheck(new SomeBean("A"));
|
||||
assertThat(list).hasSize(2);
|
||||
|
||||
list.internalAddWithCheck(new SomeBean("B"));
|
||||
assertThat(list).hasSize(3);
|
||||
}
|
||||
|
||||
/**
|
||||
* A entity bean with interesting equals implementation.
|
||||
*/
|
||||
private static class SomeBean {
|
||||
|
||||
final String val;
|
||||
|
||||
SomeBean(String val) {
|
||||
this.val = val;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return 42;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
if (other instanceof SomeBean) {
|
||||
return this.val.equals(((SomeBean)other).val);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user