CategoriesPlugin extends CompositeAggregator implements Reader { @SuppressWarnings("PMD.DefaultPackage") static Tree<TestResult> getData(final List<LaunchResults> launchResults) { final Tree<TestResult> categories = new TestResultTree(CATEGORIES, CategoriesPlugin::groupByCategories); launchResults.stream() .map(LaunchResults::getResults) .flatMap(Collection::stream) .sorted(comparingByTimeAsc()) .forEach(categories::add); return categories; } CategoriesPlugin(); @Override void readResults(final Configuration configuration,
                            final ResultsVisitor visitor,
                            final Path directory); static boolean matches(final TestResult result, final Category category); @Override void aggregate(final Configuration configuration,
                          final List<LaunchResults> launchesResults,
                          final Path outputDirectory); static final String CATEGORIES; static final Category FAILED_TESTS; static final Category BROKEN_TESTS; static final String JSON_FILE_NAME; static final String CSV_FILE_NAME; }
@Test void shouldCreateTree() { final TestResult first = new TestResult() .setName("first") .setStatus(Status.BROKEN) .setStatusMessage("M1"); final TestResult second = new TestResult() .setName("second") .setStatus(Status.FAILED) .setStatusMessage("M2"); final TestResult third = new TestResult() .setName("third") .setStatus(Status.BROKEN) .setStatusMessage("M3"); final TestResult other = new TestResult() .setName("other") .setStatus(Status.PASSED) .setStatusMessage("M4"); first.addExtraBlock(CATEGORIES, singletonList(new Category().setName("C1"))); second.addExtraBlock(CATEGORIES, singletonList(new Category().setName("C2"))); third.addExtraBlock(CATEGORIES, singletonList(new Category().setName("C1"))); other.addExtraBlock(CATEGORIES, singletonList(new Category().setName("C3"))); final List<LaunchResults> launchResults = createSingleLaunchResults(first, second, third, other); final Tree<TestResult> tree = CategoriesPlugin.getData(launchResults); assertThat(tree.getChildren()) .hasSize(3) .extracting(TreeNode::getName) .containsExactlyInAnyOrder("C1", "C2", "C3"); assertThat(tree.getChildren()) .filteredOn("name", "C1") .flatExtracting("children") .extracting("name") .containsExactlyInAnyOrder("M1", "M3"); assertThat(tree.getChildren()) .filteredOn("name", "C1") .flatExtracting("children") .flatExtracting("children") .extracting("name") .containsExactlyInAnyOrder("first", "third"); }
@Issue("587") @Issue("572") @Test void shouldSortByStartTimeAsc() { final Category category = new Category().setName("some"); final TestResult first = new TestResult() .setName("first") .setStatus(Status.FAILED) .setTime(new Time().setStart(10L)); first.addExtraBlock(CATEGORIES, singletonList(category)); final TestResult second = new TestResult() .setName("second") .setStatus(Status.FAILED) .setTime(new Time().setStart(12L)); second.addExtraBlock(CATEGORIES, singletonList(category)); final TestResult timeless = new TestResult() .setName("timeless") .setStatus(Status.FAILED); timeless.addExtraBlock(CATEGORIES, singletonList(category)); final Tree<TestResult> tree = CategoriesPlugin.getData( createSingleLaunchResults(second, first, timeless) ); assertThat(tree.getChildren()) .flatExtracting("children") .flatExtracting("children") .extracting("name") .containsExactly("timeless", "first", "second"); }