0

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.

Tej Kiran
  • 2,218
  • 5
  • 21
  • 42
  • 2
    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 08 '18 at 16:40

3 Answers3

1

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

Tej Kiran
  • 2,218
  • 5
  • 21
  • 42
0

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
Joel Costigliola
  • 6,308
  • 27
  • 35
0

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.

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

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

Note that the first argument is the expected value.

default locale
  • 13,035
  • 13
  • 56
  • 62