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

Partial mocking of global MockUps causes NullPointerException #62

Closed
borisbrodski opened this issue Sep 12, 2014 · 1 comment
Closed
Assignees
Labels

Comments

@borisbrodski
Copy link

Reproduction steps:

Create following files:
  • Tool.java
public class Tool {
    public void doIt() {
    }
}
  • ToolMock.java:
import mockit.Invocation;
import mockit.Mock;
import mockit.MockUp;

public class ToolMock extends MockUp<Tool>{
    @Mock
    public void doIt(Invocation e){
    }
}
  • jmockit.properties:
mocks=test.ToolMock
  • Test1.java:
import mockit.NonStrictExpectations;

import org.junit.Test;

public class Test1 {
    @Test
    public void test1() {
        new NonStrictExpectations(Tool.class) {{
        }};
    }

    @Test
    public void test2() {
        new Tool().doIt();
    }
}
Run Test1.

Result:

  • Test1.test1 OK
  • Test1.test2 FAILS. Exception:
java.lang.NullPointerException
    at test.Tool.doIt(Tool.java)
    at test.Test1.test2(Test1.java:16)

Also all consequent tests getting the same NullPointerException, if Tool class get used.

@rliesenfeld rliesenfeld self-assigned this Sep 12, 2014
@rliesenfeld
Copy link
Member

Well spotted, thanks! It will be fixed for release 1.12.

Col-E pushed a commit to Col-E/jmockit1 that referenced this issue Oct 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants