Problem should override equals and hashcode
See original GitHub issueI would like to write tests to compare thrown problems like this
exception.expect(is(Problem.valueOf(MoreStatus.UNPROCESSABLE_ENTITY, "Some error")))
org.hamcrest.core.Is compares objects using equals method of objects.
So to be able write those kind of tests I need Problem to override equals method.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:9
Top Results From Across the Web
Why to Override equals(Object) and hashCode() method
Whenever it(hashcode) is invoked on the same object more than once during an execution of a Java application, the hashCode method must ...
Read more >Why do we need to override equals and hashcode methods in ...
We know that two objects are considered equal only if their references point to the same object, and unless we override equals and...
Read more >Why : Overriding equals() and hashCode() in Java - Medium
i added these emp objects to a HashSet. Set should override the duplicate values and should return me only one object as both...
Read more >Why Override equals, hashcode and toString method in Java ...
According to which, you must override hashcode if you are overriding equals and vice-versa. The problem is that this is not enforced by...
Read more >Java equals() and hashCode() Contracts - Baeldung
If we want to use instances of the Team class as HashMap keys, we have to override the hashCode() method so that it...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
No, that would break the contract of equals:
I agree. Doing this right is borderline impossible on interface level. I recommend reading Chapter 3 of Effective Java Programming Language Guide By Joshua Bloch on this.
@whiskeysierra Has this issue been abandoned ? How do you unit test without some sort of
equals
method or matcher ?