Java Mailing List Archive

http://www.gg3721.com/

Home » user.jmock »

[jmock-user] mocking concrete classes with final toString method

Haroon Rafique

2008-07-16

Replies: Find Java Web Hosting

Author LoginPost Reply
Hi there,

I'm using jmock 2.5.0RC1. When trying to mock concrete classes with final
toString methods, I'm getting:

java.lang.IllegalArgumentException:
ClassNameHere has a final toString method

Looking through jira and the changelogs, this is a direct result of this
bug:
 http://jira.codehaus.org/browse/JMOCK-150
and was implemented in changeset:
 http://fisheye.codehaus.org/changelog/jmock?cs=1152

Is there a middle ground somewhere? I'm working with 3rd party classes
where I have no control over their class structure. JMOCK-150 seems like
squashing a bug with a hammer.

The original bug reporter mentioned that:

 * an un-expected exception during the assertIsSatisfied() check
      (got the exception when tring to describe the mocked class using
      the final toString() which uses other methods from the original
      class)

Could the code in Mockery.assertIsSatisfied() look for the fact that a
ClassImposteriser is being used and to bypass the toString method in case
it is final? pseudo-code follows:

new ExpectationError("not all expectations were satisfied",
 !toStringMethodIsFinalAndUsingClassImposteriser(dispatcher) ?
 dispatcher :
 dispatcher.getClass().getName()
);

Cheers,
--
Haroon Rafique
<haroon.rafique@(protected)>


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

  http://xircles.codehaus.org/manage_email


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