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

Partial mocking of global MockUps causes NullPointerException #62

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

Comments

@borisbrodski
Copy link

@borisbrodski borisbrodski commented Sep 12, 2014

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

@rliesenfeld rliesenfeld commented Sep 12, 2014

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

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