Server side mock of Work Items with Mockito
I want to write JUnit Tests for my Follow-Up Action. Therefor I want to mock all necessary Artifacts with Mockito.
But if I try to Mock the class IWorkItem.class
IWorkItem workItem = mock(IWorkItem.class);
I receive a NullPointerException. Did somebody know how to mock in a server plugin the work item with Mockito?
Thanks and regards
Martin
java.lang.ExceptionInInitializerError
at java.lang.J9VMInternals.initialize(J9VMInternals.java:259)
at com.ibm.team.workitem.common.internal.util.AuditablesHelper.<clinit>(AuditablesHelper.java:40)
at java.lang.J9VMInternals.initializeImpl(Native Method)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:237)
at com.ibm.team.workitem.common.model.IWorkItem.<clinit>(IWorkItem.java:130)
at java.lang.J9VMInternals.initializeImpl(Native Method)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:237)
at java.lang.Class.forNameImpl(Native Method)
at java.lang.Class.forName(Class.java:186)
at com.ibm.team.workitem.common.model.IWorkItem$$EnhancerByMockitoWithCGLIB$$75f09a5d.CGLIB$STATICHOOK5(<generated>)
at com.ibm.team.workitem.common.model.IWorkItem$$EnhancerByMockitoWithCGLIB$$75f09a5d.<clinit>(<generated>)
at java.lang.J9VMInternals.initializeImpl(Native Method)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:237)
at java.lang.reflect.Constructor.newInstance(Constructor.java:541)
at org.objenesis.instantiator.sun.SunReflectionFactoryInstantiator.newInstance(SunReflectionFactoryInstantiator.java:40)
at org.objenesis.ObjenesisBase.newInstance(ObjenesisBase.java:59)
at org.mockito.internal.creation.jmock.ClassImposterizer.createProxy(ClassImposterizer.java:128)
at org.mockito.internal.creation.jmock.ClassImposterizer.imposterise(ClassImposterizer.java:63)
at org.mockito.internal.creation.jmock.ClassImposterizer.imposterise(ClassImposterizer.java:56)
at org.mockito.internal.creation.CglibMockMaker.createMock(CglibMockMaker.java:23)
at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:26)
at org.mockito.internal.MockitoCore.mock(MockitoCore.java:51)
at org.mockito.Mockito.mock(Mockito.java:1243)
at org.mockito.Mockito.mock(Mockito.java:1120)
at com.rus.jazz.extension.service.mailnotification.MyFollowUpActionTest.setup(MyFollowUpActionTest.java:62)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.lang.reflect.Method.invoke(Method.java:619)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.NullPointerException
at com.ibm.team.workitem.common.internal.util.Utils.<clinit>(Utils.java:90)
at java.lang.J9VMInternals.initializeImpl(Native Method)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:237)
... 32 more
|
4 answers
Hi Martin,
I do not know the exact reason to this but mockito is not completely aware of RTC Nature. I also faced this problem but after digging a bit I figured out that for some of the RTC objects mocking doesn't work without starting the team platform. So add beforeTeamPlatform.startup();
and then it starts working as expected.
|
What is line 62 of your test case? It looks like the Utils class is missing. Is the com.ibm.team.workitem.common in the features for the launcher for your test? Is it imported in the manifest.mf for the test package?
Here's a sample mock of a work item:
private IWorkItem aWorkItem(Identifier<IState> state, Identifier<IResolution> resolution, IApprovalDescriptor ... approvalDescriptors) throws Exception {
Here is the manifest for a sample service test package... you may not need all of this...
Manifest-Version: 1.0
Lawrence Smith [IBM]
|
Your answer
Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.