You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What steps will reproduce the problem?
Here are two classes
public final class AnotherSimpleClass {
private final transient OutputStream output;
public AnotherSimpleClass(final OutputStream stream) {
this.output = stream;
}
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
return true;
}
public int hashCode() {
return output != null ? output.hashCode() : 0;
}
}
and
public final class SimpleClass {
private final transient AnotherSimpleClass foo;
public SimpleClass(final AnotherSimpleClass foo) {
this.foo = foo;
}
public AnotherSimpleClass getFoo() {
return foo;
}
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final SimpleClass that = (SimpleClass) o;
if (foo != null ? !foo.equals(that.foo) : that.foo != null)
return false;
return true;
}
@Override
public int hashCode() {
return foo != null ? foo.hashCode() : 0;
}
}
equals and hashcode are generated by IDEA (in production code we use lombok)
Here are tests:
public class SimpleClassTest {
@Test
public void testEquals() throws Exception {
EqualsVerifier.forClass(SimpleClass.class)
.suppress(Warning.TRANSIENT_FIELDS)
.verify();
}
@Test
public void testEqualsAnother() throws Exception {
EqualsVerifier
.forClass(AnotherSimpleClass.class)
.suppress(Warning.TRANSIENT_FIELDS)
.verify();
}
}
So the fist problem:
AnotherSimpleClass is kinda singleton, so second test failed with
java.lang.AssertionError: Precondition: two objects are equal to each other:
And as SimpleClass uses AnotherSimpleClass first test failed with:
java.lang.AssertionError: java.lang.IllegalArgumentException: red equals black
I read your post
http://www.jqno.nl/equalsverifier/2012/11/20/precondition-two-objects-are-equal-
to-each-other/
What version of EqualsVerifier are you using?
1.4.11, 1.5.1
Original issue reported on code.google.com by [email protected] on 7 Dec 2014 at 4:22
The text was updated successfully, but these errors were encountered:
Thanks for posting this.
As for the first problem (AnotherSimpleClass): that's essentially the same
problem as Issue 46, so I will handle that there.
The second problem (SimpleClass) is a problem in EqualsVerifier. I think it
should work the way you describe, although I'm not 100% sure yet I can make
that work. At the very least, the error message should be improved.
Note, btw, that due to the implementation of AnotherSimpleClass's equals
method, the whole "(foo != null ? !foo.equals(that.foo) : that.foo != null)" is
basically a no-op if both foos are non-null.
Original issue reported on code.google.com by
[email protected]
on 7 Dec 2014 at 4:22The text was updated successfully, but these errors were encountered: