Repository: corona-warn-app/cwa-server
File: services/distribution/src/test/java/app/coronawarn/server/services/distribution/statistics/KeyFigureCardFactoryTest.java (Java)

Code before:
      statisticsJsonStringObject.setInfectionsReported7daysTrend5percent(0);
      var result = figureCardFactory.createKeyFigureCard(statisticsJsonStringObject, 1);
      assertThat(result.getKeyFigures(1)).extracting(KeyFigure::getTrend, KeyFigure::getTrendSemantic)
          .containsExactly(Trend.STABLE, TrendSemantic.NEUTRAL);
    }

    @Test
    void shouldThrowAnExceptionIfAnyPropertyIsMissing() {
      var missingPropertyObject = new StatisticsJsonStringObject();
      missingPropertyObject.setEffectiveDate("2020-01-01");
      assertThatThrownBy(() -> figureCardFactory.createKeyFigureCard(missingPropertyObject, 1))
          .isInstanceOf(MissingPropertyException.class);
    }

    @ParameterizedTest
    @ValueSource(ints = {0, -1})
    void shouldFailIfInfectionCardIsNotValid(Integer value) {
      statisticsJsonStringObject.setInfectionsReportedCumulated(value);
      final int cardOrdinal = INFECTIONS_CARD.ordinal();
      assertThatThrownBy(
          () -> figureCardFactory.createKeyFigureCard(statisticsJsonStringObject, cardOrdinal))
          .isInstanceOf(MissingPropertyException.class);
    }
    @Test
    void shouldFailIfInfectionReported7daysAvgIsBelowThreshold() {
      statisticsJsonStringObject.setInfectionsReportedDaily(10);
      final int cardOrdinal = INFECTIONS_CARD.ordinal();
      assertThatThrownBy(
          () -> figureCardFactory.createKeyFigureCard(statisticsJsonStringObject, cardOrdinal))
          .isInstanceOf(MissingPropertyException.class);
    }
  }

  @Nested
  @EnableConfigurationProperties(value = DistributionServiceConfig.class)
  @ContextConfiguration(classes = {
      KeyFigureCardFactory.class}, initializers = ConfigDataApplicationContextInitializer.class)
  class IncidenceCardTest {

    @Test
    void testCardHasCorrectKeyFigures() {
      var result = figureCardFactory.createKeyFigureCard(statisticsJsonStringObject, INCIDENCE_CARD.ordinal());
      assertKeyFigure(result.getKeyFigures(0), 168.5, Rank.PRIMARY, Trend.INCREASING, TrendSemantic.NEGATIVE, 1);
    }

    @Test
    void testIncidenceTrendDecreasing() {
      statisticsJsonStringObject.setSevenDayIncidenceTrend1percent(-1);
      var result = figureCardFactory.createKeyFigureCard(statisticsJsonStringObject, INCIDENCE_CARD.ordinal());
      assertThat(result.getKeyFigures(0)).extracting(KeyFigure::getTrend, KeyFigure::getTrendSemantic)
          .containsExactly(Trend.DECREASING, TrendSemantic.POSITIVE);

Review comment (suggestion):
```suggestion
      statisticsJsonStringObject.setInfectionsReportedDaily(10); // this is less than 1% of the given 7dayAvg, see 'setInfectionsReported7daysAvg(1234.0)' in setup()
```

Code after:
      statisticsJsonStringObject.setInfectionsReported7daysTrend5percent(0);
      var result = figureCardFactory.createKeyFigureCard(statisticsJsonStringObject, 1);
      assertThat(result.getKeyFigures(1)).extracting(KeyFigure::getTrend, KeyFigure::getTrendSemantic)
          .containsExactly(Trend.STABLE, TrendSemantic.NEUTRAL);
    }

    @Test
    void shouldThrowAnExceptionIfAnyPropertyIsMissing() {
      var missingPropertyObject = new StatisticsJsonStringObject();
      missingPropertyObject.setEffectiveDate("2020-01-01");
      assertThatThrownBy(() -> figureCardFactory.createKeyFigureCard(missingPropertyObject, 1))
          .isInstanceOf(MissingPropertyException.class);
    }

    @ParameterizedTest
    @ValueSource(ints = {0, -1})
    void shouldFailIfInfectionCardIsNotValid(Integer value) {
      statisticsJsonStringObject.setInfectionsReportedCumulated(value);
      final int cardOrdinal = INFECTIONS_CARD.ordinal();
      assertThatThrownBy(
          () -> figureCardFactory.createKeyFigureCard(statisticsJsonStringObject, cardOrdinal))
          .isInstanceOf(MissingPropertyException.class);
    }
    @Test
    void shouldFailIfInfectionReported7daysAvgIsBelowThreshold() {
      statisticsJsonStringObject.setInfectionsReportedDaily(10); // this is less than 1% of the given 7dayAvg, see 'setInfectionsReported7daysAvg(1234.0)' in setup()
      final int cardOrdinal = INFECTIONS_CARD.ordinal();
      assertThatThrownBy(
          () -> figureCardFactory.createKeyFigureCard(statisticsJsonStringObject, cardOrdinal))
          .isInstanceOf(MissingPropertyException.class);
    }
  }

  @Nested
  @EnableConfigurationProperties(value = DistributionServiceConfig.class)
  @ContextConfiguration(classes = {
      KeyFigureCardFactory.class}, initializers = ConfigDataApplicationContextInitializer.class)
  class IncidenceCardTest {

    @Test
    void testCardHasCorrectKeyFigures() {
      var result = figureCardFactory.createKeyFigureCard(statisticsJsonStringObject, INCIDENCE_CARD.ordinal());
      assertKeyFigure(result.getKeyFigures(0), 168.5, Rank.PRIMARY, Trend.INCREASING, TrendSemantic.NEGATIVE, 1);
    }

    @Test
    void testIncidenceTrendDecreasing() {
      statisticsJsonStringObject.setSevenDayIncidenceTrend1percent(-1);
      var result = figureCardFactory.createKeyFigureCard(statisticsJsonStringObject, INCIDENCE_CARD.ordinal());
      assertThat(result.getKeyFigures(0)).extracting(KeyFigure::getTrend, KeyFigure::getTrendSemantic)
          .containsExactly(Trend.DECREASING, TrendSemantic.POSITIVE);