use of org.mockito.stubbing.Answer in project hazelcast by hazelcast.
the class HazelcastInstanceFactoryTest method test_NewInstance_terminateInstance_afterNodeStart.
@Test(expected = IllegalStateException.class)
public void test_NewInstance_terminateInstance_afterNodeStart() throws Exception {
NodeContext context = new TestNodeContext() {
@Override
public NodeExtension createNodeExtension(final Node node) {
NodeExtension nodeExtension = super.createNodeExtension(node);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
node.hazelcastInstance.shutdown();
return null;
}
}).when(nodeExtension).afterStart();
return nodeExtension;
}
};
Config config = new Config();
config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
hazelcastInstance = HazelcastInstanceFactory.newHazelcastInstance(config, randomString(), context);
}
use of org.mockito.stubbing.Answer in project fresco by facebook.
the class DrawableTestUtils method stubSetAlpha.
/**
* Stubs setAlpha method.
* @param drawable to stub method of
*/
public static void stubSetAlpha(final Drawable drawable) {
final AtomicInteger atomicInteger = new AtomicInteger(255);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
Integer alpha = (Integer) invocation.getArguments()[0];
drawable.invalidateSelf();
atomicInteger.set(alpha);
return null;
}
}).when(drawable).setAlpha(anyInt());
}
use of org.mockito.stubbing.Answer in project fresco by facebook.
the class DrawableTestUtils method stubGetAndSetBounds.
/**
* Stubs setBounds and getBounds methods.
* @param drawable drawable to stub methods of
*/
public static void stubGetAndSetBounds(Drawable drawable) {
final Rect rect = new Rect();
when(drawable.getBounds()).thenReturn(rect);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
rect.set((Integer) invocation.getArguments()[0], (Integer) invocation.getArguments()[1], (Integer) invocation.getArguments()[2], (Integer) invocation.getArguments()[3]);
return null;
}
}).when(drawable).setBounds(anyInt(), anyInt(), anyInt(), anyInt());
}
use of org.mockito.stubbing.Answer in project fresco by facebook.
the class DraweeMocks method stubGetAndSetHierarchy.
/**
* Stubs setHierarchy and getHierarchy methods.
* @param controller controller to stub methods of
*/
public static void stubGetAndSetHierarchy(DraweeController controller) {
final DraweeHierarchy[] dhHolder = new DraweeHierarchy[1];
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
return dhHolder[0];
}
}).when(controller).getHierarchy();
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
return dhHolder[0] = (DraweeHierarchy) invocation.getArguments()[0];
}
}).when(controller).setHierarchy(any(DraweeHierarchy.class));
}
use of org.mockito.stubbing.Answer in project fresco by facebook.
the class DraweeMocks method stubGetAndSetContentDescription.
/**
* Stubs setContentDescription and getContentDescription methods.
* @param controller controller to stub methods of
*/
public static void stubGetAndSetContentDescription(DraweeController controller) {
final String[] contentDescriptionHolder = new String[1];
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
return contentDescriptionHolder[0];
}
}).when(controller).getContentDescription();
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
return contentDescriptionHolder[0] = (String) invocation.getArguments()[0];
}
}).when(controller).setContentDescription(any(String.class));
}
Aggregations