Home > Enterprise >  Mockito Junit : ExceptionInIntialize and NullPointer Error on struts DispatchAction.java when runnin
Mockito Junit : ExceptionInIntialize and NullPointer Error on struts DispatchAction.java when runnin

Time:08-17

I have a class ClassA which is extending DispatchAction class from org.apache.struts.actions.DispatchAction, I have written JUnit code coverage test for ClassA but whenever I try to run the test case I keep getting these error but if I remove the extends DispatchAction from ClassA the test runs normally without any error but then obviously my application won't work ClassA

public class ClassA extends DispatchAction {
//some methods and other code
}

TestClassA

@RunWith(Junit4.class)
public class TestClassA {
@InjectMocks
ClassA objA;
/* mock some objects here */
@Before
public void setUp()
{
MockitoAnnotations.openMocks(this);
}
@Test
public void methodToTest()
{
//Coverage code
objA.methodA();
}
}

Here is the stack trace I get when I run this test case (when I keep "extends DispatchAction" in class ClassA )

java.lang.ExceptionInInitializerError at 
java.lang.J9VMInternals.ensureError(J9VMInternals.java:148) at 
java.lang.J9VMInternals.recordInitializationFailure(J9VMInternals.java:137) at 
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at 
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:83) at 
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:57) at 
java.lang.reflect.Constructor.newInstance(Constructor.java:437) at 
org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:217) at 
org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:266) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at 
org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:263) 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.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41) at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541) at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463) at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209) 

Caused by: java.lang.NullPointerException at 
org.apache.struts.util.MessageResources.getMessageResources(MessageResources.java:577) at 
org.apache.struts.actions.DispatchAction.<clinit>(DispatchAction.java:153) ... 22 more

Now if I remove the "extends DispatchAction" from class ClassA it will run and cover the intended lines in the test case without any problems but my application won't work as intended.

I tried searching on how to resolve all those errors but I cannot find anything that might help.

CodePudding user response:

Resolved the issue by adding the latest j2ee jar which was missing earlier.

  • Related