Java Code Examples for org.junit.runner.notification.RunNotifier#removeListener()

The following examples show how to use org.junit.runner.notification.RunNotifier#removeListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestRunner.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the {@link Statement} which will execute all the tests in the class given
 * to the {@linkplain #TestRunner(Class) constructor}.
 *
 * @param  notifier  the object to notify about test results.
 * @return the statement to execute for running the tests.
 */
@Override
protected Statement childrenInvoker(final RunNotifier notifier) {
    final Statement stmt = super.childrenInvoker(notifier);
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            checkClassDependencies();
            notifier.addListener(listener);
            try {
                stmt.evaluate();
            } finally {
                notifier.removeListener(listener);
            }
        }
    };
}
 
Example 2
Source File: TestUtils.java    From january with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void run(RunNotifier notifier) {
	// To avoid duplicates need to do N-1 times if there's N levels of these suites
	// Note, in this notifier implementation it does not matter if we try to remove
	// a listener if is not contained with the notifier
	notifier.removeListener(listener);

	notifier.addListener(listener);
	super.run(notifier);
	notifier.removeListener(listener);
}
 
Example 3
Source File: ParameterizedSWTBotRunner.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void run(RunNotifier notifier) {
	RunListener failureSpy = new ScreenshotCaptureListener();
	notifier.removeListener(failureSpy); // remove existing listeners that could be added by suite or class runners
	notifier.addListener(failureSpy);
	try {
		super.run(notifier);
	} finally {
		notifier.removeListener(failureSpy);
	}
}
 
Example 4
Source File: SwtBotRecordingTestRunner.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void run(final RunNotifier notifier) {
  try {
    notifier.removeListener(testRunRecording); // remove existing listeners that could be added by suite or class runners
    notifier.addListener(testRunRecording);
    super.run(notifier);
  } finally {
    notifier.removeListener(testRunRecording);
  }
}
 
Example 5
Source File: SpecRunner.java    From yatspec with Apache License 2.0 5 votes vote down vote up
@Override
public void run(RunNotifier notifier) {
    final SpecListener listener = new SpecListener();
    notifier.addListener(listener);
    super.run(notifier);
    notifier.removeListener(listener);
    try {
        for (SpecResultListener resultListener : listeners.getResultListeners()) {
            resultListener.complete(outputDirectory(), testResult);
        }
    } catch (Exception e) {
        System.out.println("Error while writing yatspec output");
        e.printStackTrace(System.out);
    }
}
 
Example 6
Source File: ParameterizedSWTBotRunner.java    From editorconfig-eclipse with Apache License 2.0 5 votes vote down vote up
@Override
public void run(final RunNotifier notifier) {
	final RunListener failureSpy = new ScreenshotCaptureListener();
	notifier.removeListener(failureSpy); // remove existing listeners that could be added by suite or class runners
	notifier.addListener(failureSpy);
	try {
		super.run(notifier);
	} finally {
		notifier.removeListener(failureSpy);
	}
}
 
Example 7
Source File: KurentoTestRunner.java    From kurento-java with Apache License 2.0 5 votes vote down vote up
@Override
public void run(RunNotifier notifier) {

  if (listener != null) {
    notifier.removeListener(listener);
  }

  List<FrameworkField> services = this.getTestClass().getAnnotatedFields(Service.class);

  ArrayList<FrameworkField> sortedServices = new ArrayList<>(services);
  Collections.sort(sortedServices, new Comparator<FrameworkField>() {
    @Override
    public int compare(FrameworkField o1, FrameworkField o2) {
      return Integer.compare(o1.getAnnotation(Service.class).value(),
          o2.getAnnotation(Service.class).value());
    }
  });

  listener = new KurentoTestListener(sortedServices);
  notifier.addListener(listener);
  listener.testRunStarted(getDescription());

  if (!shutdownHook) {
    shutdownHook = true;
    Runtime.getRuntime().addShutdownHook(new Thread("app-shutdown-hook") {
      @Override
      public void run() {
        listener.testSuiteFinished();
      }
    });
  }

  // TODO Remove this if we change service management
  notifier = new KurentoRunNotifier(notifier);

  super.run(notifier);
}
 
Example 8
Source File: BonitaSuite.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void run(RunNotifier notifier) {
    final RunListener logNotifier = getRunListener();
    notifier.removeListener(logNotifier); // remove existing listeners that could be added by suite or class runners
    notifier.addListener(logNotifier);
    try {
        super.run(notifier);
    } finally {
        notifier.removeListener(logNotifier);
    }
}
 
