Last active
March 17, 2016 02:53
-
-
Save SeongUgJung/fbbe44e26626efc1d243 to your computer and use it in GitHub Desktop.
mocking test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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