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

NullPointerException is thrown by mocked instance in Expectations in JMockit 1.12 #89

Closed
Varun200864 opened this Issue Oct 16, 2014 · 5 comments

Comments

2 participants
@Varun200864

Varun200864 commented Oct 16, 2014

Mocked instance throws NullPointerException in Expectations() with JMockit 1.12 but it runs successfully with JMockit 1.11.

@rliesenfeld

This comment has been minimized.

Show comment
Hide comment
@rliesenfeld

rliesenfeld Oct 16, 2014

Member

I will need an example test; otherwise I've no idea how to produce the NPE.

Member

rliesenfeld commented Oct 16, 2014

I will need an example test; otherwise I've no idea how to produce the NPE.

@Varun200864

This comment has been minimized.

Show comment
Hide comment
@Varun200864

Varun200864 Oct 16, 2014

public class TestClass
{
@Mocked ClassToMock mockedInstance;
@test
public void testMethodToTest()
{
ClassToTest classToTestInstance = new ClassToTest();
Object someObject = new Object();
new Expectations()
{
mockedInstance.methodToMock();//NullPointerException
returns(someObject);
}
}
}

Some test cases pass but some test cases throw exception.

Varun200864 commented Oct 16, 2014

public class TestClass
{
@Mocked ClassToMock mockedInstance;
@test
public void testMethodToTest()
{
ClassToTest classToTestInstance = new ClassToTest();
Object someObject = new Object();
new Expectations()
{
mockedInstance.methodToMock();//NullPointerException
returns(someObject);
}
}
}

Some test cases pass but some test cases throw exception.

@rliesenfeld

This comment has been minimized.

Show comment
Hide comment
@rliesenfeld

rliesenfeld Oct 16, 2014

Member

Running the example test, there is no NullPointerException for me...

Member

rliesenfeld commented Oct 16, 2014

Running the example test, there is no NullPointerException for me...

@Varun200864

This comment has been minimized.

Show comment
Hide comment
@Varun200864

Varun200864 Oct 17, 2014

Yes. But in my other code there is NullPointerException. That is proprietary code. So I can not post that code.
Here is the stack trace
java.lang.NullPointerException
at mockit.internal.state.MockedTypeCascade.createNewCascadedInstanceOrUseNonCascadedOneIfAvailable(MockedTypeCascade.java:208)
at mockit.internal.state.MockedTypeCascade.getCascadedInstance(MockedTypeCascade.java:161)
at mockit.internal.state.MockedTypeCascade.getMock(MockedTypeCascade.java:66)
at mockit.internal.expectations.invocation.ExpectedInvocation.produceCascadedInstanceIfApplicable(ExpectedInvocation.java:392)
at mockit.internal.expectations.invocation.ExpectedInvocation.getDefaultValueForReturnType(ExpectedInvocation.java:380)
at mockit.internal.expectations.RecordPhase.handleInvocation(RecordPhase.java:72)
at mockit.internal.expectations.RecordAndReplayExecution.recordOrReplay(RecordAndReplayExecution.java:220)
at ClassToMock
at ClassToTest
at TestClass
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:483)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at mockit.integration.junit4.internal.JUnit4TestRunnerDecorator.executeTestMethod(JUnit4TestRunnerDecorator.java:142)
at mockit.integration.junit4.internal.JUnit4TestRunnerDecorator.invokeExplosively(JUnit4TestRunnerDecorator.java:71)
at mockit.integration.junit4.internal.MockFrameworkMethod.invokeExplosively(MockFrameworkMethod.java:40)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java)
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.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
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)

Varun200864 commented Oct 17, 2014

Yes. But in my other code there is NullPointerException. That is proprietary code. So I can not post that code.
Here is the stack trace
java.lang.NullPointerException
at mockit.internal.state.MockedTypeCascade.createNewCascadedInstanceOrUseNonCascadedOneIfAvailable(MockedTypeCascade.java:208)
at mockit.internal.state.MockedTypeCascade.getCascadedInstance(MockedTypeCascade.java:161)
at mockit.internal.state.MockedTypeCascade.getMock(MockedTypeCascade.java:66)
at mockit.internal.expectations.invocation.ExpectedInvocation.produceCascadedInstanceIfApplicable(ExpectedInvocation.java:392)
at mockit.internal.expectations.invocation.ExpectedInvocation.getDefaultValueForReturnType(ExpectedInvocation.java:380)
at mockit.internal.expectations.RecordPhase.handleInvocation(RecordPhase.java:72)
at mockit.internal.expectations.RecordAndReplayExecution.recordOrReplay(RecordAndReplayExecution.java:220)
at ClassToMock
at ClassToTest
at TestClass
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:483)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at mockit.integration.junit4.internal.JUnit4TestRunnerDecorator.executeTestMethod(JUnit4TestRunnerDecorator.java:142)
at mockit.integration.junit4.internal.JUnit4TestRunnerDecorator.invokeExplosively(JUnit4TestRunnerDecorator.java:71)
at mockit.integration.junit4.internal.MockFrameworkMethod.invokeExplosively(MockFrameworkMethod.java:40)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java)
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.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
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)

@Varun200864

This comment has been minimized.

Show comment
Hide comment
@Varun200864

Varun200864 Oct 20, 2014

Thank you. This issue is resolved. But some other test cases started failing when I downloaded this 577b334 code. Cases which has result = new MyException() in Expectations() are not working properly. Method which I mocked to throw MyException is not throwing Exception.

Varun200864 commented Oct 20, 2014

Thank you. This issue is resolved. But some other test cases started failing when I downloaded this 577b334 code. Cases which has result = new MyException() in Expectations() are not working properly. Method which I mocked to throw MyException is not throwing Exception.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment