Skip to content

Instantly share code, notes, and snippets.

@mohsenoid
Last active February 4, 2018 18:02
Show Gist options
  • Save mohsenoid/2400b492e7533ed9c3e500cdbe9af9c6 to your computer and use it in GitHub Desktop.
Save mohsenoid/2400b492e7533ed9c3e500cdbe9af9c6 to your computer and use it in GitHub Desktop.
package com.mirhoseini.marvel.activity;
/*...*/
@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 21, shadows = {ShadowSnackbar.class})
public class MainActivityRobolectricTest {
private final static String TEST_TEXT = "This is a test text.";
private MainActivity activity;
@Before
public void setUp() throws Exception {
activity = Robolectric.setupActivity(MainActivity.class);
assertNotNull(activity);
}
@Test
public void testShowToastMessage() throws Exception {
activity.showMessage(TEST_TEXT);
assertThat(TEST_TEXT, equalTo(ShadowToast.getTextOfLatestToast()));
}
@Test
public void testShowOfflineMessage() throws Exception {
activity.showOfflineMessage();
assertSnackbarIsShown(R.string.offline_message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment