0

I encounter a problem during unit testing with EasyMock. When trying to create a mock object, the following Exception is thrown:

java.lang.IllegalArgumentException: class  ...UnitOfWork$$EnhancerByCGLIB$$3561f3ca is not an enhanced class
    at net.sf.cglib.proxy.Enhancer.setCallbacksHelper(Enhancer.java:621)
    at net.sf.cglib.proxy.Enhancer.setThreadCallbacks(Enhancer.java:612)
    at net.sf.cglib.proxy.Enhancer.registerCallbacks(Enhancer.java:581)
    at org.easymock.internal.ClassProxyFactory.createProxy(ClassProxyFactory.java:194)
    at org.easymock.internal.MocksControl.createMock(MocksControl.java:60)
    at org.easymock.EasyMock.createMock(EasyMock.java:104)
    at testplugin.Test.testMethod(Test.java:65)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.internal.runners.s

What makes a class enhanced? And what is the Enhancer doing anyways (I don't know what net.sf.cglib.proxypackage is about) And why is it not working for this class, but for another mock object directly created before this object?

Mock1 mock1 = EasyMock.createMock(Mock1.class);
UnitOfWork mockUow = EasyMock.createMock(UnitOfWork.class); // Exception Happening here

Used versions are easymock-3.0.jar and cglib-nodep-2.2.jar. UnitOfWork is not a final class. The only thing that might be different are transient fields. Sadly I can't provide the code or recreate the Exception with another class.

BloodyMettle
  • 104
  • 8

1 Answers1

0

This is extremely strange. Cglib is used by EasyMock to create mocks under the hood. Which version of EasyMock and Cglib are you using?

Normally, when cglib creates a class, it adds some specific static fields to it. In your case, these fields were not found. But I can't think why the fields are not there in your case. Is the UnitOfWork class final?

Can you provide the UnitOfWork code? Or a subset reproducing the issue?

Henri
  • 5,551
  • 1
  • 22
  • 29
  • Thanks for the answer. I have edited the question to give the information you asked for. – BloodyMettle Jul 27 '17 at 15:39
  • The first step I would suggest is to update to EasyMock 3.4 and see if it works. Then, without a way to reproduce, it will be hard to say. – Henri Jul 28 '17 at 17:08