Java 类org.junit.internal.runners.statements.Fail 实例源码

项目:easy-test    文件:EasyJUnit4.java   
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;
}
项目:spring4-understanding    文件:SpringJUnit4ClassRunner.java   
/**
 * 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;
}
项目:parameterized-suite    文件:BlockJUnit4ClassRunnerWithParametersUtil.java   
/**
 * Extends a given {@link Statement} for a {@link TestClass} with the evaluation of
 * {@link TestRule}, {@link ClassRule}, {@link Before} and {@link After}.
 * <p>
 * Therefore the test class will be instantiated and parameters will be injected with the same
 * mechanism as in {@link Parameterized}.
 * 
 * Implementation has been extracted from BlockJUnit4ClassRunner#methodBlock(FrameworkMethod).
 * 
 * @param baseStatementWithChildren - A {@link Statement} that includes execution of the test's
 *        children
 * @param testClass - The {@link TestClass} of the test.
 * @param description - The {@link Description} will be passed to the {@link Rule}s and
 *        {@link ClassRule}s.
 * @param singleParameter - The parameters will be injected in attributes annotated with
 *        {@link Parameterized.Parameter} or passed to the constructor otherwise.
 * 
 * @see BlockJUnit4ClassRunnerWithParameters#createTest()
 * @see BlockJUnit4ClassRunner#methodBlock(FrameworkMethod)
 */
public static Statement buildStatementWithTestRules(Statement baseStatementWithChildren, final TestClass testClass, Description description,
        final Object[] singleParameter) {
    final Object test;
    try {
        test = new ReflectiveCallable() {
            protected Object runReflectiveCall() throws Throwable {
                return createInstanceOfParameterizedTest(testClass, singleParameter);
            }
        }.run();
    } catch (Throwable e) {
        return new Fail(e);
    }

    List<TestRule> testRules = BlockJUnit4ClassRunnerUtil.getTestRules(test, testClass);
    Statement statement = BlockJUnit4ClassRunnerUtil.withTestRules(testRules, description, baseStatementWithChildren);

    statement = ParentRunnerUtil.withBeforeClasses(statement, testClass);
    statement = ParentRunnerUtil.withAfterClasses(statement, testClass);
    statement = ParentRunnerUtil.withClassRules(statement, testClass, description);
    return statement;
}
项目:jspare-container    文件:JspareUnitRunner.java   
/**
 * Augment the default JUnit behavior
 * <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 #possiblyExpectingExceptions(FrameworkMethod, Object, Statement)
 * @see #withBefores(FrameworkMethod, Object, Statement)
 * @see #withAfters(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);
  }

  Environment.inject(testInstance);

  Statement statement = methodInvoker(frameworkMethod, testInstance);
  statement = possiblyExpectingExceptions(frameworkMethod, testInstance, statement);
  statement = withBefores(frameworkMethod, testInstance, statement);
  statement = withAfters(frameworkMethod, testInstance, statement);
  statement = withPotentialTimeout(frameworkMethod, testInstance, statement);
  return statement;
}
项目:vertx-jspare    文件:VertxJspareUnitRunner.java   
@Override
protected Statement methodBlock(FrameworkMethod frameworkMethod) {
  testContext = new TestContextImpl(new HashMap<>(classAttributes), null);
  Object testInstance;
  try {
    testInstance = new ReflectiveCallable() {
      @Override
      protected Object runReflectiveCall() throws Throwable {
        return createTest();
      }
    }.run();
  } catch (Throwable ex) {
    return new Fail(ex);
  }

  Environment.inject(testInstance);

  Statement statement = methodInvoker(frameworkMethod, testInstance);
  statement = possiblyExpectingExceptions(frameworkMethod, testInstance, statement);
  statement = withBefores(frameworkMethod, testInstance, statement);
  statement = withAfters(frameworkMethod, testInstance, statement);
  statement = withPotentialTimeout(frameworkMethod, testInstance, statement);
  testContext = null;
  return statement;
}
项目:intellij-ce-playground    文件:GuiTestRunner.java   
@Override
protected Statement methodInvoker(final FrameworkMethod method, Object test) {
  if (canRunGuiTests()) {
    try {
      assertNotNull(myScreenshotTaker);
      return new MethodInvoker(method, test, myScreenshotTaker);
    }
    catch (Throwable e) {
      return new Fail(e);
    }
  }
  // Skip the test.
  return new Statement() {
    @Override
    public void evaluate() throws Throwable {
      String msg = String.format("Skipping test '%1$s'. UI tests cannot run in a headless environment.", method.getName());
      System.out.println(msg);
    }
  };
}
项目:FuzzUnit    文件:FuzzUnitTestRunner.java   
protected Statement methodBlock( FuzzUnitTestMethod testMethod )
{
        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( testMethod, test );
        statement = withRules( testMethod, test, statement );
        return statement;
}
项目:junit-clptr    文件:ClassLoaderPerTestRunner.java   
@Override
protected synchronized Statement methodBlock(FrameworkMethod method)
{
    FrameworkMethod newMethod = null;
    try
    {
        // Need the class from the custom loader now, so lets load the class.
        loadClassesWithCustomClassLoader( method );
        // The method as parameter is from the original class and thus not found in our
        // class loaded by the custom name (reflection is class loader sensitive)
        // So find the same method but now in the class from the class Loader.
        newMethod =
            new FrameworkMethod(
                    testClassFromClassLoader.getJavaClass().getMethod(method.getName()));
    }
    catch (Exception e)
    {
        // Show any problem nicely as a JUnit Test failure.
        return new Fail(e);
    }

    // We can carry out the normal JUnit functionality with our newly discoverd method now.
    return super.methodBlock(newMethod);
}
项目:contiperf    文件:BlockContiPerfClassRunner.java   
/**
    * method taken as is from BlockJUnit4ClassRunner 4.7 in order to preserve
    * its functionality over following versions
    */
   @Override
   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 = withRules(method, test, statement);
