It is a very strange problem. I think we need some more information, since it should work correctly. I tried to reproduce it using JUnit 4.4 and Hamcrest 1.1 (a bit older, but that's what I'm using at my current project, so it was easy to test) and it worked perfectly.
The only difference I noticed is that my Eclipse imported org.hamcrest.Matchers.lessThan
instead of org.hamcrest.number.OrderingComparisons.lessThan
, but when I used the latter it worked flawlessly as well.
It could be caused by the fact that you using an old version of Hamcrest or JUnit (which versions are you actually using? You didn't mentioned it yet). What is strange is the fact that you got an error even when you've added an explicit cast to Integer
. That's interesting, and it could be helpful when you post this error...
Anyway, it should work perfectly since there are no syntax errors or something, so your setup has to be the cause of the problem.