HelloPresenter { public void onNextClicked(String age, String gender, String language, String country, int type, String unit) { if (validateAge(age)) { saveToDatabase(id, name, language, country, Integer.parseInt(age), gender, type, unit); helloView.startMainView(); } else { helloView.displayErrorWrongAge(); } } HelloPresenter(final HelloView helloView, final DatabaseHandler dbHandler); void loadDatabase(); void onNextClicked(String age, String gender, String language, String country, int type, String unit);  }
@Test public void ShouldAskForWarning_WhenAgeIsNegative() throws Exception { presenter.onNextClicked("-1", null, null, null, -1, null); verify(helloViewMock).displayErrorWrongAge(); verify(dbHandlerMock, never()).addUser(any(User.class)); }
@Test public void ShouldAskForWarning_WhenAgeIsZero() throws Exception { presenter.onNextClicked("0", null, null, null, -1, null); verify(helloViewMock).displayErrorWrongAge(); verify(dbHandlerMock, never()).addUser(any(User.class)); }
@Test public void ShouldAskForWarning_WhenAgeIsAbove120() throws Exception { presenter.onNextClicked("121", null, null, null, -1, null); verify(helloViewMock).displayErrorWrongAge(); verify(dbHandlerMock, never()).addUser(any(User.class)); }
@Test public void ShouldAskForWarning_WhenAgeIsNotNumber() throws Exception { presenter.onNextClicked("12haha", null, null, null, -1, null); verify(helloViewMock).displayErrorWrongAge(); verify(dbHandlerMock, never()).addUser(any(User.class)); }
@Test public void ShouldAskForWarning_WhenAgeIsEmpty() throws Exception { presenter.onNextClicked("", null, null, null, -1, null); verify(helloViewMock).displayErrorWrongAge(); verify(dbHandlerMock, never()).addUser(any(User.class)); }
@Test public void ShouldAskForWarning_WhenAgeIsNull() throws Exception { presenter.onNextClicked(null, null, null, null, -1, null); verify(helloViewMock).displayErrorWrongAge(); verify(dbHandlerMock, never()).addUser(any(User.class)); }
@Test public void ShouldPropagateAllValues_WhenSavingUser() throws Exception { final String gender = "male"; final String language = "ukrainian"; final String country = "ukraine"; final int type = 1; final String unit = "mmol/l"; presenter.onNextClicked("35", gender, language, country, type, unit); verify(dbHandlerMock).addUser(userCaptor.capture()); final User user = userCaptor.getValue(); assertThat(user.getAge()).isEqualTo(35); assertThat(user.getGender()).isEqualTo(gender); assertThat(user.getPreferred_language()).isEqualTo(language); assertThat(user.getCountry()).isEqualTo(country); assertThat(user.getD_type()).isEqualTo(type); assertThat(user.getPreferred_unit()).isEqualTo(unit); }
@Test public void ShouldPutADAValuesAsDefault_WhenSavingUser() throws Exception { presenter.onNextClicked("35", null, null, null, -1, null); verify(dbHandlerMock).addUser(userCaptor.capture()); final User user = userCaptor.getValue(); assertThat(user.getPreferred_unit_a1c()).isEqualTo("percentage"); assertThat(user.getPreferred_unit_weight()).isEqualTo("kilograms"); assertThat(user.getPreferred_range()).isEqualTo("ADA"); assertThat(user.getCustom_range_max()).isEqualTo(180); assertThat(user.getCustom_range_min()).isEqualTo(70); }