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
public class DummyClass {
enum DummyEnum {
SINGLE_VALUE
}
@Test
public void verifyHashCodeAndEquals() {
class DummyInner {
final DummyEnum value;
public DummyInner(DummyEnum value) {
this.value = value;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
DummyInner that = (DummyInner) o;
return value == that.value;
}
@Override
public int hashCode() {
return Objects.hash(value);
}
}
class DummyVersion {
final String someData;
final int someMoreData;
final DummyInner dummyInner;
public DummyVersion(String someData, int someMoreData, DummyInner dummyInner) {
this.someData = someData;
this.someMoreData = someMoreData;
this.dummyInner = dummyInner;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
DummyVersion that = (DummyVersion) o;
return someMoreData == that.someMoreData &&
Objects.equals(someData, that.someData) &&
Objects.equals(dummyInner, that.dummyInner);
}
@Override
public int hashCode() {
return Objects.hash(someData, someMoreData, dummyInner);
}
}
EqualsVerifier.forClass(DummyVersion.class).usingGetClass().verify();
}
}
What error message or stack trace does EqualsVerifier give?
java.lang.AssertionError: Significant fields: equals does not use dummyInner, or it is stateless.
For more information, go to: http://www.jqno.nl/equalsverifier/errormessages
at nl.jqno.equalsverifier.EqualsVerifier.handleError(EqualsVerifier.java:389)
at nl.jqno.equalsverifier.EqualsVerifier.verify(EqualsVerifier.java:375)
What did you expect?
I expect the test to pass
Which version of EqualsVerifier are you using?
2.5
Please provide any additional information below.
The reason why I expect this to work is because even though the enum's value can only be SINGLE_VALUE right now, there will be more enums in the future. In reality, DummyVersion has a bunch of members where I do need to make sure equals and hashcode are correctly implemented, so I can't just skip using EqualsVerifier either.
I figured I would've been able to fix this by ignoring dummyInner:
java.lang.AssertionError: Significant fields: equals should not use dummyInner, but it does.
For more information, go to: http://www.jqno.nl/equalsverifier/errormessages
at nl.jqno.equalsverifier.EqualsVerifier.handleError(EqualsVerifier.java:375)
at nl.jqno.equalsverifier.EqualsVerifier.verify(EqualsVerifier.java:361)
The text was updated successfully, but these errors were encountered:
What steps will reproduce the problem?
Running the given JUnit test
What is the code that triggers this problem?
What error message or stack trace does EqualsVerifier give?
What did you expect?
I expect the test to pass
Which version of EqualsVerifier are you using?
2.5
Please provide any additional information below.
The reason why I expect this to work is because even though the enum's value can only be
SINGLE_VALUE
right now, there will be more enums in the future. In reality, DummyVersion has a bunch of members where I do need to make sureequals
andhashcode
are correctly implemented, so I can't just skip using EqualsVerifier either.I figured I would've been able to fix this by ignoring dummyInner:
But that gives me
The text was updated successfully, but these errors were encountered: