[infinispan-issues] [JBoss JIRA] (ISPN-3671) Evaluate replacement of Mockito usage of spy with Forwarding mocks instead
Dan Berindei (JIRA)
issues at jboss.org
Mon Feb 17 09:47:48 EST 2014
[ https://issues.jboss.org/browse/ISPN-3671?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Dan Berindei updated ISPN-3671:
-------------------------------
Assignee: William Burns (was: Mircea Markus)
> 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 - Core
> Affects Versions: 6.0.0.CR1
> Reporter: William Burns
> Assignee: William Burns
>
> 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
More information about the infinispan-issues
mailing list