### Question:
RegisterEmailActivity extends AppCompatBase implements
        CheckEmailFragment.CheckEmailListener { @Override public void onNewUser(User user) { TextInputLayout emailLayout = (TextInputLayout) findViewById(R.id.email_layout); if (mActivityHelper.getFlowParams().allowNewEmailAccounts) { RegisterEmailFragment fragment = RegisterEmailFragment.newInstance( mActivityHelper.getFlowParams(), user); FragmentTransaction ft = getSupportFragmentManager().beginTransaction() .replace(R.id.fragment_register_email, fragment, RegisterEmailFragment.TAG); if (emailLayout != null) ft.addSharedElement(emailLayout, "email_field"); ft.disallowAddToBackStack().commit(); } else { emailLayout.setError(getString(R.string.error_email_does_not_exist)); } }  static Intent createIntent(Context context, FlowParameters flowParams); static Intent createIntent(Context context, FlowParameters flowParams, String email); @Override void onExistingEmailUser(User user); @Override void onExistingIdpUser(User user); @Override void onNewUser(User user); static final int RC_WELCOME_BACK_IDP; }### Answer:
@Test public void testSignUpButton_validatesFields() { RegisterEmailActivity registerEmailActivity = createActivity(); registerEmailActivity.onNewUser(new User.Builder(TestConstants.EMAIL).build()); Button button = (Button) registerEmailActivity.findViewById(R.id.button_create); button.performClick(); TextInputLayout nameLayout = (TextInputLayout) registerEmailActivity.findViewById(R.id.name_layout); TextInputLayout passwordLayout = (TextInputLayout) registerEmailActivity.findViewById(R.id.password_layout); assertEquals( registerEmailActivity.getString(R.string.required_field), nameLayout.getError().toString()); assertEquals( String.format( registerEmailActivity.getResources().getQuantityString( R.plurals.error_weak_password, R.integer.min_password_length), registerEmailActivity.getResources() .getInteger(R.integer.min_password_length) ), passwordLayout.getError().toString()); }
@Test @Config(shadows = {BaseHelperShadow.class, ActivityHelperShadow.class}) public void testSignUpButton_successfulRegistrationShouldContinueToSaveCredentials() { new BaseHelperShadow(); reset(BaseHelperShadow.sSaveSmartLock); TestHelper.initializeApp(RuntimeEnvironment.application); RegisterEmailActivity registerEmailActivity = createActivity(); registerEmailActivity.onNewUser(new User.Builder(TestConstants.EMAIL) .setName(TestConstants.NAME) .setPhotoUri(TestConstants.PHOTO_URI) .build()); EditText name = (EditText) registerEmailActivity.findViewById(R.id.name); EditText password = (EditText) registerEmailActivity.findViewById(R.id.password); name.setText(TestConstants.NAME); password.setText(TestConstants.PASSWORD); when(BaseHelperShadow.sFirebaseUser.updateProfile(any(UserProfileChangeRequest.class))) .thenReturn(new AutoCompleteTask<Void>(null, true, null)); when(BaseHelperShadow.sFirebaseAuth .createUserWithEmailAndPassword( TestConstants.EMAIL, TestConstants.PASSWORD)) .thenReturn(new AutoCompleteTask<>(FakeAuthResult.INSTANCE, true, null)); Button button = (Button) registerEmailActivity.findViewById(R.id.button_create); button.performClick(); TestHelper.verifySmartLockSave( EmailAuthProvider.PROVIDER_ID, TestConstants.EMAIL, TestConstants.PASSWORD); }