@Test public void set_variations_on_all_periods() { SnapshotDto period1ProjectSnapshot = createForProject(PROJECT_DTO).setLast(false); SnapshotDto period2ProjectSnapshot = createForProject(PROJECT_DTO).setLast(false); SnapshotDto period3ProjectSnapshot = createForProject(PROJECT_DTO).setLast(false); SnapshotDto period4ProjectSnapshot = createForProject(PROJECT_DTO).setLast(false); SnapshotDto period5ProjectSnapshot = createForProject(PROJECT_DTO).setLast(false); dbClient .snapshotDao() .insert( session, period1ProjectSnapshot, period2ProjectSnapshot, period3ProjectSnapshot, period4ProjectSnapshot, period5ProjectSnapshot); dbClient .measureDao() .insert( session, newMeasureDto( ISSUES_METRIC.getId(), PROJECT_DTO.getId(), period1ProjectSnapshot.getId(), 0d), newMeasureDto( ISSUES_METRIC.getId(), PROJECT_DTO.getId(), period2ProjectSnapshot.getId(), 20d), newMeasureDto( ISSUES_METRIC.getId(), PROJECT_DTO.getId(), period3ProjectSnapshot.getId(), 40d), newMeasureDto( ISSUES_METRIC.getId(), PROJECT_DTO.getId(), period4ProjectSnapshot.getId(), 80d), newMeasureDto( ISSUES_METRIC.getId(), PROJECT_DTO.getId(), period5ProjectSnapshot.getId(), 100d)); session.commit(); periodsHolder.setPeriods( newPeriod(1, period1ProjectSnapshot), newPeriod(2, period2ProjectSnapshot), newPeriod(3, period3ProjectSnapshot), newPeriod(4, period4ProjectSnapshot), newPeriod(5, period5ProjectSnapshot)); treeRootHolder.setRoot(PROJECT); addRawMeasure(PROJECT, ISSUES_METRIC, Measure.newMeasureBuilder().create(80, null)); underTest.execute(); assertThat(measureRepository.getRawMeasures(PROJECT).keys()).hasSize(1); Measure measure = measureRepository.getRawMeasure(PROJECT, ISSUES_METRIC).get(); assertThat(measure.hasVariations()).isTrue(); assertThat(measure.getVariations().getVariation1()).isEqualTo(80d); assertThat(measure.getVariations().getVariation2()).isEqualTo(60d); assertThat(measure.getVariations().getVariation3()).isEqualTo(40d); assertThat(measure.getVariations().getVariation4()).isEqualTo(0d); assertThat(measure.getVariations().getVariation5()).isEqualTo(-20d); }
private void assertVariation(Component component, String metricKey, int variation) { Measure newMeasure = measureRepository.getRawMeasure(component, metricRepository.getByKey(metricKey)).get(); assertThat(newMeasure.getVariations().getVariation(PERIOD.getIndex())).isEqualTo(variation); assertThat(newMeasure.getVariations().hasVariation(PERIOD.getIndex() + 1)).isFalse(); }