Example 9
Source File: XpectConfigurationDelegate.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Runs provided File in Engine. Returns output of execution.
 */
public void execute(ILaunch launch, XpectRunConfiguration runConfiguration) throws RuntimeException {

	Job job = new Job(launch.getLaunchConfiguration().getName()) {

		@Override
		protected IStatus run(IProgressMonitor monitor) {
			XpectRunner xr;
			try {
				xr = new XpectRunner(N4IDEXpectTestClass.class);
			} catch (InitializationError e) {
				N4IDEXpectUIPlugin.logError("cannot initialize xpect runner", e);
				return Status.CANCEL_STATUS;
			}

			// TODO support multiple selection
			/*
			 * if Project provided, or package files should be discovered there. Also multiple selected files
			 */
			String testFileLocation = runConfiguration.getXtFileToRun();

			IXpectURIProvider uriprov = xr.getUriProvider();
			if (uriprov instanceof N4IDEXpectTestURIProvider) {
				((N4IDEXpectTestURIProvider) uriprov).addTestFileLocation(testFileLocation);
			}

			Result result = new Result();
			RunNotifier notifier = new RunNotifier();
			RunListener listener = result.createListener();
			N4IDEXpectRunListener n4Listener = new N4IDEXpectRunListener();

			notifier.addFirstListener(listener);
			notifier.addListener(n4Listener);

			try {
				notifier.fireTestRunStarted(xr.getDescription());
				xr.run(notifier);
				notifier.fireTestRunFinished(result);
			} finally {
				notifier.removeListener(n4Listener);
				notifier.removeListener(listener);
			}
			// Do something with test run result?
			// return result;

			return Status.OK_STATUS;
		}

	};
	job.setUser(true);
	job.schedule();
}
 
Example 10
Source File: AllureJunit4ListenerAspect.java    From allure-java with Apache License 2.0 4 votes vote down vote up
@After("execution(org.junit.runner.notification.RunNotifier.new())")
public void addListener(final JoinPoint point) {
    final RunNotifier notifier = (RunNotifier) point.getThis();
    notifier.removeListener(allure);
    notifier.addListener(allure);
}
 
Example 11
Source File: ListenerSuite.java    From elasticsearch-helper with Apache License 2.0 4 votes vote down vote up
@Override
protected void runChild(Runner runner, RunNotifier notifier) {
    notifier.addListener(listener);
    runner.run(notifier);
    notifier.removeListener(listener);
}
 
Example 12
Source File: JUnitGradeSheetTestRunner.java    From public with Apache License 2.0 3 votes vote down vote up
@Override
public void run(final RunNotifier notifier) {
    listener.testRunStarted(getDescription());

    notifier.addListener(listener);

    super.run(notifier);

    notifier.removeListener(listener);

    listener.testRunFinished(null);
}
 
Example 13
Source File: JUnitGradeSheetTestRunner.java    From public with Apache License 2.0 3 votes vote down vote up
@Override
public void run(final RunNotifier notifier) {
    listener.testRunStarted(getDescription());

    notifier.addListener(listener);

    super.run(notifier);

    notifier.removeListener(listener);

    listener.testRunFinished(null);
}
 
Example 14
Source File: JUnitGradeSheetTestRunner.java    From public with Apache License 2.0 3 votes vote down vote up
@Override
public void run(final RunNotifier notifier) {
    listener.testRunStarted(getDescription());

    notifier.addListener(listener);

    super.run(notifier);

    notifier.removeListener(listener);

    listener.testRunFinished(null);
}
 
Example 15
Source File: JUnitGradeSheetTestRunner.java    From public with Apache License 2.0 3 votes vote down vote up
@Override
public void run(final RunNotifier notifier) {
    listener.testRunStarted(getDescription());

    notifier.addListener(listener);

    super.run(notifier);

    notifier.removeListener(listener);

    listener.testRunFinished(null);
}
 
Example 16
Source File: JUnitGradeSheetTestRunner.java    From public with Apache License 2.0 3 votes vote down vote up
@Override
public void run(final RunNotifier notifier) {
    listener.testRunStarted(getDescription());

    notifier.addListener(listener);

    super.run(notifier);

    notifier.removeListener(listener);

    listener.testRunFinished(null);
}