@Test public void signInFailsWithGeneralError() { main.launchActivity(SignInActivity.getStartIntent(component.getContext(), false)); stubAccountPickerIntent(); // Stub an error when calling sign in doReturn(Observable.error(new RuntimeException("Error"))) .when(component.getMockDataManager()) .signIn(mSelectedAccount); onView(withId(R.id.button_sign_in)).perform(click()); allowPermissionsIfNeeded(); onView(withText(R.string.error_sign_in)).check(matches(isDisplayed())); }
@Test public void signInSuccessfulNavigatesToWelcome() { main.launchActivity(SignInActivity.getStartIntent(component.getContext(), false)); stubAccountPickerIntent(); // Stub sign in method in the DataManager Ribot ribot = MockModelFabric.newRibot(); doReturn(Observable.just(ribot)).when(component.getMockDataManager()).signIn(mSelectedAccount); onView(withId(R.id.button_sign_in)).perform(click()); allowPermissionsIfNeeded(); // Check that it navigates correctly to the welcome screen String expectedWelcome = main.getActivity().getString(R.string.welcome_greetings, ribot.profile.name.first); onView(withText(expectedWelcome)).check(matches(isDisplayed())); }
@Test public void signInFailsWithProfileNotFound() { main.launchActivity(SignInActivity.getStartIntent(component.getContext(), false)); stubAccountPickerIntent(); // Stub with http 403 error HttpException http403Exception = new HttpException(Response.error(403, null)); doReturn(Observable.error(http403Exception)) .when(component.getMockDataManager()) .signIn(mSelectedAccount); onView(withId(R.id.button_sign_in)).perform(click()); allowPermissionsIfNeeded(); String expectedWelcome = main.getActivity().getString(R.string.error_ribot_profile_not_found, mSelectedAccount.name); onView(withText(expectedWelcome)).check(matches(isDisplayed())); }