private Throwable evaluateSafely(Statement base) { try { base.evaluate(); return null; } catch (Throwable throwable) { return throwable; } } };
@Override public void evaluate() throws Throwable { try { this.next.evaluate(); } finally { testContextManagerCache.remove(this.testClass); } } }
@Override public void evaluate() throws Throwable { try { statement.evaluate(); } finally { Thread.interrupted(); // clearing thread interrupted status for isolation } } };
/** * Evaluate the next {@link Statement statement} in the execution chain * repeatedly, using the specified repeat count. */ @Override public void evaluate() throws Throwable { for (int i = 0; i < this.repeat; i++) { if (this.repeat > 1 && logger.isInfoEnabled()) { logger.info(String.format("Repetition %d of test %s#%s()", (i + 1), this.testMethod.getDeclaringClass().getSimpleName(), this.testMethod.getName())); } this.next.evaluate(); } }
/** * Evaluate the next {@link Statement statement} in the execution chain * (typically an instance of {@link SpringRepeat}) and throw a * {@link TimeoutException} if the next {@code statement} executes longer * than the specified {@code timeout}. */ @Override public void evaluate() throws Throwable { if (this.timeout == 0) { this.next.evaluate(); } else { long startTime = System.currentTimeMillis(); this.next.evaluate(); long elapsed = System.currentTimeMillis() - startTime; if (elapsed > this.timeout) { throw new TimeoutException( String.format("Test took %s ms; limit was %s ms.", elapsed, this.timeout)); } } }
@Override public void evaluate() throws Throwable { base.evaluate(); ensureResourcesClosed(); } };
/** * Invoke {@link TestContextManager#prepareTestInstance(Object)} and * then evaluate the next {@link Statement} in the execution chain * (typically an instance of {@link RunAfterTestMethodCallbacks}). */ @Override public void evaluate() throws Throwable { this.testContextManager.prepareTestInstance(this.testInstance); this.next.evaluate(); }
/** * Invoke {@link TestContextManager#beforeTestMethod(Object, Method)} * and then evaluate the next {@link Statement} in the execution chain * (typically an instance of * {@link org.junit.internal.runners.statements.RunBefores RunBefores}). */ @Override public void evaluate() throws Throwable { this.testContextManager.beforeTestMethod(this.testInstance, this.testMethod); this.next.evaluate(); }
/** * Invoke {@link TestContextManager#beforeTestExecution(Object, Method)} * and then evaluate the next {@link Statement} in the execution chain * (typically an instance of * {@link org.junit.internal.runners.statements.InvokeMethod InvokeMethod}). */ @Override public void evaluate() throws Throwable { this.testContextManager.beforeTestExecution(this.testInstance, this.testMethod); this.next.evaluate(); }
/** * Invoke {@link TestContextManager#beforeTestClass()} and then evaluate * the next {@link Statement} in the execution chain (typically an instance * of {@link org.junit.internal.runners.statements.RunBefores RunBefores}). */ @Override public void evaluate() throws Throwable { this.testContextManager.beforeTestClass(); this.next.evaluate(); }
@Override public void evaluate() throws Throwable { for( int i = 0; i < times; i++ ) { System.out.println("*** Iteration " + (i + 1) + "/" + times + " of test"); statement.evaluate(); } } }
@Override public void evaluate() throws Throwable { final Locale save = Locale.getDefault(); try { Locale.setDefault(newLocale); stmt.evaluate(); } finally { Locale.setDefault(save); } } };
@Override public void evaluate() throws Throwable { final TimeZone save = TimeZone.getDefault(); try { TimeZone.setDefault(newTimeZone); stmt.evaluate(); } finally { TimeZone.setDefault(save); } } };
@Override public void evaluate() throws Throwable { isUsedAsRule = true; base.evaluate(); if (isUsedWithoutCallingTest) { fail("You used KeyTester but failed to call test()!"); } } };
@Override public void evaluate() throws Throwable { try { base.evaluate(); } finally { Glide.tearDown(); } } };
@Override public void evaluate() throws Throwable { Throwable caughtThrowable = null; for (int i = 0; i < retryCount; i++) { try { base.evaluate(); return; } catch (Throwable t) { caughtThrowable = t; System.err.println(description.getDisplayName() + ": run " + (i + 1) + " failed"); int n = sleep; if (backoff && i != 0) { n = n * (2 << i); } Thread.sleep(n); } } System.err.println(description.getDisplayName() + ": giving up after " + retryCount + " failures"); throw caughtThrowable; } }
@Test public void noExceptionThrownIfNoUserExceptionAndTimeoutDoesNotOccur() throws Throwable { doAnswer((Answer<Void>) invocation -> { return null; }).when(statement).evaluate(); new SpringFailOnTimeout(statement, 100).evaluate(); }
@Test public void timeoutExceptionThrownIfNoUserException() throws Throwable { doAnswer((Answer<Void>) invocation -> { TimeUnit.MILLISECONDS.sleep(50); return null; }).when(statement).evaluate(); exception.expect(TimeoutException.class); new SpringFailOnTimeout(statement, 1).evaluate(); }
@Override public void evaluate() throws Throwable { try { VerificationCollectorImpl.this.assertLazily(); base.evaluate(); VerificationCollectorImpl.this.collectAndReport(); } finally { // If base.evaluate() throws an error, we must explicitly reset the VerificationStrategy // to prevent subsequent tests to be assert lazily mockingProgress().setVerificationStrategy(MockingProgressImpl.getDefaultVerificationStrategy()); } } };
@Test public void userExceptionPropagates() throws Throwable { doThrow(new Boom()).when(statement).evaluate(); exception.expect(Boom.class); new SpringFailOnTimeout(statement, 1).evaluate(); }