mirror of
https://github.com/google/nomulus
synced 2026-02-09 22:40:55 +00:00
Make ImmutableObject.toString deterministic (#1469)
* Make ImmutableObject.toString deterministic Remove the identity hash from the output. There is no use case (including debugging) for it. Removing it allows us to also remove some overriding implementations in subclasses, and may also simplify tests.
This commit is contained in:
@@ -68,11 +68,8 @@ public class ImmutableObjectTest {
|
||||
@Test
|
||||
void testToString_simpleClass() {
|
||||
SimpleObject object = new SimpleObject("foo", null);
|
||||
assertThat(object.toString()).isEqualTo(""
|
||||
+ "SimpleObject (@" + System.identityHashCode(object) + "): {\n"
|
||||
+ " a=foo\n"
|
||||
+ " b=null\n"
|
||||
+ "}");
|
||||
assertThat(object.toString())
|
||||
.isEqualTo("" + "SimpleObject: {\n" + " a=foo\n" + " b=null\n" + "}");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -332,8 +329,8 @@ public class ImmutableObjectTest {
|
||||
|
||||
// The hash code test test is implicit in "equals", it is added here just for clarity.
|
||||
assertThat(instance1.hashCode()).isEqualTo(instance2.hashCode());
|
||||
assertThat(instance1.toString()).matches(
|
||||
"(?s)HasInsignificantFields (.*): \\{\\s*significant=significant\\s*\\}\\s*");
|
||||
assertThat(instance1.toString())
|
||||
.matches("(?s)HasInsignificantFields: \\{\\s*significant=significant\\s*\\}\\s*");
|
||||
}
|
||||
|
||||
static class HasInsignificantFields extends ImmutableObject {
|
||||
|
||||
Reference in New Issue
Block a user