23

I was recently trying to assert the inequality in one of the test. However I wasnt able to find the appropriate matcher in hamcrest. What I ideally want to do is something like.

assertThat(2 , isNot(3));

Is there any way to do it?

Ankit Dhingra
  • 6,534
  • 6
  • 31
  • 34

2 Answers2

33

You're almost there:

assertThat(2 , is(not(3)));
skaffman
  • 398,947
  • 96
  • 818
  • 769
  • 5
    And unless `is()` is the only matcher present, it's unnecessary syntactic sugar. `assertThat(2 , not(3));` also works here. – David Harkness Apr 28 '11 at 22:23
19

Be sure you import it:

import static org.hamcrest.CoreMatchers.not;
anfilbiblio
  • 201
  • 2
  • 2