Skip to content

Instantly share code, notes, and snippets.

@drawers
Created November 1, 2017 19:47
Show Gist options
  • Save drawers/ad65659b8502685c1d6050ce601b5355 to your computer and use it in GitHub Desktop.
Save drawers/ad65659b8502685c1d6050ce601b5355 to your computer and use it in GitHub Desktop.
An integration test for the RegistrationActivity
public class RegistrationTest {
//mocks
@Mock Storage mockStorage;
@Mock RegistrationService mockRegistrationService;
@Mock RegistrationContract.View mockView;
//system under test
RegistrationContract.Interactor interactor;
RegistrationContract.Presenter presenter;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
presenter = new RegistrationPresenter(mockRegistrationService, mockStorage);
presenter.takeView(mockView);
interactor = new RegistrationInteractor(presenter);
}
@Test
public void givenNoInternet_whenClickRegisterButton_thenShowsAlertDialogWithMessage() {
//arrange
when(mockRegistrationService.register(any(RegistrationDTO.class)).thenThrow(new ConnectException());
//act
interactor.onRegisterButtonClick("username", "password");
//assert
verify(view).showMessage("No internet available.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment