William Burns created ISPN-3671:
-----------------------------------
Summary: Evaluate replacement of Mockito usage of spy with Forwarding mocks
instead
Key: ISPN-3671
URL:
https://issues.jboss.org/browse/ISPN-3671
Project: Infinispan
Issue Type: Bug
Components: Test Suite
Affects Versions: 6.0.0.CR1
Reporter: William Burns
Assignee: Mircea Markus
Usage of Mockito spy actually creates a new instance (with current state) of the provided
delegate. This can cause issues if there are already threads created that modify the
provided delegate state as it won't affect the new object.
It would be safer to first use a forwarding mock instead that doesn't create another
instance as this has caused issues with some tests regarding state transfer.
Here is an example of how the forwarding mock can be used.
{code}
StateConsumer sc = TestingUtil.extractComponent(cache, StateConsumer.class);
final Answer<Object> forwardedAnswer = AdditionalAnswers.delegatesTo(sc);
StateConsumer mockConsumer = mock(StateConsumer.class,
withSettings().defaultAnswer(forwardedAnswer));
TestingUtil.replaceComponent(cache, StateConsumer.class, mockConsumer, true);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
// Do something
return forwardedAnswer.answer(invocation);
}
}).when(mockConsumer).applyState(any(Address.class), anyInt(), anyCollection());
{code}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see:
http://www.atlassian.com/software/jira