Skip to content

Instantly share code, notes, and snippets.

@wingyplus
Created September 30, 2016 05:06
Show Gist options
  • Save wingyplus/17e1808450062700405eb2d55d54e4bb to your computer and use it in GitHub Desktop.
Save wingyplus/17e1808450062700405eb2d55d54e4bb to your computer and use it in GitHub Desktop.
@Test
public void getSingleUserWithAsynchronousMethod() throws InterruptedException {
User wingyplus = new User();
CountDownLatch signal = new CountDownLatch(1);
userService
.getSingleUser("wingyplus")
.enqueue(new Callback<User>() {
@Override
public void onResponse(Call<User> call, Response<User> response) {
User user = response.body();
wingyplus.setLogin(user.getLogin());
wingyplus.setId(user.getId());
wingyplus.setAvatarUrl(user.getAvatarUrl());
wingyplus.setPublicGists(user.getPublicGists());
wingyplus.setPublicRepos(user.getPublicRepos());
signal.countDown();
}
@Override
public void onFailure(Call<User> call, Throwable t) {
}
});
signal.await();
assertThat(wingyplus.getLogin(), is("wingyplus"));
assertThat(wingyplus.getId(), is(484530));
assertThat(wingyplus.getPublicRepos(), is(197));
assertThat(wingyplus.getPublicGists(), is(216));
assertThat(wingyplus.getAvatarUrl(), is("https://avatars.githubusercontent.com/u/484530?v=3"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment