Last active
August 27, 2015 16:11
-
-
Save patrykpoborca/50df683017e70b8471a3 to your computer and use it in GitHub Desktop.
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(JUnit4.class) | |
public class MVPTest { | |
private static final String SOME_URL = "SOME_URL"; | |
private static final String USER_PASSWORD = "USER_PASSWORD"; | |
private static final String USER_NAME = "USER_NAME"; | |
@Inject | |
MockTweeterActivityPview pView; | |
@Inject | |
TweeterMVPPresenter presenter; | |
@Before | |
public void setUp(){ | |
TestHelper.getTestClassInjector() | |
.inject(this); | |
Assert.assertTrue(TestHelper.getBaseComponent().getLocalDataCache() instanceof MockLocalDataCache); | |
Assert.assertTrue(TestHelper.getBaseComponent().getRetrofit() instanceof MockRetrofit); | |
Assert.assertTrue(TestHelper.getBaseComponent().getOkHTTP() instanceof MockOkHTTP); | |
} | |
@Test | |
public void testLogin(){ | |
presenter.toggleLogin(USER_NAME, USER_PASSWORD); | |
TestHelper.waitFor(() -> pView.toggleLoginContainerCalled); | |
Assert.assertTrue(pView.toggleLoginContainerCalled); | |
pView.toggleLoginContainerCalled = false; | |
presenter.toggleLogin(USER_NAME, USER_PASSWORD); | |
TestHelper.waitFor(() -> pView.toggleLoginContainerCalled); | |
Assert.assertTrue(pView.toggleLoginContainerCalled); | |
} | |
@Test | |
public void testFetchTweets(){ | |
presenter.fetchCurrentTweet(); | |
TestHelper.waitFor(() -> pView.fetchedTweet != null); | |
String tweet = pView.fetchedTweet; | |
presenter.fetchPreviousTweets(); | |
TestHelper.waitFor(() -> pView.previousTweets != null); | |
boolean found = false; | |
for(int i=0; i < pView.previousTweets.size(); i++){ | |
found = tweet.contains(pView.previousTweets.get(i)); | |
if(found){ | |
break; | |
} | |
} | |
Assert.assertTrue(found); | |
} | |
@Test | |
public void testWebPage() { | |
presenter.loadWebPage(SOME_URL); | |
TestHelper.waitFor(() -> pView.displayWebpage != null); | |
String webPage = pView.displayWebpage; | |
Assert.assertTrue(webPage.contains(SOME_URL)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment