fb-contrib icon indicating copy to clipboard operation
fb-contrib copied to clipboard

Test classes do not need equals or hashCode

Open ThrawnCA opened this issue 6 years ago • 3 comments

Our test classes frequently have fields, eg for mock injection, but as far as I can tell, there is no reason for them to implement equals or hashCode. IMC_IMMATURE_CLASS_NO_EQUALS and IMC_IMMATURE_CLASS_NO_TOSTRING should not apply.

I'm not sure of the best way to identify unit test classes, but the presence of annotated test methods should be fairly quick to check. Filename patterns aren't the most reliable, but it's worth at least considering the default Surefire patterns.

ThrawnCA avatar Jan 11 '19 05:01 ThrawnCA

reasonable

mebigfatguy avatar Jan 21 '19 22:01 mebigfatguy

hold on. this should already be happening. The code looks for annotations on any method of the class that if (type.startsWith("Lorg/junit/") || type.startsWith("Lorg/testng/")) {

is there something wrong there?

mebigfatguy avatar Jan 21 '19 23:01 mebigfatguy

Hmm, looks like you're right. We had an exclusion rule for that, but maybe it's outdated now.

ThrawnCA avatar Feb 03 '19 23:02 ThrawnCA