org.junit.internal.runners.statements.Fail Java Examples

The following examples show how to use org.junit.internal.runners.statements.Fail. 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: ColaTestUnitRunner.java    From COLA with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected Statement methodBlock(FrameworkMethod frameworkMethod) {
    Object testInstance;
    try {
        testInstance = new ReflectiveCallable() {
            @Override
            protected Object runReflectiveCall() throws Throwable {
                Description description = describeChild(frameworkMethod);
                return createTest(description);
            }
        }.run();
    }
    catch (Throwable ex) {
        return new Fail(ex);
    }


    Statement statement = methodInvoker(frameworkMethod, testInstance);
    statement = possiblyExpectingExceptions(frameworkMethod, testInstance, statement);
    statement = withBefores(frameworkMethod, testInstance, statement);
    if(!ColaMockito.g().getContext().isRecording()) {
        statement = withColaBefores(frameworkMethod, testInstance, statement);
    }
    statement = withAfters(frameworkMethod, testInstance, statement);
    return statement;
}
 
Example #2
Source File: SpringJUnit4ClassRunner.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Augment the default JUnit behavior
 * {@linkplain #withPotentialRepeat with potential repeats} of the entire
 * execution chain.
 * <p>Furthermore, support for timeouts has been moved down the execution
 * chain in order to include execution of {@link org.junit.Before @Before}
 * and {@link org.junit.After @After} methods within the timed execution.
 * Note that this differs from the default JUnit behavior of executing
 * {@code @Before} and {@code @After} methods in the main thread while
 * executing the actual test method in a separate thread. Thus, the net
 * effect is that {@code @Before} and {@code @After} methods will be
 * executed in the same thread as the test method. As a consequence,
 * JUnit-specified timeouts will work fine in combination with Spring
 * transactions. However, JUnit-specific timeouts still differ from
 * Spring-specific timeouts in that the former execute in a separate
 * thread while the latter simply execute in the main thread (like regular
 * tests).
 * @see #possiblyExpectingExceptions(FrameworkMethod, Object, Statement)
 * @see #withBefores(FrameworkMethod, Object, Statement)
 * @see #withAfters(FrameworkMethod, Object, Statement)
 * @see #withRulesReflectively(FrameworkMethod, Object, Statement)
 * @see #withPotentialRepeat(FrameworkMethod, Object, Statement)
 * @see #withPotentialTimeout(FrameworkMethod, Object, Statement)
 */
@Override
protected Statement methodBlock(FrameworkMethod frameworkMethod) {
	Object testInstance;
	try {
		testInstance = new ReflectiveCallable() {
			@Override
			protected Object runReflectiveCall() throws Throwable {
				return createTest();
			}
		}.run();
	}
	catch (Throwable ex) {
		return new Fail(ex);
	}

	Statement statement = methodInvoker(frameworkMethod, testInstance);
	statement = possiblyExpectingExceptions(frameworkMethod, testInstance, statement);
	statement = withBefores(frameworkMethod, testInstance, statement);
	statement = withAfters(frameworkMethod, testInstance, statement);
	statement = withRulesReflectively(frameworkMethod, testInstance, statement);
	statement = withPotentialRepeat(frameworkMethod, testInstance, statement);
	statement = withPotentialTimeout(frameworkMethod, testInstance, statement);
	return statement;
}
 
Example #3
Source File: MetaRunner.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Override
protected Statement methodBlock(final FrameworkMethod method) {
    final Object test;
    try {
        test = new ReflectiveCallable() {
            @Override
            protected Object runReflectiveCall() throws Throwable {
                return createTest();
            }
        }.run();
    } catch (final Throwable e) {
        return new Fail(e);
    }
    Statement statement = new MetaTest.$(method, test);
    statement = withBefores(method, test, statement);
    statement = withAfters(method, test, statement);
    return statement;
}
 
Example #4
Source File: ValidationRunner.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Override
protected Statement methodBlock(final FrameworkMethod method) {
    final Object test;
    try {
        test = new ReflectiveCallable() {
            @Override
            protected Object runReflectiveCall() throws Throwable {
                return createTest();
            }
        }.run();
    } catch (final Throwable e) {
        return new Fail(e);
    }
    Statement statement = new InvokeMethod(method, test);
    statement = withBefores(method, test, statement);
    statement = withAfters(method, test, statement);
    return statement;
}
 
Example #5
Source File: EndToEndRunner.java    From buck with Apache License 2.0 6 votes vote down vote up
/** Creates the test statement for a testDescriptor */
private Statement methodBlock(EndToEndTestDescriptor testDescriptor) {
  Object test;
  try {
    test =
        new ReflectiveCallable() {
          @Override
          protected Object runReflectiveCall() throws Throwable {
            return createTest();
          }
        }.run();
  } catch (Throwable e) {
    return new Fail(e);
  }

  Statement statement = new BuckInvoker(testDescriptor, test);
  statement = withBefores(test, statement);
  statement = withAfters(test, statement);
  statement = withExpectedExceptions(testDescriptor, statement);
  statement = withRules(testDescriptor, test, statement);
  return statement;
}
 
Example #6
Source File: SpringJUnit4ParameterizedClassRunner.java    From tds with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Augments the default JUnit behavior
 * {@link #withPotentialRepeat(FrameworkMethod, Object, Statement) with
 * potential repeats} of the entire execution chain.
 * <p>
 * Furthermore, support for timeouts has been moved down the execution chain
 * in order to include execution of {@link org.junit.Before &#064;Before}
 * and {@link org.junit.After &#064;After} methods within the timed
 * execution. Note that this differs from the default JUnit behavior of
 * executing <code>&#064;Before</code> and <code>&#064;After</code> methods
 * in the main thread while executing the actual test method in a separate
 * thread. Thus, the end effect is that <code>&#064;Before</code> and
 * <code>&#064;After</code> methods will be executed in the same thread as
 * the test method. As a consequence, JUnit-specified timeouts will work
 * fine in combination with Spring transactions. Note that JUnit-specific
 * timeouts still differ from Spring-specific timeouts in that the former
 * execute in a separate thread while the latter simply execute in the main
 * thread (like regular tests).
 * </p>
 *
 * @see #possiblyExpectingExceptions(FrameworkMethod, Object, Statement)
 * @see #withBefores(FrameworkMethod, Object, Statement)
 * @see #withAfters(FrameworkMethod, Object, Statement)
 * @see #withPotentialTimeout(FrameworkMethod, Object, Statement)
 * @see #withPotentialRepeat(FrameworkMethod, Object, Statement)
 */
@Override
protected Statement methodBlock(FrameworkMethod frameworkMethod) {

  Object testInstance;
  try {
    testInstance = new ReflectiveCallable() {

      @Override
      protected Object runReflectiveCall() throws Throwable {
        return createTest();
      }
    }.run();
  } catch (Throwable e) {
    return new Fail(e);
  }

  Statement statement = methodInvoker(frameworkMethod, testInstance);
  statement = possiblyExpectingExceptions(frameworkMethod, testInstance, statement);
  statement = withRulesReflectively(frameworkMethod, testInstance, statement);
  statement = withBefores(frameworkMethod, testInstance, statement);
  statement = withAfters(frameworkMethod, testInstance, statement);
  statement = withPotentialRepeat(frameworkMethod, testInstance, statement);
  statement = withPotentialTimeout(frameworkMethod, testInstance, statement);

  return statement;
}
 
Example #7
Source File: SpringRunnerWithGlobalExpectedExceptionInspected.java    From grpc-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
@Override
protected Statement methodBlock(FrameworkMethod frameworkMethod) {
    Statement result = super.methodBlock(frameworkMethod);
    try {
        return new ExpectExceptionWithPredicate(result, expectedExceptionInspector.newInstance());
    } catch (InstantiationException | IllegalAccessException e) {
        return new Fail(e);
    }
}
 
Example #8
Source File: JUnit4Runner.java    From tomee with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new test instance
 *
 * @return new instance
 */
private Object newTestInstance() {
    try {
        return new ReflectiveCallable() {
            @Override
            protected Object runReflectiveCall() throws Throwable {
                return createTest();
            }
        }.run();
    } catch (final Throwable e) {
        return new Fail(e);
    }
}
 
Example #9
Source File: LocalClientRunner.java    From tomee with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new test instance
 *
 * @return new instance
 */
private Object newTestInstance() {
    try {
        return new ReflectiveCallable() {
            @Override
            protected Object runReflectiveCall() throws Throwable {
                return createTest();
            }
        }.run();
    } catch (final Throwable e) {
        return new Fail(e);
    }
}
 
Example #10
Source File: BrowserVersionClassRunner.java    From htmlunit with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("deprecation")
protected Statement methodBlock(final FrameworkMethod method) {
    final Object test;
    final WebTestCase testCase;
    try {
        testCase = (WebTestCase) createTest();
        test = new ReflectiveCallable() {
            @Override
            protected Object runReflectiveCall() throws Throwable {
                return testCase;
            }
        } .run();
    }
    catch (final Throwable e) {
        return new Fail(e);
    }

    Statement statement = methodInvoker(method, test);
    statement = possiblyExpectingExceptions(method, test, statement);
    statement = withPotentialTimeout(method, test, statement);
    statement = withBefores(method, test, statement);
    statement = withAfters(method, test, statement);
    statement = withRules(method, test, statement);

    //  End of copy & paste from super.methodBlock()  //

    boolean notYetImplemented = false;
    final int tries;

    if (testCase instanceof WebDriverTestCase && realBrowser_) {
        tries = 1;
    }
    else {
        notYetImplemented = isNotYetImplemented(method);
        tries = getTries(method);
    }
    if (method instanceof StandardsFrameworkMethod && ((StandardsFrameworkMethod) method).isStandards()) {
        setAlertsStandards(testCase, method.getMethod());
    }
    else {
        setAlerts(testCase, method.getMethod());
    }
    statement = new BrowserStatement(statement, method, realBrowser_,
            notYetImplemented, tries, browserVersion_);
    return statement;
}
 
Example #11
Source File: LoadTimeWeavableTestRunner.java    From rice with Educational Community License v2.0 4 votes vote down vote up
/**
 * Returns a Statement that, when executed, either returns normally if
 * {@code method} passes, or throws an exception if {@code method} fails.
 *
 * Here is an outline of the default implementation:
 *
 * <ul>
 * <li>Invoke {@code method} on the result of {@code createTest()}, and
 * throw any exceptions thrown by either operation.
 * <li>HOWEVER, if {@code method}'s {@code @Test} annotation has the {@code
 * expecting} attribute, return normally only if the previous step threw an
 * exception of the correct type, and throw an exception otherwise.
 * <li>HOWEVER, if {@code method}'s {@code @Test} annotation has the {@code
 * timeout} attribute, throw an exception if the previous step takes more
 * than the specified number of milliseconds.
 * <li>ALWAYS run all non-overridden {@code @Before} methods on this class
 * and superclasses before any of the previous steps; if any throws an
 * Exception, stop execution and pass the exception on.
 * <li>ALWAYS run all non-overridden {@code @After} methods on this class
 * and superclasses after any of the previous steps; all After methods are
 * always executed: exceptions thrown by previous steps are combined, if
 * necessary, with exceptions from After methods into a
 * {@link org.junit.runners.model.MultipleFailureException}.
 * <li>ALWAYS allow {@code @Rule} fields to modify the execution of the
 * above steps. A {@code Rule} may prevent all execution of the above steps,
 * or add additional behavior before and after, or modify thrown exceptions.
 * For more information, see {@link org.junit.rules.TestRule}
 * </ul>
 *
 * This can be overridden in subclasses, either by overriding this method,
 * or the implementations creating each sub-statement.
 */
protected Statement methodBlock(FrameworkMethod method) {
    Object test;
    try {
        test = new ReflectiveCallable() {
            @Override
            protected Object runReflectiveCall() throws Throwable {
                return createTest();
            }
        }.run();
    } catch (Throwable e) {
        return new Fail(e);
    }

    Statement statement = methodInvoker(method, test);
    statement = possiblyExpectingExceptions(method, test, statement);
    statement = withPotentialTimeout(method, test, statement);
    statement = withBefores(method, test, statement);
    statement = withAfters(method, test, statement);
    statement = withRules(method, test, statement);
    return statement;
}
 
Example #12
Source File: SpringJUnit4ClassRunner.java    From spring-analysis-note with MIT License 3 votes vote down vote up
/**
 * Augment the default JUnit behavior
 * {@linkplain #withPotentialRepeat with potential repeats} of the entire
 * execution chain.
 * <p>Furthermore, support for timeouts has been moved down the execution
 * chain in order to include execution of {@link org.junit.Before @Before}
 * and {@link org.junit.After @After} methods within the timed execution.
 * Note that this differs from the default JUnit behavior of executing
 * {@code @Before} and {@code @After} methods in the main thread while
 * executing the actual test method in a separate thread. Thus, the net
 * effect is that {@code @Before} and {@code @After} methods will be
 * executed in the same thread as the test method. As a consequence,
 * JUnit-specified timeouts will work fine in combination with Spring
 * transactions. However, JUnit-specific timeouts still differ from
 * Spring-specific timeouts in that the former execute in a separate
 * thread while the latter simply execute in the main thread (like regular
 * tests).
 * @see #methodInvoker(FrameworkMethod, Object)
 * @see #withBeforeTestExecutionCallbacks(FrameworkMethod, Object, Statement)
 * @see #withAfterTestExecutionCallbacks(FrameworkMethod, Object, Statement)
 * @see #possiblyExpectingExceptions(FrameworkMethod, Object, Statement)
 * @see #withBefores(FrameworkMethod, Object, Statement)
 * @see #withAfters(FrameworkMethod, Object, Statement)
 * @see #withRulesReflectively(FrameworkMethod, Object, Statement)
 * @see #withPotentialRepeat(FrameworkMethod, Object, Statement)
 * @see #withPotentialTimeout(FrameworkMethod, Object, Statement)
 */
@Override
protected Statement methodBlock(FrameworkMethod frameworkMethod) {
	Object testInstance;
	try {
		testInstance = new ReflectiveCallable() {
			@Override
			protected Object runReflectiveCall() throws Throwable {
				return createTest();
			}
		}.run();
	}
	catch (Throwable ex) {
		return new Fail(ex);
	}

	Statement statement = methodInvoker(frameworkMethod, testInstance);
	statement = withBeforeTestExecutionCallbacks(frameworkMethod, testInstance, statement);
	statement = withAfterTestExecutionCallbacks(frameworkMethod, testInstance, statement);
	statement = possiblyExpectingExceptions(frameworkMethod, testInstance, statement);
	statement = withBefores(frameworkMethod, testInstance, statement);
	statement = withAfters(frameworkMethod, testInstance, statement);
	statement = withRulesReflectively(frameworkMethod, testInstance, statement);
	statement = withPotentialRepeat(frameworkMethod, testInstance, statement);
	statement = withPotentialTimeout(frameworkMethod, testInstance, statement);
	return statement;
}
 
Example #13
Source File: SpringJUnit4ClassRunner.java    From java-technology-stack with MIT License 3 votes vote down vote up
/**
 * Augment the default JUnit behavior
 * {@linkplain #withPotentialRepeat with potential repeats} of the entire
 * execution chain.
 * <p>Furthermore, support for timeouts has been moved down the execution
 * chain in order to include execution of {@link org.junit.Before @Before}
 * and {@link org.junit.After @After} methods within the timed execution.
 * Note that this differs from the default JUnit behavior of executing
 * {@code @Before} and {@code @After} methods in the main thread while
 * executing the actual test method in a separate thread. Thus, the net
 * effect is that {@code @Before} and {@code @After} methods will be
 * executed in the same thread as the test method. As a consequence,
 * JUnit-specified timeouts will work fine in combination with Spring
 * transactions. However, JUnit-specific timeouts still differ from
 * Spring-specific timeouts in that the former execute in a separate
 * thread while the latter simply execute in the main thread (like regular
 * tests).
 * @see #methodInvoker(FrameworkMethod, Object)
 * @see #withBeforeTestExecutionCallbacks(FrameworkMethod, Object, Statement)
 * @see #withAfterTestExecutionCallbacks(FrameworkMethod, Object, Statement)
 * @see #possiblyExpectingExceptions(FrameworkMethod, Object, Statement)
 * @see #withBefores(FrameworkMethod, Object, Statement)
 * @see #withAfters(FrameworkMethod, Object, Statement)
 * @see #withRulesReflectively(FrameworkMethod, Object, Statement)
 * @see #withPotentialRepeat(FrameworkMethod, Object, Statement)
 * @see #withPotentialTimeout(FrameworkMethod, Object, Statement)
 */
@Override
protected Statement methodBlock(FrameworkMethod frameworkMethod) {
	Object testInstance;
	try {
		testInstance = new ReflectiveCallable() {
			@Override
			protected Object runReflectiveCall() throws Throwable {
				return createTest();
			}
		}.run();
	}
	catch (Throwable ex) {
		return new Fail(ex);
	}

	Statement statement = methodInvoker(frameworkMethod, testInstance);
	statement = withBeforeTestExecutionCallbacks(frameworkMethod, testInstance, statement);
	statement = withAfterTestExecutionCallbacks(frameworkMethod, testInstance, statement);
	statement = possiblyExpectingExceptions(frameworkMethod, testInstance, statement);
	statement = withBefores(frameworkMethod, testInstance, statement);
	statement = withAfters(frameworkMethod, testInstance, statement);
	statement = withRulesReflectively(frameworkMethod, testInstance, statement);
	statement = withPotentialRepeat(frameworkMethod, testInstance, statement);
	statement = withPotentialTimeout(frameworkMethod, testInstance, statement);
	return statement;
}