Skip to content

Instantly share code, notes, and snippets.

@SeongUgJung
Last active March 17, 2016 02:53
Show Gist options
  • Save SeongUgJung/fbbe44e26626efc1d243 to your computer and use it in GitHub Desktop.
Save SeongUgJung/fbbe44e26626efc1d243 to your computer and use it in GitHub Desktop.
mocking test
@RunWith(AndroidJUnit4.class)
public class AccountHomePresenterImplTest {
private AccountHomePresenterImpl accountHomePresenter;
private AccountHomePresenter.View viewMock;
@Before
public void setUp() throws Exception {
accountHomePresenter = AccountHomePresenterImpl_.getInstance_(JandiApplication.getContext());
viewMock = mock(AccountHomePresenter.View.class);
accountHomePresenter.setView(viewMock);
}
@Test
public void testInitViews_InvalidAccess() throws Exception {
// Given
clearSessions();
// When
accountHomePresenter.initViews();
// Then
verify(viewMock).invalidAccess();
}
@Test
public void testInitViews() throws Exception {
// Given
final boolean[] finish = {false};
doAnswer(invocationOnMock -> {
finish[0] = true;
return invocationOnMock;
}).when(viewMock).setTeamInfo(any(), any());
// When
accountHomePresenter.initViews();
verify(viewMock).setAccountName(anyString());
Awaitility.await().until(() -> finish[0]);
// Then
verify(viewMock).setTeamInfo(any(), anyObject());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment