Menu

#34 CodeGenerationException mocking a class in Eclipse plugin

EasyMock_2.5.2
closed
5
2012-10-05
2010-04-29
sprynter200
No

When attempting to mock a class in an Eclipse test plugin (a plugin that tests another plugin), a CodeGenerationException is generated when running under OSGi classloaders (the Run As | JUnit Plugin Test).

This is similar to the bug ID: 2759024, but not quite the same.

There are long descriptions of how JMock solved it: http://jira.codehaus.org/browse/JMOCK-124
and Mockito solved the same issue: http://code.google.com/p/mockito/issues/detail?id=11&can=1

The last comment in the Mockito issue ( http://code.google.com/p/mockito/issues/detail?id=11&can=1#c29 ) looks to be the key to a solution. All about taking care which classloader cglib uses,

Discussion

  • sprynter200

    sprynter200 - 2010-04-29

    Stacktrace

     
  • sprynter200

    sprynter200 - 2010-04-30

    The revisions that fixed the problem for others:

    • in Mockito [http://code.google.com/p/mockito/source/detail?r=660]

    • in JMock [http://svn.jmock.codehaus.org/changelog/jmock?cs=1263]

     
  • sprynter200

    sprynter200 - 2010-04-30

    I've attached a patch for 2.5.2 that fixes the issue.

    It's only been manually tested - it's tough to automate the test without all the build framework (we use Maven + Tycho to do Eclipse plugin builds).

     
  • Henri Tremblay

    Henri Tremblay - 2010-05-01

    Thanks a lot for the information. I was able to reproduce the problem. I'll have a look at the patch for Mockito and JMock

     
  • Henri Tremblay

    Henri Tremblay - 2010-05-02

    Thanks again for you're really precise reporting. I've applied your patch and it seems to work.

    One question, why is a naming policy starting the package name by "codegen." required?

     
  • Henri Tremblay

    Henri Tremblay - 2010-05-02

    Hum... that's weird, the fix is working for Eclipse but is making the easymock-integration OSGi tests failing.

     
  • Henri Tremblay

    Henri Tremblay - 2010-05-02

    Ok. I get it. The policy is only to put the class out of the signed package. That makes my test pass.

    For now I don't have the line setting the class loader. I'll have to read more but putting this line makes my OSGi tests fail and I can't see yet why using the class to mock classloader isn't ok (maybe it's forbidden?)

     
  • Henri Tremblay

    Henri Tremblay - 2010-05-02

    Progress are being made. I was able to reproduce the failure when running plugin tests. The fix works.

    Now the only thing left is to understand why my OSGi tests are now failing with the fix

     
  • Henri Tremblay

    Henri Tremblay - 2010-05-02

    I feel like I'm thinking aloud by commenting all the time but I got it now. There are two things:

    1- If the test class is in a classloader on top of EasyMock classloader, EasyMock classloader won't see it and so the Mockito fix doesn't work in that case
    2- If the mock class in under, the fix works

    I just need to handle both cases. Let's see what I can do.

     

Log in to post a comment.