Note that there are some explanatory texts on larger screens.

plurals
  1. POJMockit: Null Pointer Error When Mock Object Should Be Instatiated?
    primarykey
    data
    text
    <p>My understanding of <a href="https://code.google.com/p/jmockit/" rel="nofollow">JMockit</a> is that it will replace all instances of a mocked object with a mock (unless you tell it otherwise).</p> <p>Hence I am perplexed to be getting a <a href="http://download.oracle.com/javase/6/docs/api/index.html?java/lang/NullPointerException.html" rel="nofollow">NPE</a> after instantiating an object I'm attempting to mock.</p> <p>The purpose of the test is not to investigate the object causing the NPE, but I do need to mock it in order to carry out the test as it carrys out some database actions to validate some input.</p> <p>My code under test is like this (not copy pasta, as it's work code, but should highlight the issue nonetheless):</p> <pre><code>public class ClassToTest{ public execute(){ MyDependency myDep = getDependency(); myDep.doSomething(); //I get a NPE here, implying getDependency returned null } protected MyDependency getDependency(){ return new MyDependency("an Arg", "another Arg"); } } </code></pre> <p>My Test method:</p> <pre><code>@Test public void testCreateHorseDogMeetingByCodeDataProviderTruncated() throws IllegalArgumentException, SQLException, IllegalCountryLocationCombo, MEPException { // Arrange ClassToTest myClass = new ClassToTest(); new NonStrictExpectations() { MyDependency mockDep; { //Set up my expectations, not related to MyDependency } }; // Act myClass.execute(); // Assert new Verifications() { { //some verification stuff } }; } </code></pre> <p><strong>Can anyone help me fix this NPE issue so I can finish my test?</strong></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload