0

I have to write an unit test in java, and was wondering what is the difference between .isEqualTo and .equals.

Here is an example of my code:

mockLog.message(0).header(SOURCE_HEADER).isEqualTo("String");

VS

mockLog.message(0).header(SOURCE_HEADER).equals("String");

It seems that both is giving me the right information, but my colleague and I was wondering what's the difference between them.

Hendrien
  • 325
  • 1
  • 10
  • 20
  • What type does `header` have? – Egor Nov 18 '16 at 14:50
  • 1
    I suppose the `isEqualTo` method comes either with Hamcrest, JUnit or AssertJ whereas the `equals` method is standard java method – Arthur Eirich Nov 18 '16 at 14:52
  • It is unclear what you are asking for. More specifically: you seem to call methods that exist on **your** classes --- in other words - what is *header()* supposed to return?! – GhostCat Nov 18 '16 at 14:59

1 Answers1

1

Assuming you're using something like AssertJ, equals() will just return false but isEqualsTo() will throw an exception.

Alastair
  • 121
  • 1
  • 4