Skip to content

Instantly share code, notes, and snippets.

@IlyaEremin
Created July 31, 2014 05:30
Show Gist options
  • Save IlyaEremin/56ad0344c9551113ee74 to your computer and use it in GitHub Desktop.
Save IlyaEremin/56ad0344c9551113ee74 to your computer and use it in GitHub Desktop.
robolectric tests
@Config(emulateSdk = 18)
@RunWith(RobolectricTestRunner.class)
public class FileIconHelperTest {
@Test
public void testGetExtension() throws Exception {
assertThat(getExtension("image/jpeg")).isEqualTo("jpg");
assertThat(getExtension("video/avi")).isEqualTo("avi");
assertThat(getExtension("superpuper/file")).isEqualTo("");
}
@Test
public void testGetIconForType() throws Exception {
assertThat(getIconForType(Constants.SYSTEM_SHARED_FOLDER)).isEqualTo(R.drawable.shared_folder_icon);
assertThat(getIconForType(Constants.SYSTEM_CONTACTS_FOLDER)).isEqualTo(R.drawable.contacts_icon);
assertThat(getIconForType("unknown_type")).isEqualTo(R.drawable.documents_icon);
}
@Test
public void testGetTextColor() throws Exception {
// verify toLowerCase convertation
assertThat(getTextColor("pdf")).isEqualTo(getTextColor("PDF"));
assertThat(getTextColor("pdf")).isEqualTo(PDF_COLOR);
assertThat(getTextColor("docx")).isEqualTo(DOC_COLOR);
assertThat(getTextColor("mp3")).isEqualTo(MP3_COLOR);
assertThat(getTextColor("magic_extension")).isEqualTo(Color.BLACK);
}
}
@Config(emulateSdk = 18)
@RunWith(RobolectricTestRunner.class)
public class MainActivityRobTest {
@Test public void checkLogIn() throws Exception {
MainActivity activity = Robolectric.buildActivity(MainActivity.class).create().start().resume().visible().get();
EditText username = (EditText) activity.findViewById(R.id.et_login_email);
EditText password = (EditText) activity.findViewById(R.id.et_login_password);
username.setText("[email protected]");
password.setText("Password");
activity.findViewById(R.id.login_button).performClick();
Assertions.assertThat(password.getText().toString()).isNotEmpty();
Assertions.assertThat(activity).isNotEqualTo(activity);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment