Skip to content

Instantly share code, notes, and snippets.

@ecgreb
Last active April 11, 2017 07:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ecgreb/dd322efdbd360667634d687bb7467a80 to your computer and use it in GitHub Desktop.
Save ecgreb/dd322efdbd360667634d687bb7467a80 to your computer and use it in GitHub Desktop.
@RunWith(RobolectricTestRunner.class)
@Config(manifest="src/main/AndroidManifest.xml", sdk=23)
public class LoginFormTest {
LoginForm loginForm = new LoginForm(RuntimeEnvironment.application);
TextView emailView = (TextView) loginForm.findViewById(R.id.email);
TextView passwordView = (TextView) loginForm.findViewById(R.id.password);
Button signInButton = (Button) loginForm.findViewById(R.id.email_sign_in_button);
TestListener listener = new TestListener();
@Test public void onClickSignInButton_shouldNotInvokeListenerForInvalidInput() throws Exception {
emailView.setText("bad_email");
passwordView.setText("bad_password");
loginForm.setOnClickListener(listener);
signInButton.performClick();
assertThat(listener.click).isFalse();
}
@Test public void onClickSignInButton_shouldInvokeListenerForValidInput() throws Exception {
emailView.setText("foo@example.com");
passwordView.setText("hello");
loginForm.setOnClickListener(listener);
signInButton.performClick();
assertThat(listener.click).isTrue();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment