Symmetry error - why? #519
-
So I'm testing the use of EqualsVerifier against a jfreechart class: CategoryItemEntity. Fixed a couple of errors found by EqualsVerifier, but now I'm getting this output and I'm stuck on how to fix it.
I did read the explanation at the url, but I'm still lost. Here's the JUnit test (I tried copying/pasting the code but it looked terrible, even when I surrounded it by the markup tic, so here's some screenshots): Here's the hashCode method for CategoryItemEntity: When I ran the JUnit test in debug mode, I set a breakpoint at line 230 in CategoryItemEntity so I could see what the values of "rowKey" were. One was null, the other was this nl.jqno.equalsverifier.internal.reflection.Comparable$$DynamicSubclass. Any help would be appreciated! Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
Hi! |
Beta Was this translation helpful? Give feedback.
-
I did do some RTFM since then, and now I'm wondering if it could be something about the superclass. It's JFreeChart 1.5.3, so if you want to download the source for that release it's here: https://github.com/jfree/jfreechart/releases/tag/v1.5.3 Thanks for your help! |
Beta Was this translation helpful? Give feedback.
-
I see it now.
Basically, if you don't want to change the existing implementation of |
Beta Was this translation helpful? Give feedback.
-
Indeed, I make a point of it that EqualsVerifier should give 100% test coverage for equals methods 😄 Glad I could help! |
Beta Was this translation helpful? Give feedback.
I see it now.
CategoryItemEntity
implementsequals
. But it overridesChartEntity
which also implementsequals
. That means that we're talking about a type that adds state. That's the hardest thing to get right with EqualsVerifier, unfortunately. I have a short bit about that on the website, but you've probably already read that. I have a Devoxx talk that goes into a little more depth, if you prefer video.Basically, if you don't want to change the existing implementation of
equals
, you need to add.withRedefinedSuperclass()
on theCategoryItemEntity
test, and.withRedefinedSubclass(CategoryItemEntity.class)
on theChartEntity
test.