How do I assert equality on two classes without an equals method?

后端 未结 23 1666
臣服心动
臣服心动 2020-11-28 05:20

Say I have a class with no equals() method, to which do not have the source. I want to assert equality on two instances of that class.

I can do multiple asserts:

23条回答
  •  星月不相逢
    2020-11-28 05:51

    The library Hamcrest 1.3 Utility Matchers has a special matcher that uses reflection instead of equals.

    assertThat(obj1, reflectEquals(obj2));
    

提交回复
热议问题