0

I am struggling to find a way to test two object for deep non-equality (field by field) using jUnit or/and AssertJ.

Is there any way?

Something like this.

not(assertThat(mSubjectManager.getSubjectById(subjectId))
                .isEqualToComparingFieldByField(subject));
Lukáš Řádek
  • 1,273
  • 1
  • 11
  • 23
  • Possible duplicate of [How do I assert equality on two classes without an equals method?](http://stackoverflow.com/questions/12147297/how-do-i-assert-equality-on-two-classes-without-an-equals-method) – Vasu Apr 06 '17 at 17:15
  • Junit has assertNotEquals, but you need to define .equals() for that object yourself – Ishnark Apr 06 '17 at 17:15
  • This would be a weird test. If you want something to be not equal you should check every field that must differ. I can't think of a situation where what you're asking for is a valid case. – Stanislav Bashkyrtsev Apr 06 '17 at 17:51

1 Answers1

0

With AssertJ, I think you could create a Condition wrapping a deep equals check and make it fails if deep equals, a bit weird but could work.

Joel Costigliola
  • 6,308
  • 27
  • 35