Created
August 27, 2015 07:39
-
-
Save patrykpoborca/4f7f6a614f7dae846668 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 MVVMTest { | |
private static final String SOME_URL = "SOME_URL"; | |
private static final String USER_PASSWORD = "USER_PASSWORD"; | |
private static final String USER_NAME = "USER_NAME"; | |
private String tweetedTweet; | |
@Inject | |
MainViewModel viewModel; | |
@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 testWebPage() { | |
viewModel.loadWebPage(SOME_URL) | |
.toBlocking() | |
.forEach(s -> { | |
Assert.assertTrue(s.contains(MockRetrofit.MOCKED_STRING) | |
&& s.contains(SOME_URL)); | |
}); | |
} | |
@Test | |
public void testLogin() { | |
Assert.assertFalse(viewModel.isLoggedIn()); | |
viewModel.toggleLogin(USER_NAME, USER_PASSWORD) | |
.toBlocking() | |
.forEach( | |
user -> { | |
Assert.assertNotNull(user); | |
Assert.assertEquals(user.getUserName(), USER_NAME); | |
} | |
); | |
Assert.assertTrue(viewModel.isLoggedIn()); | |
} | |
@Test | |
public void testTweets() { | |
//Sanity test first to see if underlying logic of tweeter api has changed | |
viewModel.fetchPreviousTweets() | |
.toBlocking() | |
.forEach(list -> { | |
Assert.assertNotNull(list); | |
}); | |
} | |
@Test | |
public void testTweetList() { | |
viewModel.fetchCurrentTweet() | |
.toBlocking() | |
.forEach(tweet -> { | |
tweetedTweet = tweet; | |
}); | |
viewModel.fetchPreviousTweets() | |
.toBlocking() | |
.forEach(list -> { | |
boolean exists = false; | |
for (int i = 0; i < list.size(); i++) { | |
if (tweetedTweet.contains(list.get(i))) { | |
exists = true; | |
break; | |
} | |
} | |
Assert.assertTrue(exists); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment