One of static method I am using, it does two things. It returns some data, but it also modifies the argument object that is passed to it. This updated argument object is then used later in code.
I am using PowerMock to mock the return behavior.
For defining the second part - updating the input argument, I am defining doAnswer method but it's not working. The method that I'm trying to test looks like this.
public void login() throws ConnectionException, AsyncApiException {
ConnectorConfig partnerConfig = new ConnectorConfig();
//This call sets the value in one member variable 'serviceEndPoint in ParterConfig which is accessed later in this method only.
partnerConnection = Connector.newConnection(partnerConfig);
//partnerConfig.getServiceEndpoint is called.
PowerMockito.mockStatic(Connector.class);
when(Connector.newConnection(Mockito.any(ConnectorConfig.class))).thenReturn(partnerConnection);
PowerMockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) {
ConnectorConfig config = (ConnectorConfig) invocation.getArguments()[0];
config.setServiceEndpoint("service end point");
return null;
}
}).when(Connector.newConnection(Mockito.any(ConnectorConfig.class)));
}
but above throws error saying 'Unfinished stubbing detected here'.
Connector
is a third party class so I don't have control over its behavior.
Any suggestions, what could be going wrong?