Repository: mockito/mockito
Issue: stop depending on hamcrest internally
Labels: enhancement
1.* incompatible

In order to avoid compatibility/upgrade problems we will stop depending on hamcrest internally. Hamcrest will be an optional dependency of Mockito.


Issue comments:
What's the progress on this? I'd like to use Mockito with my unit tests and I'm running JUnit 4.11 that is bundled with Eclipse 4.4 that I'm using.

Is Hamcrest dependency a blocker for using Mockito with Eclipse 4.4 ?

-- Brice

On Tue, Jan 27, 2015 at 10:10 AM, Tobias Eriksson notifications@github.com
wrote:

> What's the progress on this? I'd like to use Mockito with my unit tests
> and I'm running JUnit 4.11 that is bundled with Eclipse 4.4 that I'm using.
> 
> —
> Reply to this email directly or view it on GitHub
> https://github.com/mockito/mockito/issues/154#issuecomment-71613024.

@bric3 It seems that way. Eclipse 4.4 comes with JUnit 4.11 and Hamcrest 1.3, which apparently doesn't work with Mockito? Therefore when I try to run my JUnit plug-in tests for an Eclipse 4.4 RCP application it doesn't work.

I use Mockito 1.9.5 and 1.10.16 with JUnit 4.11 and 4.12 combined with Hamcrest 1.3 in several applications and didn't have any issues.

Fells more of an Eclipse issue, if an IDE cannot work with the project
classpath...

The team / the code is clearly not near any Mockito 2.0 _final_ release.
Anyway, this task is not even started, and it will target Mockito 2.0 as
API will change.

@bric3 @martin-g My bad, I made a plugin for Mockito and forgot to add the dependencies to Hamcrest and Objenesis. Seems to work fine now as far as I can tell..

Would be nice to at least upgrade to hamcrest 1.3 (latest version I think).

@philipwhiuk Maybe in version 2.0. Maybe we could eventually drop the dependency (at this time nothing yet decided)

Working on this. We will use hamcrest 1.3, too.

This is completed on master.


Pull request review comments:

Patch that resolved the issue:
diff --git a/build.gradle b/build.gradle
index 8f7c9ac72f..d78688fc05 100644
--- a/build.gradle
+++ b/build.gradle
@@ -62,8 +62,8 @@ tasks.withType(JavaCompile) {
 dependencies {
     compile 'net.bytebuddy:byte-buddy:0.6.8'
 
-    provided "junit:junit:4.10"
-    compile "org.hamcrest:hamcrest-core:1.1", "org.objenesis:objenesis:2.1"
+    provided "junit:junit:4.11"
+    compile "org.hamcrest:hamcrest-core:1.3", "org.objenesis:objenesis:2.1"
 
     testCompile 'org.ow2.asm:asm:5.0.4'
     testCompile fileTree("lib/test")
diff --git a/src/org/mockito/internal/matchers/LocalizedMatcher.java b/src/org/mockito/internal/matchers/LocalizedMatcher.java
index 7aeb79a73f..7adb94fb22 100644
--- a/src/org/mockito/internal/matchers/LocalizedMatcher.java
+++ b/src/org/mockito/internal/matchers/LocalizedMatcher.java
@@ -31,7 +31,11 @@ public void _dont_implement_Matcher___instead_extend_BaseMatcher_() {
     public boolean matches(Object item) {
         return actualMatcher.matches(item);
     }
-
+    
+    public void describeMismatch(Object item, Description description) {
+        actualMatcher.describeMismatch(item, description);
+    }
+    
     public void describeTo(Description description) {
         actualMatcher.describeTo(description);
     }
@@ -68,4 +72,4 @@ public void captureFrom(Object argument) {
     public Matcher getActualMatcher() {
         return actualMatcher;
     }
-}
\ No newline at end of file
+}


Test patch:
diff --git a/test/org/mockito/internal/runners/RunnerFactoryTest.java b/test/org/mockito/internal/runners/RunnerFactoryTest.java
index 7620ed7197..4b8ba78074 100644
--- a/test/org/mockito/internal/runners/RunnerFactoryTest.java
+++ b/test/org/mockito/internal/runners/RunnerFactoryTest.java
@@ -37,7 +37,7 @@ public boolean isJUnit45OrHigherAvailable() {
         RunnerImpl runner = factory.create(RunnerFactoryTest.class);
         
         //then
-        assertThat(runner, is(JUnit44RunnerImpl.class));
+        assertThat(runner, isA(JUnit44RunnerImpl.class));
     }
     
     @Test
@@ -54,7 +54,7 @@ public boolean isJUnit45OrHigherAvailable() {
         RunnerImpl runner = factory.create(RunnerFactoryTest.class);
         
         //then
-        assertThat(runner, is(JUnit45AndHigherRunnerImpl.class));
+        assertThat(runner, isA(JUnit45AndHigherRunnerImpl.class));
     }
     
     @Test
@@ -118,4 +118,4 @@ public RunnerImpl newInstance(String runnerClassName, Class<?> constructorParam)
         //then
         catch (InvocationTargetException e) {}
     }
-}
\ No newline at end of file
+}
diff --git a/test/org/mockitousage/basicapi/MocksCreationTest.java b/test/org/mockitousage/basicapi/MocksCreationTest.java
index 533826a6f4..732295a112 100644
--- a/test/org/mockitousage/basicapi/MocksCreationTest.java
+++ b/test/org/mockitousage/basicapi/MocksCreationTest.java
@@ -62,7 +62,7 @@ public void shouldCombineMockNameAndExtraInterfaces() {
         //then
         assertContains("great mockie", name);
         //and
-        assertThat(mock, is(List.class));
+        assertThat(mock, isA(List.class));
     }
     
     @Test
@@ -100,4 +100,4 @@ public void shouldAllowInlineMockCreation() throws Exception {
         when(mock(Set.class).isEmpty()).thenReturn(false);
     }
 
-}
\ No newline at end of file
+}
diff --git a/test/org/mockitoutil/ExtraMatchers.java b/test/org/mockitoutil/ExtraMatchers.java
index bd0fe349ec..bce921ec6e 100644
--- a/test/org/mockitoutil/ExtraMatchers.java
+++ b/test/org/mockitoutil/ExtraMatchers.java
@@ -134,7 +134,7 @@ public void assertValue(Collection value) {
     }
     
     public static org.hamcrest.Matcher<java.lang.Object> clazz(java.lang.Class<?> type) {
-        return CoreMatchers.is(type);
+        return CoreMatchers.isA(type);
     }
 
     public static Assertor hasMethodsInStackTrace(final String ... methods) {
@@ -147,4 +147,4 @@ public void assertValue(Throwable value) {
             }
         };
     }
-}
\ No newline at end of file
+}