public static TestResult flatten(Collection<TestResult> results) { final TestResult combinedResult = new TestResult(Status.PASSED); final Map<Status, TestResult> resultsPerStatus = new HashMap<Status, TestResult>(); final List<Throwable> allExceptions = new ArrayList<Throwable>(); for (TestResult result : results) { if (result == null) { continue; // For some strange reason sometimes results contain null objects } resultsPerStatus.put(result.getStatus(), result); if (result.getThrowable() != null) { allExceptions.add(result.getThrowable()); } combinedResult.addDescription( String.format("%s: '%s'%n", result.getStatus().name(), result.getDescription())); } propagateTestResultStatus(combinedResult, resultsPerStatus); propagateExceptions(combinedResult, allExceptions); return combinedResult; }
public static TestResult flatten(Collection<TestResult> results) { final TestResult combinedResult = new TestResult(Status.PASSED); final Map<Status, TestResult> resultsPerStatus = new HashMap<Status, TestResult>(); final List<Throwable> allExceptions = new ArrayList<Throwable>(); for (TestResult result : results) { if (result == null) { continue; // For some strange reason sometimes results contain null objects } resultsPerStatus.put(result.getStatus(), result); if (result.getThrowable() != null) { allExceptions.add(result.getThrowable()); } combinedResult.addDescription( String.format("%s: '%s'%n", result.getStatus().name(), result.getDescription())); } propagateTestResultStatus(combinedResult, resultsPerStatus); propagateExceptions(combinedResult, allExceptions); return combinedResult; }
@Test public void should_treat_skipped_and_passed_tests_as_passed_overall() throws Exception { // given final TestResult passed = TestResult.passed("Test passed"); final TestResult skipped = TestResult.skipped(); final List<TestResult> testResults = asList(skipped, passed); // when final TestResult result = TestResult.flatten(testResults); // then assertThat(result.getStatus()).isEqualTo(TestResult.Status.PASSED); assertThat(result.getDescription()).isEqualTo(String.format("SKIPPED: ''%nPASSED: 'Test passed'%n")); }
@Test public void should_combine_descriptions() throws Exception { // given final TestResult p1 = TestResult.passed("First test passed"); final TestResult p2 = TestResult.passed("Second test passed"); final List<TestResult> testResults = asList(p1, p2); // when final TestResult result = TestResult.flatten(testResults); // then assertThat(result.getDescription()).isEqualTo( String.format("PASSED: 'First test passed'%nPASSED: 'Second test passed'%n")); }
@Test public void should_combine_skipped_and_passed_tests_descriptions() throws Exception { // given final TestResult passed = TestResult.passed("First test passed"); final TestResult skipped = TestResult.skipped("Not implemented yet"); final List<TestResult> testResults = asList(skipped, passed); // when final TestResult result = TestResult.flatten(testResults); // then assertThat(result.getDescription()).isEqualTo( String.format("SKIPPED: 'Not implemented yet'%nPASSED: 'First test passed'%n")); }