This is a very strange problem. I think we need more information, as it should work correctly. I tried to play it using JUnit 4.4 and Hamcrest 1.1 (a bit older, but this is what I use in the current project, so it was easy to check), and it worked fine.
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.
This may be because you are using an old version of Hamcrest or JUnit (which versions are you actually using? You haven't mentioned this yet). The strange thing is that you received an error message, even if you added an explicit cast to Integer . This is interesting, and it can be useful when posting this error ...
In any case, it should work just fine, as there are no syntax errors or anything else, so your installation should be the cause of the problem.
Martin sturm
source share