use of org.mockito.invocation.InvocationOnMock in project gocd by gocd.
the class GarageServiceTest method shouldFailWhenGitExecutionFailsWithANonZeroReturnCode.
@Test
public void shouldFailWhenGitExecutionFailsWithANonZeroReturnCode() throws Exception {
CommandLine firstCommand = mock(CommandLine.class);
doReturn(firstCommand).when(firstCommand).withArg(anyString());
doReturn(firstCommand).when(firstCommand).withWorkingDir(any(File.class));
when(firstCommand.run(any(InMemoryStreamConsumer.class), eq(GarageService.PROCESS_TAG))).thenReturn(0);
CommandLine secondCommand = mock(CommandLine.class);
doReturn(secondCommand).when(secondCommand).withArg(anyString());
doReturn(secondCommand).when(secondCommand).withWorkingDir(any(File.class));
when(secondCommand.run(any(InMemoryStreamConsumer.class), eq(GarageService.PROCESS_TAG))).thenReturn(129);
final List<CommandLine> commands = new LinkedList<>();
commands.add(firstCommand);
commands.add(secondCommand);
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
GarageService spy = spy(garageService);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
CommandLine remove = commands.get(0);
commands.remove(remove);
return remove;
}
}).when(spy).getGit();
spy.gc(result);
assertThat(result.isSuccessful(), is(false));
assertThat(result.hasMessage(), is(true));
verify(spy, times(2)).getGit();
verify(firstCommand).run(any(InMemoryStreamConsumer.class), eq(GarageService.PROCESS_TAG));
verify(secondCommand).run(any(InMemoryStreamConsumer.class), eq(GarageService.PROCESS_TAG));
}
use of org.mockito.invocation.InvocationOnMock 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.invocation.InvocationOnMock 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.invocation.InvocationOnMock 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.invocation.InvocationOnMock 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