Hamcrest's lessThan doesn't compile

hamcrest, java, junit, unit-testing

Solution

I believe the problem is that JUnit comes bundled with an older copy of Hamcrest (1.1) as signatures in later version of Hamcrest are incompatible with JUnit. There are two possible solutions:

- Drop your version of Hamcrest (1.3) from the classpath, and use the copy bundled with JUnit.

- Use a different release version of JUnit (I believe the jars are named like 'junit-dep-xxx.jar) which does not include Hamcrest

- Change calls of `org.junit.Assert.assertThat()` to org.hamcrest.MatcherAssert.assertThat()`.

The latter is probably my recommended option, since the Hamcrest version of `assertThat()` produces nicer failure messages, and versions later than 1.1 have some nice features (e.g. `TypeSafeDiagnosingMatcher`).

Problem

Trying to compile this code ``` import static org.hamcrest.Matchers.is; import static org.hamcrest.number.OrderingComparison.lessThan; ... Assert.assertThat(0, is(lessThan(1))); ``` issues this compilation error: `assertThat(Object, org.hamcrest.Matcher<java.lang.Object>)` cannot be applied to `(int, org.hamcrest.Matcher<capture<? super java.lang.Integer>>)` Could be this collisions between different hamcrest versions? I'm using jUnit 4.6 and hamcrest 1.3

Original source