Eclipse - Shazamcrest - java.lang.NoSuchFieldError: NONE

I am getting this error in Eclipse STS 3.6.3. I have basic Hamcrest calls working after removing the hamcrest jar from the eclipse plugin directory. From what I can tell, this is using hamcrest 1.3 and JUnit 4. I looked in Run> Run Configurations> myTest> Sources tab> Default and I can see the hamcrest 1.3 jar from my local maven repository.

It works using mvn command line, but not in eclipse.

Any idea what's going on here and how can I fix it?

@Test
public void testShazamcrestMap() throws Exception {
    HashMap<String,String> item = new HashMap<String,String>(); 
    HashMap<String,String> item2 = new HashMap<String,String>();

    item.put("foo", "bar");
    item2.put("foo", "bar");

    assertThat(item, sameBeanAs(item2));
}

      

java.lang.NoSuchFieldError: NONE at org.hamcrest.DiagnosingMatcher.matches (DiagnosingMatcher.java:12) at com.shazam.shazamcrest.MatcherAssert.assertThat (MatcherAssert.java:40) at com.shazam.shazamcrest.Matcher MatcherAssert.java:29) at com.nick.feed.test.SomeUnitTest.testShazamcrestMap (SomeUnitTest.java:49) at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native method) at sun.reflect.NativeMethodAccessorImpl.invavahod 39) at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke (Method.java:597) at org.junit.runners.model.FrameworkMethod (FrameworkMethod $ 1.runReflective. java: 44) at org.junit.internal.runners.model.ReflectiveCallable.run (ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively (FrameworkMethod.java:41) at org.junit.internal.runners.statements.InvokeMethod.evaluate (InvokeMethod.java:20) at org.junit.internal.runners.statements.RunBefores.evaluate java: 28) to org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored (BlockJUnit4ClassRunner.java:79) to org.junit.runners.BlockJUnit4ClassRunner.runChild (BlockJUnit4ClassRunner.jildChild (BlockJUnit4ClassRunner.java:79) .java: 49) at org.junit.runners.ParentRunner $ 3.run (ParentRunner.java:193) at org.junit.runners.ParentRunner $ 1.schedule (ParentRunner.java:52) at org.junit.runners.ParentRunner. runChildren (ParentRunner.java:191) at org.junit.runners.ParentRunner.access $ 000 (ParentRunner.java:42) at org.junit.runners.ParentRunner $ 2.evaluate (ParentRunner.java: 184) to org.junit.runners.ParentRunner.run (ParentRunner.java:236) to org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run (JUnit4TestReference.java:50) at org.eclipse .internal.junit.runner.TestExecution.run (TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests (RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit .runner.RemoteTestRunner.runTests (RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run (RemoteTestRunner.java:390) at org.eclipse.jdt.internal.jmounit. .main (RemoteTestRunner.java:197)runner.TestExecution.run (TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests (RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runestRunner.Remote. runTests (RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run (RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main (. java: 197)runner.TestExecution.run (TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests (RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runestRunner.Remote. runTests (RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run (RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main (. java: 197)

+3


source to share


1 answer


I have successfully passed this test with IntelliJ.

My environment: junit-4.12, hamcrest-1.3, shazamcrest-0.9

Make sure you only have one possible dependency for Hamcrest. Older versions of Junit are notorius causing problems with Hamcrest.



Junit 4.10 and earlier actually has Hamcrest built in (in addition to the Maven dependency). If you must be using Junit 4.10 or earlier, use junit-dep, which does not include Hamcrest. I would recommend updating before June 4th.

The version of Eclipse you are using may include Hamcrest via Junit. If so, Google will remove it.

+1


source







All Articles