org.hamcrest.Matcher's method equalTo() returning value like this <>

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



org.hamcrest.Matcher's method equalTo() returning value like this <<value>>



I am working on spring 5.0.7 project where I have some testcases which are getting fails which was working fine with previous version of spring.



when I am executing following statement


assertEquals("My message",401, equalTo(401));



getting following error message
enter image description here



There is additional <> comes in result. Can anyone has idea how can I fix it?



For more details earlier I was using assertThat()


assertThat(401, equalTo(401));



and this was working fine.





With assertEquals, you're testing if two objects are equal. They are obviously not equal because they are different classes: the first is an Integer and the second is a Matcher.
– DodgyCodeException
Aug 8 at 16:40



assertEquals




3 Answers
3



I revert back to assertThat() and that is working fine.



if you are a bit confused with hamcrest, you can give a try to AssertJ whose assertions are easy to discover with code completion.


assertThat(401).isEqualTo(401);
^
use code completion



equalTo returns a Matcher object which is not equal to an integer value, hence the AssertionError. <401> is just a string representation of a matcher.


equalTo


Matcher


AssertionError


<401>



With assertEquals, you're expected to pass the expected value directly, without a matcher:


assertEquals


assertEquals("My message", 401, 401);



Note that the first argument is the expected value.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard