SignupActivity extends RapidFtrActivity { public void createUser(View view) throws IOException, GeneralSecurityException { if (isValid()) { User user = buildUser(); if (user.exists()) { EditText editText = (EditText) findViewById(R.id.username); editText.setError(getString(R.string.username_taken)); makeToast(getString(R.string.username_taken)); } else { user.save(); makeToast(getString(R.string.registered) + " "+ getEditText(R.id.username)); finish(); } } }  boolean isValid(); void createUser(View view);  }
@Test public void shouldCloseWhenUserDetailsAreCorrect() throws Exception { fillUpFields(); signupActivity.createUser(null); verify(signupActivity).finish(); }
@Test public void shouldShowToastAfterRedirectedToLoginPage() throws Exception { fillUpFields(); signupActivity.createUser(null); assertThat(ShadowToast.getTextOfLatestToast(), equalTo(signupActivity.getString(R.string.registered)+" username")); }
@Test @Ignore public void shouldCheckIfUsernameIsAlreadyTakenInMobile() throws Exception { signupActivity.getContext().getSharedPreferences().edit().putString("user_username","{}").commit(); userName = mock(EditText.class); doReturn(userName).when(signupActivity).findViewById(R.id.username); fillUpFields(); signupActivity.createUser(null); assertThat(ShadowToast.getTextOfLatestToast(), equalTo(signupActivity.getString(R.string.username_taken))); verify(userName).setError(signupActivity.getString(R.string.username_taken)); }