HistoryTrendPlugin extends AbstractTrendPlugin<HistoryTrendItem> { @SuppressWarnings("PMD.DefaultPackage") static List<HistoryTrendItem> getData(final List<LaunchResults> launchesResults) { final HistoryTrendItem item = createCurrent(launchesResults); final List<HistoryTrendItem> data = getHistoryItems(launchesResults); return Stream.concat(Stream.of(item), data.stream()) .limit(20) .collect(Collectors.toList()); } HistoryTrendPlugin();  static final String JSON_FILE_NAME; static final String HISTORY_TREND_BLOCK_NAME; }
@SuppressWarnings("unchecked") @Test void shouldGetData() { final List<HistoryTrendItem> history = randomHistoryTrendItems(); final List<HistoryTrendItem> data = HistoryTrendPlugin.getData(createSingleLaunchResults( singletonMap(HISTORY_TREND_BLOCK_NAME, history), randomTestResult().setStatus(Status.PASSED), randomTestResult().setStatus(Status.FAILED), randomTestResult().setStatus(Status.FAILED) )); assertThat(data) .hasSize(1 + history.size()) .extracting(HistoryTrendItem::getStatistic) .extracting(Statistic::getTotal, Statistic::getFailed, Statistic::getPassed) .first() .isEqualTo(Tuple.tuple(3L, 2L, 1L)); final List<HistoryTrendItem> next = data.subList(1, data.size()); assertThat(next) .containsExactlyElementsOf(history); }
@Test void shouldFindLatestExecutor() { final Map<String, Object> extra1 = new HashMap<>(); final List<HistoryTrendItem> history1 = randomHistoryTrendItems(); extra1.put(HISTORY_TREND_BLOCK_NAME, history1); extra1.put(EXECUTORS_BLOCK_NAME, new ExecutorInfo().setBuildOrder(1L)); final Map<String, Object> extra2 = new HashMap<>(); final List<HistoryTrendItem> history2 = randomHistoryTrendItems(); extra2.put(HISTORY_TREND_BLOCK_NAME, history2); extra2.put(EXECUTORS_BLOCK_NAME, new ExecutorInfo().setBuildOrder(7L)); final List<LaunchResults> launchResults = Arrays.asList( createLaunchResults(extra1, randomTestResult().setStatus(Status.PASSED), randomTestResult().setStatus(Status.FAILED), randomTestResult().setStatus(Status.FAILED) ), createLaunchResults(extra2, randomTestResult().setStatus(Status.PASSED), randomTestResult().setStatus(Status.FAILED), randomTestResult().setStatus(Status.FAILED) ) ); final List<HistoryTrendItem> data = new HistoryTrendPlugin().getData(launchResults); assertThat(data) .hasSize(1 + history1.size() + history2.size()); final HistoryTrendItem historyTrendItem = data.get(0); assertThat(historyTrendItem) .hasFieldOrPropertyWithValue("buildOrder", 7L); }
@Test void shouldProcessNullBuildOrder() { final List<HistoryTrendItem> history = randomHistoryTrendItems(); final Map<String, Object> extra = new HashMap<>(); extra.put(HISTORY_TREND_BLOCK_NAME, history); extra.put(EXECUTORS_BLOCK_NAME, new ExecutorInfo().setBuildOrder(null)); final List<LaunchResults> launchResults = Arrays.asList( createLaunchResults(extra, randomTestResult().setStatus(Status.PASSED), randomTestResult().setStatus(Status.FAILED), randomTestResult().setStatus(Status.FAILED) ), createLaunchResults(extra, randomTestResult().setStatus(Status.PASSED), randomTestResult().setStatus(Status.FAILED), randomTestResult().setStatus(Status.FAILED) ) ); final List<HistoryTrendItem> data = HistoryTrendPlugin.getData(launchResults); assertThat(data) .hasSize(1 + 2 * history.size()); }