Issue
I saw the following code snippet online:
As it mentioned, the argument order of Junit(expected, actual) and Hamcrest(actual, expected) is reversed.
I was wondering what is the reason behind it? Does the argument order really matter for Junit or Hamcrest? If someone accidently placed the argument in the wrong order, will it affect the result?
Solution
A lot of that confusion goes away when you realize that you only need to use assertThat. This assert simply does what all the others do; and it does it in a much better way.
And no, the order doesn't really matter. In the end, this is about matching two values. If the two values are identical, you don't care.
The only problem: if you reverse values, then fixing broken tests might be harder - as you should better understand the difference between the actual and the expected value.
Finally: there is a simple helper when using assertThat. It wants A (ctual), then E(expected). Very much in alphabetical order.
Answered By - GhostCat
Answer Checked By - Senaida (JavaFixing Volunteer)