1 package org.junit.internal.runners.model; 2 3 import org.junit.internal.AssumptionViolatedException; 4 import org.junit.runner.Description; 5 import org.junit.runner.notification.Failure; 6 import org.junit.runner.notification.RunNotifier; 7 import org.junit.runners.model.MultipleFailureException; 8 9 public class EachTestNotifier { 10 private final RunNotifier notifier; 11 12 private final Description description; 13 EachTestNotifier(RunNotifier notifier, Description description)14 public EachTestNotifier(RunNotifier notifier, Description description) { 15 this.notifier = notifier; 16 this.description = description; 17 } 18 addFailure(Throwable targetException)19 public void addFailure(Throwable targetException) { 20 if (targetException instanceof MultipleFailureException) { 21 addMultipleFailureException((MultipleFailureException) targetException); 22 } else { 23 notifier.fireTestFailure(new Failure(description, targetException)); 24 } 25 } 26 addMultipleFailureException(MultipleFailureException mfe)27 private void addMultipleFailureException(MultipleFailureException mfe) { 28 for (Throwable each : mfe.getFailures()) { 29 addFailure(each); 30 } 31 } 32 addFailedAssumption(AssumptionViolatedException e)33 public void addFailedAssumption(AssumptionViolatedException e) { 34 notifier.fireTestAssumptionFailed(new Failure(description, e)); 35 } 36 fireTestFinished()37 public void fireTestFinished() { 38 notifier.fireTestFinished(description); 39 } 40 fireTestStarted()41 public void fireTestStarted() { 42 notifier.fireTestStarted(description); 43 } 44 fireTestIgnored()45 public void fireTestIgnored() { 46 notifier.fireTestIgnored(description); 47 } 48 49 /** 50 * Calls {@link RunNotifier#fireTestSuiteStarted(Description)}, passing the 51 * {@link Description} that was passed to the {@code EachTestNotifier} constructor. 52 * This should be called when a test suite is about to be started. 53 * @see RunNotifier#fireTestSuiteStarted(Description) 54 * @since 4.13 55 */ fireTestSuiteStarted()56 public void fireTestSuiteStarted() { 57 notifier.fireTestSuiteStarted(description); 58 } 59 60 /** 61 * Calls {@link RunNotifier#fireTestSuiteFinished(Description)}, passing the 62 * {@link Description} that was passed to the {@code EachTestNotifier} constructor. 63 * This should be called when a test suite has finished, whether the test suite succeeds 64 * or fails. 65 * @see RunNotifier#fireTestSuiteFinished(Description) 66 * @since 4.13 67 */ fireTestSuiteFinished()68 public void fireTestSuiteFinished() { 69 notifier.fireTestSuiteFinished(description); 70 } 71 }