use of org.mockito.stubbing.Answer in project byte-buddy by raphw.
the class AgentBuilderDefaultTest method testExecutingTransformerDoesNotRecurseWithModules.
@Test
@JavaVersionRule.Enforce(9)
public void testExecutingTransformerDoesNotRecurseWithModules() throws Exception {
final AgentBuilder.Default.ExecutingTransformer executingTransformer = new AgentBuilder.Default.ExecutingTransformer(byteBuddy, listener, poolStrategy, typeStrategy, locationStrategy, mock(AgentBuilder.Default.NativeMethodStrategy.class), initializationStrategy, mock(AgentBuilder.Default.BootstrapInjectionStrategy.class), AgentBuilder.LambdaInstrumentationStrategy.DISABLED, AgentBuilder.DescriptionStrategy.Default.HYBRID, mock(AgentBuilder.FallbackStrategy.class), mock(AgentBuilder.InstallationListener.class), mock(AgentBuilder.RawMatcher.class), mock(AgentBuilder.Default.Transformation.class), new AgentBuilder.CircularityLock.Default());
final ClassLoader classLoader = mock(ClassLoader.class);
final ProtectionDomain protectionDomain = mock(ProtectionDomain.class);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
assertThat(executingTransformer.transform(JavaModule.ofType(Object.class).unwrap(), classLoader, FOO, Object.class, protectionDomain, new byte[0]), nullValue(byte[].class));
return null;
}
}).when(listener).onComplete(FOO, classLoader, JavaModule.ofType(Object.class), true);
assertThat(executingTransformer.transform(JavaModule.of(Object.class).unwrap(), classLoader, FOO, Object.class, protectionDomain, new byte[0]), nullValue(byte[].class));
verify(listener).onComplete(FOO, classLoader, JavaModule.ofType(Object.class), true);
}
use of org.mockito.stubbing.Answer in project elasticsearch by elastic.
the class RemoteScrollableHitSourceTests method testTooLargeResponse.
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testTooLargeResponse() throws Exception {
ContentTooLongException tooLong = new ContentTooLongException("too long!");
CloseableHttpAsyncClient httpClient = mock(CloseableHttpAsyncClient.class);
when(httpClient.<HttpResponse>execute(any(HttpAsyncRequestProducer.class), any(HttpAsyncResponseConsumer.class), any(HttpClientContext.class), any(FutureCallback.class))).then(new Answer<Future<HttpResponse>>() {
@Override
public Future<HttpResponse> answer(InvocationOnMock invocationOnMock) throws Throwable {
HeapBufferedAsyncResponseConsumer consumer = (HeapBufferedAsyncResponseConsumer) invocationOnMock.getArguments()[1];
FutureCallback callback = (FutureCallback) invocationOnMock.getArguments()[3];
assertEquals(new ByteSizeValue(100, ByteSizeUnit.MB).bytesAsInt(), consumer.getBufferLimit());
callback.failed(tooLong);
return null;
}
});
RemoteScrollableHitSource source = sourceWithMockedClient(true, httpClient);
AtomicBoolean called = new AtomicBoolean();
Consumer<Response> checkResponse = r -> called.set(true);
Throwable e = expectThrows(RuntimeException.class, () -> source.doStartNextScroll(FAKE_SCROLL_ID, timeValueMillis(0), checkResponse));
// Unwrap the some artifacts from the test
while (e.getMessage().equals("failed")) {
e = e.getCause();
}
// This next exception is what the user sees
assertEquals("Remote responded with a chunk that was too large. Use a smaller batch size.", e.getMessage());
// And that exception is reported as being caused by the underlying exception returned by the client
assertSame(tooLong, e.getCause());
assertFalse(called.get());
}
use of org.mockito.stubbing.Answer in project che by eclipse.
the class GithubImporterPagePresenterTest method onLoadRepoClickedWhenGetUserReposIsSuccessful.
@Test
public void onLoadRepoClickedWhenGetUserReposIsSuccessful() throws Exception {
doAnswer(new Answer() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
presenter.onSuccessRequest(jsArrayMixed);
return null;
}
}).when(presenter).doRequest(any(Promise.class), any(Promise.class), any(Promise.class));
when(view.getAccountName()).thenReturn("AccountName");
presenter.onLoadRepoClicked();
verify(gitHubClientService).getRepositoriesList();
verify(gitHubClientService).getUserInfo();
verify(gitHubClientService).getOrganizations();
verify(view).setLoaderVisibility(eq(true));
verify(view).setInputsEnableState(eq(false));
verify(view).setLoaderVisibility(eq(false));
verify(view).setInputsEnableState(eq(true));
verify(view).setAccountNames(Matchers.<Set>anyObject());
verify(view, times(2)).showGithubPanel();
verify(view).setRepositories(Matchers.<List<ProjectData>>anyObject());
verify(view).reset();
}
use of org.mockito.stubbing.Answer in project che by eclipse.
the class GithubImporterPagePresenterTest method onLoadRepoClickedWhenGetUserReposIsFailed.
@Test
public void onLoadRepoClickedWhenGetUserReposIsFailed() throws Exception {
doAnswer(new Answer() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
presenter.onFailRequest(promiseError);
return null;
}
}).when(presenter).doRequest(any(Promise.class), any(Promise.class), any(Promise.class));
presenter.onLoadRepoClicked();
verify(gitHubClientService).getRepositoriesList();
verify(gitHubClientService).getUserInfo();
verify(gitHubClientService).getOrganizations();
verify(view).setLoaderVisibility(eq(true));
verify(view).setInputsEnableState(eq(false));
verify(view).setLoaderVisibility(eq(false));
verify(view).setInputsEnableState(eq(true));
verify(view, never()).setAccountNames((Set<String>) anyObject());
verify(view, never()).showGithubPanel();
verify(view, never()).setRepositories(Matchers.<List<ProjectData>>anyObject());
}
use of org.mockito.stubbing.Answer in project che by eclipse.
the class GithubImporterPagePresenterTest method onLoadRepoClickedWhenAuthorizeIsSuccessful.
@Test
public void onLoadRepoClickedWhenAuthorizeIsSuccessful() throws Exception {
doAnswer(new Answer() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
presenter.onFailRequest(promiseError);
return null;
}
}).doAnswer(new Answer() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
presenter.onSuccessRequest(jsArrayMixed);
return null;
}
}).when(presenter).doRequest(any(Promise.class), any(Promise.class), any(Promise.class));
final Throwable exception = mock(UnauthorizedException.class);
String userId = "userId";
CurrentUser user = mock(CurrentUser.class);
ProfileDto profile = mock(ProfileDto.class);
doReturn(exception).when(promiseError).getCause();
when(appContext.getCurrentUser()).thenReturn(user);
when(user.getProfile()).thenReturn(profile);
when(profile.getUserId()).thenReturn(userId);
presenter.onLoadRepoClicked();
verify(gitHubClientService).getRepositoriesList();
verify(gitHubClientService).getUserInfo();
verify(gitHubClientService).getOrganizations();
verify(gitHubAuthenticator).authenticate(anyString(), asyncCallbackCaptor.capture());
AsyncCallback<OAuthStatus> asyncCallback = asyncCallbackCaptor.getValue();
asyncCallback.onSuccess(null);
verify(view, times(3)).setLoaderVisibility(eq(true));
verify(view, times(3)).setInputsEnableState(eq(false));
verify(view, times(3)).setInputsEnableState(eq(true));
}
Aggregations