You are mocking NetworkClient
's constructor, which also means that the instance variable are not instantiated. You need to instantiate the nrh
variable. For example:
new MockUp<NetworkClient>() {
@Mock
public void $init(Invocation inv){
NetworkClient client = inv.getInvokedInstance();
Deencapsulation.setField(client, "nrh", new ServerRequestHandler());
}
};
Now you probably also want to mock the ServerRequestHandler
class, in which case you can simply create a new MockUp
:
new MockUp<NetworkClient>() {
};
new MockUp<ServerRequestHandler>() {
};
Note: I have not used jmockit in a while so it might not work but probably worth trying.