Java Mailing List Archive

http://www.gg3721.com/

Home » user.jmock »

[jmock-user] JMock 2.x + Maven 2.x problem: mocked class method executes, incorrect expectations listed

Richard Barnett

2008-02-12

Replies: Find Java Web Hosting

Author LoginPost Reply
I've managed to write a unit test using JMock which works when run from
Eclipse but fails in a very strange way when run from Maven. Other unit
tests written in the same manner work fine.

In summary:
- I create mock instances of classes Service & Session
- I create an expection on Service.sendXxx(Session, ...)
- Service.sendXxx is a 1-line method which calls
Service.sendMessage(Session, ...)
- Service.sendMessage(Session, ...) is a 1-line method which calls
Session.sendDataMessage(...)
- My test fails due to unexpected invocation of Session.sendDataMessage
- The list of expectations shows that Service.sendDataMessage was
expected, though this method doesn't exist
- Expected parameters to Service.sendDataMessage are exactly those with
which Session.sendDataMessage was called
- Stack trace shows Service.sendXxx calling Service.sendMessage calling
a cglib-enhanced Session.sendDataMessage

I'm using JUnit 4.3.1, JMock 2.2.0, Maven 2.0.5, Java 1.5.0_12, Eclipse
3.3.1.1/Europa. The classpath is big and I haven't yet tried to
reproduce this in a simpler project -- I thought I'd send this out to
see whether it rang any bells, and follow up with a simpler repro case.

The symptoms almost suggest to me that some kind of inlining is going
on.

Maven & Eclipse classpaths have almost identical content but very
different order.

I've tried:
- Upgrading to JMock 2.4.0
- Removing JMock 1.2 & its cglib dependency
- Altering the Maven pom to get the classpath ordering more similar to
Eclipse:
 - Excluding JMock 2's cglib-nodep dependency (cglib occurs first on
the Eclipse classpath)

cglib is 2.1_3, asm 1.5.3 - according to Maven, both are pulled in as
transitive dependencies of Hibernate 3.2.

Any ideas gratefully received. I can post code fragments & stack traces
if required.

Is there any logging I can enable in JMock or cglib that might help?

Thanks

-- Richard


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

  http://xircles.codehaus.org/manage_email


©2008 gg3721.com - Jax Systems, LLC, U.S.A.