statement = withBefores(method, test, statement);
statement = withAfters(method, test, statement);
return statement;
   }
项目:cJUnit-mc626    文件:ConcurrentRunner.java   
@Override
protected Statement methodBlock(FrameworkMethod method) {
    if (!(method instanceof ConcurrentFrameworkMethod)) {
        return super.methodBlock(method);
    }
    ConcurrentFrameworkMethod concurrentFrameworkMethod
            = (ConcurrentFrameworkMethod) method;

    Object test;
    try {
        test = createTestObject();
    } catch (Throwable e) {
        return new Fail(e);
    }
    return buildStatements(concurrentFrameworkMethod, test);
}
项目:tomee    文件:MetaRunner.java   
@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;
}
项目:tomee    文件:ValidationRunner.java   
@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;
}
项目:multiverse-test    文件:UnfinalizingTestRunner.java   
/**
 * had to override this whole method to get enough overall control to wrap
 * all method invocations...  javadoc says that this can be overridden
 */
@Override
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;
}
项目:junit-hierarchicalcontextrunner    文件:MethodExecutor.java   
public void run(final TestClass testClass, final FrameworkMethod method, final RunNotifier notifier) {
    final Description description = describer.describe(method);
    if (method.getAnnotation(Ignore.class) != null) {
        notifier.fireTestIgnored(description);
    } else {
        try {
            final Stack<Class<?>> classHierarchy = getClassHierarchy(testClass.getJavaClass());
            final Object target = createDeepInstance(classHierarchy);

            Statement statement = buildStatement(testClass, method, target, description, notifier);
            for (final MethodStatementBuilder builder : statementBuilders) {
                statement = builder.createStatement(testClass, method, target, statement, description, notifier);
            }

            statementExecutor.execute(statement, notifier, description);
        } catch (Throwable t) {
            statementExecutor.execute(new Fail(t), notifier, description);
        }
    }
}
项目:apiman-test    文件:ApimanRunner.java   
@Override
protected Statement withBeforeClasses(Statement statement) {
    Object target;
    try {
        target = createTest();
    } catch (Exception e) {
        return new Fail(e);
    }

    List<FieldAnnotationHandler> chain = annotationFieldProcessChain(target);
    statement = super.withBeforeClasses(statement);
    return new RunApimanInitAnnotations(statement, chain, false, true);
}
项目:javatrove    文件:FunctionalTestRunner.java   
@Override
protected Statement withBefores(FrameworkMethod method, Object target, Statement statement) {
    try {
        resolveFailureCollectorRule(method);
    } catch (Exception e) {
        return new Fail(e);
    }
    return super.withBefores(method, target, statement);
}
项目:javatrove    文件:FunctionalTestRunner.java   
@Override
protected Statement withBefores(FrameworkMethod method, Object target, Statement statement) {
    try {
        resolveFailureCollectorRule(method);
    } catch (Exception e) {
        return new Fail(e);
    }
    return super.withBefores(method, target, statement);
}
项目:javatrove    文件:FunctionalTestRunner.java   
@Override
protected Statement withBefores(FrameworkMethod method, Object target, Statement statement) {
    try {
        resolveFailureCollectorRule(method);
    } catch (Exception e) {
        return new Fail(e);
    }
    return super.withBefores(method, target, statement);
}
项目:javatrove    文件:FunctionalTestRunner.java   
@Override
protected Statement withBefores(FrameworkMethod method, Object target, Statement statement) {
    try {
        resolveFailureCollectorRule(method);
    } catch (Exception e) {
        return new Fail(e);
    }
    return super.withBefores(method, target, statement);
}
项目:junit-composite-runner    文件:TestRunner.java   
private Statement methodBlock(FrameworkMethod method) {
    Object testObject;
    try {
        testObject = new ReflectiveCallable() {
            @Override
            protected Object runReflectiveCall() throws Throwable {
                return getTestClass().getOnlyConstructor().newInstance(new Object[0]);
            }
        }.run();
    } catch (Throwable throwable) {
        return new Fail(throwable);
    }

    return new InvokeMethod(method, testObject);
}
项目:class-guard    文件:SpringJUnit4ClassRunner.java   
/**
 * 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} and {@code &#064;After} methods
 * in the main thread while executing the actual test method in a separate
 * thread. Thus, the end effect is that {@code &#064;Before} and
 * {@code &#064;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. 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).
 * @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 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;
}
项目:junit-seasar2    文件:Seasar24.java   
@SuppressWarnings("deprecation")
@Override
protected Statement methodBlock(final 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 = withTransaction(method, test, statement);
    statement = possiblyExpectingExceptions(method, test, statement);
    statement = withPotentialTimeout(method, test, statement);
    statement = withFieldsBinding(method, test, statement);
    statement = withContainer(method, test, statement);
    statement = withBefores(method, test, statement);
    statement = withAfters(method, test, statement);
    statement = withContext(method, test, statement);
    statement = withRootContainer(method, test, statement);
    statement = withClassLoader(statement);
    statement = withRules(method, test, statement);
    return statement;
}
项目:tomee    文件:JUnit4Runner.java   
/**
 * 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);
    }
}
项目:tomee    文件:LocalClientRunner.java   
/**
 * 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);
    }
}
项目:junit-hierarchicalcontextrunner    文件:ContextExecutor.java   
public void run(final TestClass testClass, final Class<?> clazz, final RunNotifier notifier) {
    try {
        new HierarchicalContextRunner(clazz).run(notifier);
    } catch (final Throwable t) {
        statementExecutor.execute(new Fail(t), notifier, describer.describe(clazz));
    }
}
项目:junit-hierarchicalcontextrunner    文件:MethodExecutorTest.java   
@Test
public void whenStatementExecutorThrowsException_failureIsReportedAtTheNotifier() throws Exception {
    doThrow(new RuntimeException("")).when(statementExecutor).execute(statement2, notifier, description);

    methodExecutor.run(testClass, method, notifier);

    verify(statementExecutor).execute(isA(Fail.class), same(notifier), same(description));
    verifyNoMoreInteractions(notifier);
}
项目:RxRoboBase    文件:PlayServicesRule.java   
private static Statement fail(String message){
    return new Fail(new Exception(message));
}
项目:kc-rice    文件:LoadTimeWeavableTestRunner.java   
/**
 * 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;
}
项目:cloudera-framework    文件:TestRunner.java   
@Override
@SuppressWarnings("deprecation")
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);
  }
  boolean validated = true;
  for (CdhServer cdhServer : getTestClass().getAnnotatedFieldValues(test, ClassRule.class, CdhServer.class)) {
    validated = validated && cdhServer.isValid();
    if (validated) {
      for (CdhServer cdhServerDependency : cdhServer.getDependencies()) {
        validated = validated && cdhServerDependency.isValid();
      }
    }
  }
  Statement statement;
  if (validated) {
    statement = methodInvoker(method, test);
    statement = withLogging(method, test, statement);
    statement = possiblyExpectingExceptions(method, test, statement);
    statement = withPotentialTimeout(method, test, statement);
    statement = withBefores(method, test, statement);
    statement = withAfters(method, test, statement);
    statement = withServerRules(method, test, statement);
    statement = withRules(method, test, statement);
  } else {
    statement = new Statement() {
      @Override
      public void evaluate() throws Throwable {
        if (LOG.isWarnEnabled()) {
          LOG.warn("Skipping [" + method.getDeclaringClass().getCanonicalName() + "." + method.getName() + "], invalid classpath");
        }
      }
    };
  }
  return statement;
}
项目:sosiefier    文件:BlockJUnit4ClassRunner.java   
/**
 * 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 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 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;
}
项目:lcm    文件:BlockJUnit4ClassRunner.java   
/**
 * 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 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 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;
}
项目:rice    文件:LoadTimeWeavableTestRunner.java   
/**
 * 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;
}
项目:junit    文件:BlockJUnit4ClassRunner.java   
/**
 * 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 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 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;
}
项目:org.openntf.domino    文件:BlockJUnit4ClassRunner.java   
/**
 * 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 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 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;
}