Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class Mocking with OSGi does not work. #190

Closed
Jungster124 opened this issue Jan 4, 2017 · 2 comments
Closed

Class Mocking with OSGi does not work. #190

Jungster124 opened this issue Jan 4, 2017 · 2 comments
Assignees
Labels
Milestone

Comments

@Jungster124
Copy link
Contributor

Jungster124 commented Jan 4, 2017

Mocking a class (not interface) from another Bundle leads to errors

See stacktrace (NullPointerException occured after EasyMock.reset())and repro.zip for two eclipse bundles for reproduction:
java.lang.NullPointerException
at org.easymock.internal.ClassProxyFactory$MockMethodInterceptor.access$000(ClassProxyFactory.java:42)
at org.easymock.internal.ClassProxyFactory.getInvocationHandler(ClassProxyFactory.java:277)
at org.easymock.internal.MocksControl.getControl(MocksControl.java:156)
at org.easymock.EasyMock.getControl(EasyMock.java:2037)
at org.easymock.EasyMock.reset(EasyMock.java:1952)
at dummy.test.Class1.testBlubb(BockwurstTest.java:19)
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 junit.framework.TestCase.runTest(TestCase.java:176)
at junit.framework.TestCase.runBare(TestCase.java:141)
at junit.framework.TestResult$1.protect(TestResult.java:122)
at junit.framework.TestResult.runProtected(TestResult.java:142)
at junit.framework.TestResult.run(TestResult.java:125)
at junit.framework.TestCase.run(TestCase.java:129)
at junit.framework.TestSuite.runTest(TestSuite.java:252)
at junit.framework.TestSuite.run(TestSuite.java:247)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:86)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunner.main(RemotePluginTestRunner.java:66)
at org.eclipse.pde.internal.junit.runtime.CoreTestApplication.run(CoreTestApplication.java:24)
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.eclipse.equinox.internal.app.EclipseAppContainer.callMethodWithException(EclipseAppContainer.java:587)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:198)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:388)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:243)
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.eclipse.equinox.launcher.Main.invokeFramework(Main.java:673)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:610)
at org.eclipse.equinox.launcher.Main.run(Main.java:1519)
at org.eclipse.equinox.launcher.Main.main(Main.java:1492)

An EasyMock.expect() on a mocked Class from another Bundle leads to an IllegalStateException
java.lang.IllegalStateException: no last call on a mock available
at org.easymock.EasyMock.getControlForLastCall(EasyMock.java:466)
at org.easymock.EasyMock.expect(EasyMock.java:444)

repro.zip

Jungster124 added a commit to Jungster124/easymock that referenced this issue Jan 4, 2017
The Callback of mocks has to be explicit if the mocked class is located
in an other bundle. The callback, registered at the Enhancer seems to be
useless in this case.
Jungster124 added a commit to Jungster124/easymock that referenced this issue Jan 25, 2017
The Callback of mocks has to be explicit if the mocked class is located
in an other bundle. The callback, registered at the Enhancer seems to be
useless in this case.
Jungster124 added a commit to Jungster124/easymock that referenced this issue Jan 25, 2017
The Callback of mocks has to be explicit if the mocked class is located
in an other bundle. The callback, registered at the Enhancer seems to be
useless in this case.
@henri-tremblay henri-tremblay self-assigned this Sep 12, 2017
@henri-tremblay henri-tremblay added this to the 3.5 milestone Sep 12, 2017
@vijayparashar12
Copy link

I still see the same exception though I am on version 3.5

java.lang.NullPointerException
	at org.easymock.internal.MocksControl.getProxyFactory(MocksControl.java:132)
	at org.easymock.internal.MocksControl.getControl(MocksControl.java:161)
	at org.easymock.EasyMock.getControl(EasyMock.java:2114)
	at org.easymock.EasyMock.verify(EasyMock.java:2041)
	at de.zalando.laas.service.domain.ProcessStatusUpdateJobServiceTest.markProcessStatusForUpdateAsJobWithNonNullPKAddsJobEntry(ProcessStatusUpdateJobServiceTest.java:45)
	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.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	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.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

?

@henri-tremblay
Copy link
Contributor

@vijayparashar12 This is not exactly the same error. In your case I would guess you passed null for mocking. If it's not the case, I would like a test case featuring the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants