Java 类org.junit.runner.notification.StoppedByUserException 实例源码

项目:wizards-of-lua    文件:TestResults.java   
@Override
public void fireTestStarted(Description description) throws StoppedByUserException {
  super.fireTestStarted(description);
  String message = "Running " + description.getDisplayName();
  logger.info(message);

  try {
    EntityPlayerMP player = server.getPlayerList().getPlayerByUsername(playerName);
    ITextComponent itextcomponent = new TextComponentString(message);
    SPacketTitle packet = new SPacketTitle(SPacketTitle.Type.ACTIONBAR,
        TextComponentUtils.processComponent(player, itextcomponent, player));
    player.connection.sendPacket(packet);
  } catch (CommandException e) {
    throw new RuntimeException(e);
  }
}
项目:bazel    文件:CancellableRequestFactory.java   
@Override
public void run(RunNotifier notifier) {
  currentNotifier = new ThreadSafeRunNotifier(notifier);
  if (cancelRequested) {
    currentNotifier.pleaseStop();
  }

  try {
    delegate.run(currentNotifier);
  } catch (StoppedByUserException e) {
    if (cancelRequested) {
      throw new RuntimeException("Test run interrupted", e);
    }
    throw e;
  }
}
项目:bazel    文件:CancellableRequestFactoryTest.java   
@Test
public void testCancelRunBeforeStarting() throws Exception {
  final AtomicBoolean testRan = new AtomicBoolean(false);

  // A runner that should never run its test
  FakeRunner runner = new FakeRunner("shouldNotRun", new Runnable() {
    @Override
    public void run() {
      testRan.set(true);
    }
  });

  Request request = cancellableRequestFactory.createRequest(Request.runner(runner));
  cancellableRequestFactory.cancelRun();
  JUnitCore core = new JUnitCore();

  try {
    core.run(request);
    fail("exception expected");
  } catch (RuntimeException e) {
    assertThat(e).hasMessageThat().isEqualTo("Test run interrupted");
    assertThat(e).hasCauseThat().isInstanceOf(StoppedByUserException.class);
  }

  assertThat(testRan.get()).isFalse();
}
项目:marathonv5    文件:TestRunner.java   
private void doRunTest(Test testSuite) {
    mode = Mode.RUNNING;
    resetToolBar();
    startTime = System.currentTimeMillis();
    runnerThread = new Thread("TestRunner-Thread") {
        @Override public void run() {
            try {
                runner = new MarathonTestRunner();
                runner.addListener(runListener);
                runner.addListener(new AllureMarathonRunListener());
                @SuppressWarnings("unused")
                Result result = runner.run(testSuite);
                runFinished(testSuite);
            } catch (StoppedByUserException e) {
                abort();
            } finally {
                // always return control to UI
                if (interrupted()) {
                    abort();
                }
                MarathonTestCase.reset();
                runnerThread = null;
                System.gc();
            }
        }

        private void abort() {
            endTime = System.currentTimeMillis();
            Platform.runLater(() -> status.setText("Aborted after " + (endTime - startTime) / 1000 + " seconds"));
            mode = Mode.RESULTS;
            resetToolBar();
        }

    };
    createTestReportDir();
    runnerThread.start();
}
项目:play1-maven-plugin    文件:PlayJUnit4Provider.java   
private void executeTestSet( Class<?> clazz, RunListener reporter, Notifier notifier )
{
    final ReportEntry report = new SimpleReportEntry( getClass().getName(), clazz.getName() );
    reporter.testSetStarting( report );
    try
    {
        executeWithRerun( clazz, notifier );
    }
    catch ( Throwable e )
    {
        if ( isFailFast() && e instanceof StoppedByUserException )
        {
            String reason = e.getClass().getName();
            Description skippedTest = createDescription( clazz.getName(), createIgnored( reason ) );
            notifier.fireTestIgnored( skippedTest );
        }
        else
        {
            String reportName = report.getName();
            String reportSourceName = report.getSourceName();
            PojoStackTraceWriter stackWriter = new PojoStackTraceWriter( reportSourceName, reportName, e );
            reporter.testError( withException( reportSourceName, reportName, stackWriter ) );
        }
    }
    finally
    {
        reporter.testSetCompleted( report );
    }
}
项目:kurento-java    文件:KurentoRunNotifier.java   
@Override
public void fireTestStarted(final Description description) throws StoppedByUserException {
  if (pleaseStop) {
    throw new StoppedByUserException();
  }
  new SafeNotifier() {
    @Override
    protected void notifyListener(RunListener each) throws Exception {
      each.testStarted(description);
    }
  }.run();
}
项目:pitest    文件:AdaptingRunListener.java   
@Override
public void testStarted(final Description description) throws Exception {
  if (this.failed) {
    // If the JUnit test has been annotated with @BeforeClass or @AfterClass
    // need to force the exit after the first failure as tests will be run as
    // a block
    // rather than individually.
    // This is apparently the junit way.
    throw new StoppedByUserException();
  }
  this.rc.notifyStart(this.description);
}
项目:bazel    文件:CancellableRequestFactory.java   
/**
 * {@inheritDoc}<p>
 *
 * The implementation is almost an exact copy of the version in
 * {@code RunNotifier} but is thread-safe.
 */
@Override
public void fireTestStarted(Description description) throws StoppedByUserException {
  if (stopRequested) {
    throw new StoppedByUserException();
  }
  getDelegate().fireTestStarted(description);
}
项目:bazel    文件:JUnit4RunnerTest.java   
@Test
public void testInterruptedTest() throws Exception {
  config = createConfig();
  mockRunListener = mock(RunListener.class);
  JUnit4BazelMock component = createComponent(SampleSuite.class);
  JUnit4Runner runner = component.runner();
  final CancellableRequestFactory requestFactory = component.cancellableRequestFactory();

  Description testDescription = Description.createTestDescription(SamplePassingTest.class,
      "testThatAlwaysPasses");

  doAnswer(cancelTestRun(requestFactory))
      .when(mockRunListener).testStarted(testDescription);

  try {
    runner.run();
    fail("exception expected");
  } catch (RuntimeException e) {
    assertThat(e).hasMessageThat().isEqualTo("Test run interrupted");
    assertWithMessage("Expected cause to be a StoppedByUserException")
        .that(e.getCause() instanceof StoppedByUserException)
        .isTrue();

    InOrder inOrder = inOrder(mockRunListener);
    inOrder.verify(mockRunListener).testRunStarted(any(Description.class));
    inOrder.verify(mockRunListener).testStarted(testDescription);
    inOrder.verify(mockRunListener).testFinished(testDescription);
  }
}
项目:junit-composite-runner    文件:NullRunNotifier.java   
@Override
public void fireTestStarted(Description description) throws StoppedByUserException {
    // empty
}
项目:sosiefier    文件:UserStopTest.java   
@Test(expected = StoppedByUserException.class)
public void userStop() {
    fNotifier.fireTestStarted(null);
}
项目:sosiefier    文件:UserStopTest.java   
@Test(expected = StoppedByUserException.class)
public void stopClassRunner() throws Exception {
    Request.aClass(OneTest.class).getRunner().run(fNotifier);
}
项目:wso2-axis2    文件:RuntimeIgnoreRunNotifier.java   
@Override
public void fireTestStarted(Description description) throws StoppedByUserException {
    target.fireTestStarted(description);
}
项目:pitest    文件:AdaptingRunListenerTest.java   
@Test(expected = StoppedByUserException.class)
public void shouldRunStoppedByUserExceptionIfMoreTestsRunAfterAFailure()
    throws Exception {
  this.testee.testFailure(new Failure(this.junitDesc, this.throwable));
  this.testee.testStarted(this.junitDesc);
}
项目:bazel    文件:RunNotifierWrapper.java   
@Override
public void fireTestStarted(Description description) throws StoppedByUserException {
  delegate.fireTestStarted(description);
}
项目:buck-cutom    文件:DelegateRunNotifier.java   
@Override
public void fireTestStarted(final Description description) throws StoppedByUserException {
  delegate.fireTestStarted(description);

  // Do not do apply the default timeout if the test has its own @Test(timeout).
  Test testAnnotation = description.getAnnotation(Test.class);
  if (testAnnotation != null && testAnnotation.timeout() > 0) {
    return;
  }

  // Do not do apply the default timeout if the test has its own @Rule Timeout.
  TestClass testClass = getTestClass(description);
  if (BuckBlockJUnit4ClassRunner.hasTimeoutRule(testClass)) {
    return;
  }

  // Schedule a timer that verifies that the test completed within the specified timeout.
  TimerTask task = new TimerTask() {
    @Override
    public void run() {
      synchronized (finishedTests) {
        // If the test already finished, then do nothing.
        if (finishedTests.contains(description)) {
          return;
        }

        // Should report the failure. The Exception is modeled after the one created by
        // org.junit.internal.runners.statements.FailOnTimeout#createTimeoutException(Thread).
        Exception exception = new Exception(String.format(
            "test timed out after %d milliseconds", defaultTestTimeoutMillis));
        Failure failure = new Failure(description, exception);
        fireTestFailure(failure);
        fireTestFinished(description);

        if (!finishedTests.contains(description)) {
          throw new IllegalStateException("fireTestFinished() should update finishedTests.");
        }

        onTestRunFinished();
        hasTestThatExceededTimeout.set(true);
      }
    }
  };
  timer.schedule(task, defaultTestTimeoutMillis);
}
项目:buck    文件:DelegateRunNotifier.java   
@Override
public void fireTestStarted(final Description description) throws StoppedByUserException {
  delegate.fireTestStarted(description);

  // Do not do apply the default timeout if the test has its own @Test(timeout).
  if (hasJunitTimeout(description)) {
    return;
  }

  // Schedule a timer that verifies that the test completed within the specified timeout.
  TimerTask task =
      new TimerTask() {
        @Override
        public void run() {
          synchronized (finishedTests) {
            // If the test already finished, then do nothing.
            if (finishedTests.contains(description)) {
              return;
            }

            hasTestThatExceededTimeout.set(true);

            // Should report the failure. The Exception is modeled after the one created by
            // org.junit.internal.runners.statements.FailOnTimeout#createTimeoutException(Thread).
            Exception exception =
                new Exception(
                    String.format(
                        "test timed out after %d milliseconds", defaultTestTimeoutMillis));
            Failure failure = new Failure(description, exception);
            fireTestFailure(failure);
            fireTestFinished(description);

            if (!finishedTests.contains(description)) {
              throw new IllegalStateException("fireTestFinished() should update finishedTests.");
            }

            onTestRunFinished();
          }
        }
      };
  timer.schedule(task, defaultTestTimeoutMillis);
}
项目:afton    文件:AftonJUnitRunner.java   
@Override
public void fireTestStarted(final Description description) throws StoppedByUserException {
  trace("AftonJUnitRunner$AftonRunNotifier.fireTestStarted");
  trace("description = [" + description + "]");
  notifier.fireTestStarted(description);
}
项目:junit    文件:UserStopTest.java   
@Test(expected = StoppedByUserException.class)
public void userStop() {
    fNotifier.fireTestStarted(null);
}
项目:junit    文件:UserStopTest.java   
@Test(expected = StoppedByUserException.class)
public void stopClassRunner() throws Exception {
    Request.aClass(OneTest.class).getRunner().run(fNotifier);
}
项目:health-and-care-developer-network    文件:UserStopTest.java   
@Test(expected = StoppedByUserException.class)
public void userStop() {
    fNotifier.fireTestStarted(null);
}
项目:health-and-care-developer-network    文件:UserStopTest.java   
@Test(expected = StoppedByUserException.class)
public void stopClassRunner() throws Exception {
    Request.aClass(OneTest.class).getRunner().run(fNotifier);
}