-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Give TemplateDescriptions proper equals() and hashCode() (#312)
* Give TemplateDescriptions proper equals() and hashCode() These types are frequently used in Sets. Accordingly, they'll be hashed, and so should have proper hashCode() and equals() implementations. The implementations I chose were a best-effort guess as to the identity of the models. ClassInfo was particularly challenging as it has a mutable field and I found it challenging to figure out the difference between the various types of names. * fixup! Give TemplateDescriptions proper equals() and hashCode() * fixup! Give TemplateDescriptions proper equals() and hashCode()
- Loading branch information
1 parent
6cb0fa7
commit 7ad2e12
Showing
6 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
jte-runtime/src/test/java/gg/jte/runtime/ClassInfoTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package gg.jte.runtime; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class ClassInfoTest { | ||
|
||
@Test | ||
void equality() { | ||
var a1 = new ClassInfo("Message", "my.app"); | ||
var a2 = new ClassInfo("Message", "my.app"); | ||
var b = new ClassInfo("OtherMessage", "my.app"); | ||
var c = new ClassInfo("Message", "my.app.package"); | ||
|
||
assertThat(a1).isEqualTo(a2); | ||
assertThat(a1).hasSameHashCodeAs(a2); | ||
|
||
assertThat(a1).isNotEqualTo(b); | ||
assertThat(a1).doesNotHaveSameHashCodeAs(b); | ||
|
||
assertThat(a1).isNotEqualTo(c); | ||
assertThat(a1).doesNotHaveSameHashCodeAs(c); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
jte/src/test/java/gg/jte/compiler/extensionsupport/ExtensionTemplateDescriptionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package gg.jte.compiler.extensionsupport; | ||
|
||
import gg.jte.compiler.ClassDefinition; | ||
import gg.jte.runtime.ClassInfo; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class ExtensionTemplateDescriptionTest { | ||
|
||
@Test | ||
void equality() { | ||
var a1 = new ExtensionTemplateDescription( | ||
new ClassDefinition("Stub", "kt"), | ||
new ClassInfo("Message", "my.app") | ||
); | ||
var a2 = new ExtensionTemplateDescription( | ||
new ClassDefinition("Stub", "kt"), | ||
new ClassInfo("Message", "my.app") | ||
); | ||
var b = new ExtensionTemplateDescription( | ||
new ClassDefinition("Stub", "kt"), | ||
new ClassInfo("OtherMessage", "my.app") | ||
); | ||
var c = new ExtensionTemplateDescription( | ||
new ClassDefinition("OtherStub", "kt"), | ||
new ClassInfo("Message", "my.app") | ||
); | ||
var d = new ExtensionTemplateDescription( | ||
null, | ||
new ClassInfo("Message", "my.app") | ||
); | ||
var e = new ExtensionTemplateDescription( | ||
new ClassDefinition("OtherStub", "kt"), | ||
null | ||
); | ||
|
||
assertThat(a1).isEqualTo(a2); | ||
assertThat(a1).hasSameHashCodeAs(a2); | ||
|
||
assertThat(a1).isNotEqualTo(b); | ||
assertThat(a1).doesNotHaveSameHashCodeAs(b); | ||
|
||
assertThat(a1).isNotEqualTo(c); | ||
assertThat(a1).doesNotHaveSameHashCodeAs(c); | ||
|
||
assertThat(a1).isNotEqualTo(d); | ||
assertThat(a1).doesNotHaveSameHashCodeAs(d); | ||
|
||
assertThat(a1).isNotEqualTo(e); | ||
assertThat(a1).doesNotHaveSameHashCodeAs(e); | ||
} | ||
} |