Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two ModelRefs with key == null should be equal #20

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion slim3-gen/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<!-- The Basics -->
<groupId>org.slim3</groupId>
<artifactId>slim3-gen</artifactId>
<version>1.0.16</version>
<version>1.0.16-jas</version>
<packaging>jar</packaging>

<!-- More Project Information -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,9 @@ protected void printPackage(Printer printer) {
protected void printClass(Printer printer) {
printer
.println(
"//@javax.annotation.Generated(value = { \"%s\", \"%s\" }, date = \"%tF %<tT\")",
"//@javax.annotation.Generated(value = { \"%s\", \"%s\" })",
ProductInfo.getName(),
ProductInfo.getVersion(),
new Date());
ProductInfo.getVersion());
printer.println("/** */");
printer.println(
"public final class %s extends %s<%s> {",
Expand Down
2 changes: 1 addition & 1 deletion slim3/src/main/java/org/slim3/datastore/ModelRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public boolean equals(Object obj) {
}
Key otherKey = ((ModelRef<?>) obj).getKey();
if (key == null) {
return false;
return otherKey == null;
}
return key.equals(otherKey);
}
Expand Down
5 changes: 4 additions & 1 deletion slim3/src/test/java/org/slim3/datastore/ModelRefTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,13 @@ public void testEquals() throws Exception {
Key key = Datastore.allocateId(Hoge.class);
assertThat(ref.equals(ref), is(true));
assertThat(ref.equals(null), is(false));
assertThat(ref.equals(other), is(false));
assertThat(ref.equals(other), is(true)); //Two ModelRefs with key==null should be equal
ref.setKey(key);
assertThat(ref.equals(other), is(false));
assertThat(other.equals(ref), is(false));
other.setKey(key);
assertThat(ref.equals(other), is(true));
assertThat(other.equals(ref), is(true));
}

/**
Expand Down