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?
Given this class
public final class VariableHash {
@Override
public int hashCode() {
return (int)(1000*Math.random());
}
}
Test the class with this unit test
@Test
public void equalsContract() {
EqualsVerifier.forClass(VariableHash.class).verify();
}
/////////////////////////////////////
What is the code (equals method, hashCode method, relevant fields) that
triggers the problem?
hashcode method in a class with no fields that doesn't also override equals
/////////////////////////////////////
What error message does EqualsVerifier give?
No error message, but the above test passes instead of fails.
This test actually does fail as one would expect:
@Test
public void testVariableHash() {
Object c = new VariableHash();
assertEquals(c.hashCode(), c.hashCode());
}
/////////////////////////////////////
What stacktrace does EqualsVerifier print, when called with the debug()
method?
N/A
/////////////////////////////////////
What did you expect?
Expected the test to fail.
/////////////////////////////////////
What version of EqualsVerifier are you using?
1.5
/////////////////////////////////////
Please provide any additional information below.
See conversation in google group:
https://groups.google.com/forum/?fromgroups#!topic/equalsverifier/mflja4nNBqw
Maybe we can add a check where EV tests the hashCode of an object on itself.
Maybe we should also add a check that if hashCode is defined, so should equals
be (and vice versa). But it would be necessary that such a check can be
disabled, too.
Original issue reported on code.google.com by [email protected] on 26 Sep 2014 at 1:30
The text was updated successfully, but these errors were encountered:
Original issue reported on code.google.com by
[email protected]
on 26 Sep 2014 at 1:30The text was updated successfully, but these errors were encountered: