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));
}
use of org.mockito.stubbing.Answer in project che by eclipse.
the class GithubImporterPagePresenterTest method onLoadRepoClickedWhenAuthorizeIsFailed.
@Test
public void onLoadRepoClickedWhenAuthorizeIsFailed() throws Exception {
String userId = "userId";
CurrentUser user = mock(CurrentUser.class);
ProfileDto profile = mock(ProfileDto.class);
when(appContext.getCurrentUser()).thenReturn(user);
when(user.getProfile()).thenReturn(profile);
when(profile.getUserId()).thenReturn(userId);
final Throwable exception = mock(UnauthorizedException.class);
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));
doReturn(exception).when(promiseError).getCause();
presenter.onLoadRepoClicked();
verify(gitHubClientService).getRepositoriesList();
verify(gitHubClientService).getUserInfo();
verify(gitHubClientService).getOrganizations();
verify(gitHubAuthenticator).authenticate(anyString(), asyncCallbackCaptor.capture());
AsyncCallback<OAuthStatus> asyncCallback = asyncCallbackCaptor.getValue();
asyncCallback.onFailure(exception);
verify(view, times(2)).setLoaderVisibility(eq(true));
verify(view, times(2)).setInputsEnableState(eq(false));
verify(view, times(2)).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 opentsdb by OpenTSDB.
the class TestBatchedDataPoints method before.
@SuppressWarnings("unchecked")
@Before
public void before() throws Exception {
config = new Config(false);
tsdb = new TSDB(client, config);
// replace the "real" field objects with mocks
Field met = tsdb.getClass().getDeclaredField("metrics");
met.setAccessible(true);
met.set(tsdb, metrics);
Field tagk = tsdb.getClass().getDeclaredField("tag_names");
tagk.setAccessible(true);
tagk.set(tsdb, tag_names);
Field tagv = tsdb.getClass().getDeclaredField("tag_values");
tagv.setAccessible(true);
tagv.set(tsdb, tag_values);
when(metrics.width()).thenReturn((short) 3);
when(tag_names.width()).thenReturn((short) 3);
when(tag_values.width()).thenReturn((short) 3);
when(metrics.getId("foo")).thenReturn(new byte[] { 0, 0, 1 });
when(metrics.getNameAsync(new byte[] { 0, 0, 1 })).thenReturn(Deferred.fromResult("foo"));
PowerMockito.mockStatic(IncomingDataPoints.class);
final byte[] row = new byte[] { 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1 };
PowerMockito.doAnswer(new Answer<byte[]>() {
public byte[] answer(final InvocationOnMock unused) throws Exception {
return row;
}
}).when(IncomingDataPoints.class, "rowKeyTemplate", (TSDB) any(), anyString(), (Map<String, String>) any());
Map<String, String> tags = new HashMap<String, String>();
tags.put("host", "web01");
bdp = new BatchedDataPoints(tsdb, "foo", tags);
}
Aggregations