liangzai-cool / hamcrest

Automatically exported from code.google.com/p/hamcrest
0 stars 0 forks source link

assertThat throws error #76

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
when assertion fails eg:

assertThat("size", ruleAnswer.size(), equalTo(3));

The following is thrown

java.lang.NoSuchMethodError: 
org.hamcrest.Matcher.describeMismatch(Ljava/lang/Object;Lorg/hamcrest/Descr
iption;)V
    at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:18)
    at 
com.citigroup.cdcla.jba.busunit.BusinessUnitTest.test_answer_basic_rule_acc
tnudisplay(BusinessUnitTest.java:94)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:3
9)
    at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImp
l.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at junit.framework.TestCase.runTest(TestCase.java:164)
    at junit.framework.TestCase.runBare(TestCase.java:130)
    at junit.framework.TestResult$1.protect(TestResult.java:106)
    at junit.framework.TestResult.runProtected(TestResult.java:124)
    at junit.framework.TestResult.run(TestResult.java:109)
    at junit.framework.TestCase.run(TestCase.java:120)
    at junit.framework.TestSuite.runTest(TestSuite.java:230)
    at junit.framework.TestSuite.run(TestSuite.java:225)
    at 
org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3
TestReference.java:130)
    at 
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:
38)
    at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestR
unner.java:460)
    at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestR
unner.java:673)
    at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner
.java:386)
    at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunne
r.java:196)

Original issue reported on code.google.com by bhup...@gmail.com on 9 Apr 2009 at 8:23

GoogleCodeExporter commented 9 years ago
I forgot I got this error on 1.2RC4. I have hamcrest-all-1.2RC$ in path.

Original comment by bhup...@gmail.com on 9 Apr 2009 at 8:24

GoogleCodeExporter commented 9 years ago
I tried this on my machine and it works :) Can you try setting up a temporary 
project to make sure the 
dependencies are right. For example, is there a clash with something in your 
version of JUnit? Can you check you 
version of Matcher to make sure that it has the missing method?

Original comment by smgfree...@gmail.com on 10 Apr 2009 at 7:45

GoogleCodeExporter commented 9 years ago
Issue not confirmed, so closing. Will reopen if asked.

Original comment by smgfree...@gmail.com on 25 Apr 2009 at 8:47

GoogleCodeExporter commented 9 years ago
I am seeing the same issue when running in Eclipse with JUnit 4.4

Original comment by cmichael...@netscape.net on 8 May 2009 at 3:58

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
A thought. Are you using the no-dependencies version of JUnit. If not, you 
might be picking up the previous 
Matcher that's included with JUnit.

Original comment by smgfree...@gmail.com on 8 May 2009 at 10:56

GoogleCodeExporter commented 9 years ago
I had the same problem with org.hamcrest.Matcher being picked up in the JUnit 
4.4 JAR.  
Changing to the no dependencies version (albeit 4.6) didn't work by itself -- I 
also had to 
change to the no dependencies versions of Mockito and Hamcrest.

With only these JARs on the build path, this problem is resolved for me:
* junit-dep-4.6.jar
* hamcrest-core-1.2.jar
* mockito-core-1.7.jar
* objenesis-1.0.jar

It seems that the org.hamcrest.Matcher included in mockito-all-1.7.jar is from 
Hamcrest 1.1 
(i.e. does not have the describeMismatch() method) even though Mockito appears 
to depend on 
Hamcrest 1.2.  I checked in the full distribution of Mockito 1.7 and it 
incluedes hamcrest-
all-1.1.jar (1.8.0-rc1 seems to have this problem too?  Or is it just me doing 
something 
silly?).

Anyhow, Mockito rocks my world :-)  Now we just need to migrate to Maven...

Original comment by todd1...@gmail.com on 18 Jun 2009 at 2:21

GoogleCodeExporter commented 9 years ago
I had this problem in Eclipse. It's dependant on the class path order - it only 
works
for me if junit-4.8.1.jar is loaded after the hamcrest jars, so that the newer
version of the Matcher interface is used. You can modify the order easily 
enough in
the project properties.

I suppose this will become unnecessary whenever JUnit updates the version of 
Matcher
it embeds to have the describeMismatch() method, thus dropping support for older
versions of Hamcrest.

Original comment by nickhowes on 23 Feb 2010 at 4:57

GoogleCodeExporter commented 9 years ago
You should the junit-dep jar which does not include Hamcrest. (it's a bit 
confusing since perhaps it should be 
junit-no-dep)

Original comment by smgfree...@gmail.com on 23 Feb 2010 at 7:18