A1CCalculatorPresenter { public double calculateA1C(String glucose) { if (isInvalidDouble(glucose)) { return 0; } double convertedA1C; User user = dbHandler.getUser(1); double glucoseDouble = ReadingTools.safeParseDouble(glucose); if (Constants.Units.MG_DL.equals(user.getPreferred_unit())) { convertedA1C = GlucosioConverter.glucoseToA1C(glucoseDouble); } else { convertedA1C = GlucosioConverter.glucoseToA1C(GlucosioConverter.glucoseToMgDl(glucoseDouble)); } if ("percentage".equals(user.getPreferred_unit_a1c())) { return convertedA1C; } else { return GlucosioConverter.a1cNgspToIfcc(convertedA1C); } } A1CCalculatorPresenter(@NonNull final A1cCalculatorActivity activity,
                                  @NonNull final DatabaseHandler dbHandler); double calculateA1C(String glucose); void checkGlucoseUnit(); void saveA1C(double a1c); String getA1cUnit();  }
@Test public void ShouldReturnZero_WhenNullStringPassed() { assertThat(presenter.calculateA1C(null)).isZero(); }
@Test public void ShouldReturnZero_WhenEmptyStringPassed() { assertThat(presenter.calculateA1C(null)).isZero(); }
@Test public void ShouldReturnZero_WhenDecimalSeparatorStringPassed() { assertThat(presenter.calculateA1C(".")).isZero(); }
@Test public void ShouldReturnZero_WhenAnotherDecimalSeparatorStringPassed() { assertThat(presenter.calculateA1C(",")).isZero(); }
@Test public void ShouldCalculatable_WhenUserPreferredMmol() { user.setPreferred_unit(Constants.Units.MMOL_L); assertThat(presenter.calculateA1C("1")).isEqualTo(2.25); }
@Test public void ShouldCalculatable_WhenUserPreferredPercentage() { user.setPreferred_unit_a1c("mmol/mol"); assertThat(presenter.calculateA1C("20")).isEqualTo(1.84); }