use of org.mockito.invocation.InvocationOnMock in project spring-security by spring-projects.
the class UsernamePasswordAuthenticationFilterTests method createAuthenticationManager.
private AuthenticationManager createAuthenticationManager() {
AuthenticationManager am = mock(AuthenticationManager.class);
when(am.authenticate(any(Authentication.class))).thenAnswer(new Answer<Authentication>() {
public Authentication answer(InvocationOnMock invocation) throws Throwable {
return (Authentication) invocation.getArguments()[0];
}
});
return am;
}
use of org.mockito.invocation.InvocationOnMock in project ExoPlayer by google.
the class CronetDataSourceTest method testCallbackFromPreviousRequest.
@Test
public void testCallbackFromPreviousRequest() throws HttpDataSourceException {
mockResponseStartSuccess();
dataSourceUnderTest.open(testDataSpec);
dataSourceUnderTest.close();
// Prepare a mock UrlRequest to be used in the second open() call.
final UrlRequest mockUrlRequest2 = mock(UrlRequest.class);
when(mockUrlRequestBuilder.build()).thenReturn(mockUrlRequest2);
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
// Invoke the callback for the previous request.
dataSourceUnderTest.onFailed(mockUrlRequest, testUrlResponseInfo, mockNetworkException);
dataSourceUnderTest.onResponseStarted(mockUrlRequest2, testUrlResponseInfo);
return null;
}
}).when(mockUrlRequest2).start();
dataSourceUnderTest.open(testDataSpec);
}
use of org.mockito.invocation.InvocationOnMock in project gocd by gocd.
the class DefaultPluginManagerTest method shouldNotFindPluginIsOfGivenExtensionWhenReferenceNotFoundAndExtensionDoNotMatch.
@Test
public void shouldNotFindPluginIsOfGivenExtensionWhenReferenceNotFoundAndExtensionDoNotMatch() throws Exception {
final String pluginThatDoesNotImplement = "plugin-that-does-not-implement";
GoPluginIdentifier pluginIdentifier = new GoPluginIdentifier("another-extension-type", asList("1.0"));
final GoPlugin goPlugin = mock(GoPlugin.class);
final GoPluginDescriptor descriptor = mock(GoPluginDescriptor.class);
when(goPluginOSGiFramework.hasReferenceFor(GoPlugin.class, pluginThatDoesNotImplement)).thenReturn(true);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
ActionWithReturn<GoPlugin, GoPluginApiResponse> action = (ActionWithReturn<GoPlugin, GoPluginApiResponse>) invocationOnMock.getArguments()[2];
return action.execute(goPlugin, descriptor);
}
}).when(goPluginOSGiFramework).doOn(eq(GoPlugin.class), eq(pluginThatDoesNotImplement), any(ActionWithReturn.class));
when(goPlugin.pluginIdentifier()).thenReturn(pluginIdentifier);
DefaultPluginManager pluginManager = new DefaultPluginManager(monitor, registry, goPluginOSGiFramework, jarChangeListener, pluginRequestProcessorRegistry, pluginWriter, pluginValidator, systemEnvironment, pluginsZipUpdater, pluginsListListener);
assertFalse(pluginManager.isPluginOfType("extension-type", pluginThatDoesNotImplement));
verify(goPluginOSGiFramework).doOn(eq(GoPlugin.class), eq(pluginThatDoesNotImplement), any(ActionWithReturn.class));
}
use of org.mockito.invocation.InvocationOnMock in project stetho by facebook.
the class StethoInterceptorTest method hookAlmostRealInterpretResponseStream.
/**
* Provide a suitably "real" implementation of
* {@link NetworkEventReporter#interpretResponseStream} for our mock to test that
* events are properly delegated.
*/
private static ByteArrayOutputStream hookAlmostRealInterpretResponseStream(final NetworkEventReporter mockEventReporter) {
final ByteArrayOutputStream capturedOutput = new ByteArrayOutputStream();
Mockito.when(mockEventReporter.interpretResponseStream(anyString(), anyString(), anyString(), any(InputStream.class), any(ResponseHandler.class))).thenAnswer(new Answer<InputStream>() {
@Override
public InputStream answer(InvocationOnMock invocationOnMock) throws Throwable {
Object[] args = invocationOnMock.getArguments();
String requestId = (String) args[0];
String contentEncoding = (String) args[2];
InputStream responseStream = (InputStream) args[3];
ResponseHandler responseHandler = (ResponseHandler) args[4];
return DecompressionHelper.teeInputWithDecompression(null, /* networkPeerManager */
requestId, responseStream, capturedOutput, contentEncoding, responseHandler);
}
});
return capturedOutput;
}
use of org.mockito.invocation.InvocationOnMock in project gocd by gocd.
the class GarageServiceTest method shouldSucceedWhenGitGCIsCompleted.
@Test
public void shouldSucceedWhenGitGCIsCompleted() 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(0);
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(true));
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));
}
Aggregations