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

项目:geowave    文件:GeoWaveITRunner.java   
@Override
protected Statement withBeforeClasses(
        final Statement statement ) {
    // add test environment setup
    try {
        final Method setupMethod = GeoWaveITRunner.class.getDeclaredMethod("setup");
        setupMethod.setAccessible(true);
        return super.withBeforeClasses(new RunBefores(
                statement,
                Collections.singletonList(new FrameworkMethod(
                        setupMethod)),
                this));
    }
    catch (NoSuchMethodException | SecurityException e) {
        LOGGER.warn(
                "Unable to find setup method",
                e);
    }

    return super.withBeforeClasses(statement);
}
项目:pravega    文件:SystemTestRunner.java   
private Statement withEnvironment(Statement statement) {
    List<FrameworkMethod> environment = super.getTestClass().getAnnotatedMethods(Environment.class);
    if (environment.isEmpty()) {
        log.error("@Environment annotation not used for system test , {}", getTestClass().getName());
        return statement;
    } else {
        return new RunBefores(statement, environment, null);
    }
}
项目:dsl-devkit    文件:ClassRunner.java   
/**
 * Adds any @BeforeAll methods to be run before the normal @Before annotated methods for the first test method only.
 * <p>
 * {@inheritDoc}
 */
@Override
protected Statement withBefores(final FrameworkMethod method, final Object target, final Statement stmt) {
  ensureInitialized();
  Statement statement = super.withBefores(method, target, stmt); // NOPMD.CloseResource
  if (method.equals(expectedMethods.get(0))) {
    // reverse BeforeAll method order to get a 'runs top to bottom' order
    final List<FrameworkMethod> befores = Lists.reverse(getTestClass().getAnnotatedMethods(BeforeAll.class));
    statement = befores.isEmpty() ? statement : new RunBefores(statement, befores, target);
  }
  return statement;
}
项目:kc-rice    文件:LoadTimeWeavableTestRunner.java   
/**
 * Returns a {@link org.junit.runners.model.Statement}: run all non-overridden {@code @BeforeClass} methods on this class
 * and superclasses before executing {@code statement}; if any throws an
 * Exception, stop execution and pass the exception on.
 */
protected Statement withBeforeClasses(Statement statement) {
    List<FrameworkMethod> befores = getTestClass()
            .getAnnotatedMethods(BeforeClass.class);
    return befores.isEmpty() ? statement :
            new RunBefores(statement, befores, null);
}
项目:kc-rice    文件:LoadTimeWeavableTestRunner.java   
/**
 * Returns a {@link org.junit.runners.model.Statement}: run all non-overridden {@code @Before}
 * methods on this class and superclasses before running {@code next}; if
 * any throws an Exception, stop execution and pass the exception on.
 *
 * @deprecated Will be private soon: use Rules instead
 */
@Deprecated
protected Statement withBefores(FrameworkMethod method, Object target,
        Statement statement) {
    List<FrameworkMethod> befores = getTestClass().getAnnotatedMethods(Before.class);
    return befores.isEmpty() ? statement : new RunBefores(statement,
            befores, target);
}
项目:junit-clptr    文件:ClassLoaderPerTestRunner.java   
@Override
protected synchronized Statement withBefores(FrameworkMethod method, Object target, Statement statement)
{
    // We now to need to search in the class from the custom loader.
    //We also need to search with the annotation loaded by the custom class loader or otherwise we don't find any method.
    List<FrameworkMethod> befores =
        testClassFromClassLoader
            .getAnnotatedMethods((Class<? extends Annotation>) beforeFromClassLoader);

    return new RunBefores(statement, befores, target);
}
项目:j2objc    文件:ParentRunner.java   
/**
 * Returns a {@link Statement}: run all non-overridden {@code @BeforeClass} methods on this class
 * and superclasses before executing {@code statement}; if any throws an
 * Exception, stop execution and pass the exception on.
 */
protected Statement withBeforeClasses(Statement statement) {
    List<FrameworkMethod> befores= fTestClass
            .getAnnotatedMethods(BeforeClass.class);
    return befores.isEmpty() ? statement :
        new RunBefores(statement, befores, null);
}
项目:sosiefier    文件:BlockJUnit4ClassRunner.java   
/**
 * Returns a {@link Statement}: run all non-overridden {@code @Before}
 * methods on this class and superclasses before running {@code next}; if
 * any throws an Exception, stop execution and pass the exception on.
 */
protected Statement withBefores(FrameworkMethod method, Object target,
        Statement statement) {
    List<FrameworkMethod> befores = getTestClass().getAnnotatedMethods(
            Before.class);
    return befores.isEmpty() ? statement : new RunBefores(statement,
            befores, target);
}
项目:sosiefier    文件:ParentRunner.java   
/**
 * Returns a {@link Statement}: run all non-overridden {@code @BeforeClass} methods on this class
 * and superclasses before executing {@code statement}; if any throws an
 * Exception, stop execution and pass the exception on.
 */
protected Statement withBeforeClasses(Statement statement) {
    List<FrameworkMethod> befores = fTestClass
            .getAnnotatedMethods(BeforeClass.class);
    return befores.isEmpty() ? statement :
            new RunBefores(statement, befores, null);
}
项目:lcm    文件:BlockJUnit4ClassRunner.java   
/**
 * Returns a {@link Statement}: run all non-overridden {@code @Before}
 * methods on this class and superclasses before running {@code next}; if
 * any throws an Exception, stop execution and pass the exception on.
 *
 * @deprecated Will be private soon: use Rules instead
 */
@Deprecated
protected Statement withBefores(FrameworkMethod method, Object target,
        Statement statement) {
    List<FrameworkMethod> befores = getTestClass().getAnnotatedMethods(
            Before.class);
    return befores.isEmpty() ? statement : new RunBefores(statement,
            befores, target);
}
项目:lcm    文件:ParentRunner.java   
/**
 * Returns a {@link Statement}: run all non-overridden {@code @BeforeClass} methods on this class
 * and superclasses before executing {@code statement}; if any throws an
 * Exception, stop execution and pass the exception on.
 */
protected Statement withBeforeClasses(Statement statement) {
    List<FrameworkMethod> befores = fTestClass
            .getAnnotatedMethods(BeforeClass.class);
    return befores.isEmpty() ? statement :
            new RunBefores(statement, befores, null);
}
项目:rice    文件:LoadTimeWeavableTestRunner.java   
/**
 * Returns a {@link org.junit.runners.model.Statement}: run all non-overridden {@code @BeforeClass} methods on this class
 * and superclasses before executing {@code statement}; if any throws an
 * Exception, stop execution and pass the exception on.
 */
protected Statement withBeforeClasses(Statement statement) {
    List<FrameworkMethod> befores = getTestClass()
            .getAnnotatedMethods(BeforeClass.class);
    return befores.isEmpty() ? statement :
            new RunBefores(statement, befores, null);
}
项目:rice    文件:LoadTimeWeavableTestRunner.java   
/**
 * Returns a {@link org.junit.runners.model.Statement}: run all non-overridden {@code @Before}
 * methods on this class and superclasses before running {@code next}; if
 * any throws an Exception, stop execution and pass the exception on.
 *
 * @deprecated Will be private soon: use Rules instead
 */
@Deprecated
protected Statement withBefores(FrameworkMethod method, Object target,
        Statement statement) {
    List<FrameworkMethod> befores = getTestClass().getAnnotatedMethods(Before.class);
    return befores.isEmpty() ? statement : new RunBefores(statement,
            befores, target);
}
项目:multiverse-test    文件:UnfinalizingTestRunner.java   
/**
 * Returns a {@link Statement}: run all non-overridden {@code @Before}
 * methods on this class and superclasses before running {@code next}; if
 * any throws an Exception, stop execution and pass the exception on.
 * 
 * @deprecated Will be private soon: use Rules instead
 */
@Override
protected Statement withBefores(FrameworkMethod method, Object target,
        Statement statement) {
    List<FrameworkMethod> befores= getTestClass().getAnnotatedMethods(
            Before.class);
    befores = convert(befores);
    return befores.isEmpty() ? statement : new RunBefores(statement,
            befores, target);
}
项目:multiverse-test    文件:UnfinalizingTestRunner.java   
@Override
protected Statement withBeforeClasses(Statement statement) {
    List<FrameworkMethod> befores = getTestClass().getAnnotatedMethods(BeforeClass.class);
    befores = convert(befores);
    return befores.isEmpty() ? statement :
        new RunBefores(statement, befores, null);
}
项目:junit-hierarchicalcontextrunner    文件:BeforeClassStatementBuilderTest.java   
@Test
public void givenTestClassWithBeforeClassAnnotatedMethods_returnsRunBeforeStatement() throws Exception {
    List<FrameworkMethod> befores = Arrays.asList(method1, method2);
    when(testClass.getAnnotatedMethods(BeforeClass.class)).thenReturn(befores);

    Statement actual = builder.createStatement(testClass, next, description, notifier);
    assertThat(actual, is(instanceOf(RunBefores.class)));
}
项目:junit    文件:BlockJUnit4ClassRunner.java   
/**
 * Returns a {@link Statement}: run all non-overridden {@code @Before}
 * methods on this class and superclasses before running {@code next}; if
 * any throws an Exception, stop execution and pass the exception on.
 *
 * @deprecated Will be private soon: use Rules instead
 */
@Deprecated
protected Statement withBefores(FrameworkMethod method, Object target,
        Statement statement) {
    List<FrameworkMethod> befores = getTestClass().getAnnotatedMethods(
            Before.class);
    return befores.isEmpty() ? statement : new RunBefores(statement,
            befores, target);
}
项目:junit    文件:ParentRunner.java   
/**
 * Returns a {@link Statement}: run all non-overridden {@code @BeforeClass} methods on this class
 * and superclasses before executing {@code statement}; if any throws an
 * Exception, stop execution and pass the exception on.
 */
protected Statement withBeforeClasses(Statement statement) {
    List<FrameworkMethod> befores = fTestClass
            .getAnnotatedMethods(BeforeClass.class);
    return befores.isEmpty() ? statement :
            new RunBefores(statement, befores, null);
}
项目:org.openntf.domino    文件:BlockJUnit4ClassRunner.java   
/**
 * Returns a {@link Statement}: run all non-overridden {@code @Before}
 * methods on this class and superclasses before running {@code next}; if
 * any throws an Exception, stop execution and pass the exception on.
 *
 * @deprecated Will be private soon: use Rules instead
 */
@Deprecated
protected Statement withBefores(FrameworkMethod method, Object target,
        Statement statement) {
    List<FrameworkMethod> befores = getTestClass().getAnnotatedMethods(
            Before.class);
    return befores.isEmpty() ? statement : new RunBefores(statement,
            befores, target);
}
项目:org.openntf.domino    文件:ParentRunner.java   
/**
 * Returns a {@link Statement}: run all non-overridden {@code @BeforeClass} methods on this class
 * and superclasses before executing {@code statement}; if any throws an
 * Exception, stop execution and pass the exception on.
 */
protected Statement withBeforeClasses(Statement statement) {
    List<FrameworkMethod> befores = fTestClass
            .getAnnotatedMethods(BeforeClass.class);
    return befores.isEmpty() ? statement :
            new RunBefores(statement, befores, null);
}
项目:xtf    文件:XTFTestSuite.java   
@Override
@SneakyThrows(NoSuchMethodException.class)
protected Statement withBeforeClasses(Statement statement) {
    final FrameworkMethod fm = new FrameworkMethod(XTFTestSuite.class.getDeclaredMethod("beforeSuite"));
    return new RunBefores(statement, join(fm, getTestClass().getAnnotatedMethods(BeforeClass.class), true), null);
}
项目:aspectj-junit-runner    文件:AspectJUnit4Runner.java   
@Override
protected Statement withBeforeClasses(Statement statement) {
    Class<? extends Annotation> beforeClass = loadClassFromClassLoader(BeforeClass.class, cl);
       List<FrameworkMethod> befores = testClass.getAnnotatedMethods(beforeClass);
       return befores.isEmpty() ? statement : new RunBefores(statement, befores, null);
   }
项目:aspectj-junit-runner    文件:AspectJUnit4Runner.java   
@Override
protected Statement withBefores(FrameworkMethod method, Object target, Statement statement) {
    Class<? extends Annotation> before = loadClassFromClassLoader(Before.class, cl);
       List<FrameworkMethod> befores = getTestClass().getAnnotatedMethods(before);
       return befores.isEmpty() ? statement : new RunBefores(statement, befores, target);
   }
项目:blaze-storage    文件:DatabaseAwareArquillianRunner.java   
/**
 * Manages CDI-Contexts to be started before entering end stopped after exiting a Statement.
 * Additionally it is aware of the DatabaseAware, DatabaseUnaware and BeforeDatabaseAware annotations.
 * It creates an EntityManagerFactory before entering the test method and closes it after exiting
 * to always have a clean state of the database.
 */
@Override
protected List<TestRule> getTestRules(final Object target) {
    List<TestRule> rules = new ArrayList<TestRule>(super.getTestRules(target));
    rules.add(new TestRule() {

        @Override
        public Statement apply(final Statement base, final Description description) {
            final DatabaseAware databaseAwareAnnotation;

            if (description.getAnnotation(DatabaseUnaware.class) != null) {
                databaseAwareAnnotation = null;
            } else if (description.getAnnotation(DatabaseAware.class) != null) {
                databaseAwareAnnotation = description.getAnnotation(DatabaseAware.class);
            } else {
                databaseAwareAnnotation = AnnotationUtils.findAnnotation(target.getClass(), DatabaseAware.class);
            }

            List<FrameworkMethod> befores = new ArrayList<FrameworkMethod>(0);

            if (databaseAwareAnnotation != null) {
                for (FrameworkMethod m : getTestClass().getAnnotatedMethods(BeforeDatabaseAware.class)) {
                    if (databaseAwareAnnotation.unitName().equals(m.getAnnotation(BeforeDatabaseAware.class).unitName())) {
                        befores.add(m);
                    }
                }
            }

            final Statement statement = befores.isEmpty() ? base : new RunBefores(base, befores, target);

            return new Statement() {

                @Override
                public void evaluate() throws Throwable {
                    EntityManagerFactory emf = null;

                    try {

                        if (databaseAwareAnnotation != null) {
                            Map<String, String> properties = new HashMap<String, String>();
                            properties.put("hibernate.hbm2ddl.auto", "create-drop");
                            properties.put("hibernate.ejb.entitymanager_factory_name", databaseAwareAnnotation.unitName()
                                + testRun++);

                            emf = Persistence.createEntityManagerFactory(databaseAwareAnnotation.unitName(), properties);
                        }

                        statement.evaluate();
                    } catch (Throwable e) {
                        // We do some exception unwrapping here to get the real exception
                        @SuppressWarnings("unchecked")
                        Throwable ex = ExceptionUtils.unwrap(e, InvocationTargetException.class, EJBException.class,
                                                             TransactionRolledbackException.class);
                        throw ex;
                    } finally {
                        if (emf != null && emf.isOpen()) {
                            emf.close();
                        }

                    }
                }
            };
        }
    });
    return rules;
}
项目:components    文件:RunBeforesContiPerfAdapter.java   
public static RunBeforesContiPerfAdapter create(RunBefores runBefores, Statement next)
        throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
    List<FrameworkMethod> befores = ReflectionUtils.getObjectByField(runBefores, runBefores.getClass(), "befores");
    Object target = ReflectionUtils.getObjectByField(runBefores, runBefores.getClass(), "target");
    return new RunBeforesContiPerfAdapter(next, befores, target);
}
项目:lightblue-client    文件:BeforeAfterTestRule.java   
protected Statement prepareBeforeClasses(TestClass extension, Statement base) {
    return new RunBefores(
            base, extension.getAnnotatedMethods(BeforeClass.class), null);
}
项目:lightblue-client    文件:BeforeAfterTestRule.java   
protected Statement prepareBefores(TestClass extension, Statement base, Object target) {
    return new RunBefores(
            base, extension.getAnnotatedMethods(Before.class), target);
}
项目:lightblue-hibernate-ogm    文件:BeforeAfterTestRule.java   
protected Statement prepareBeforeClasses(TestClass extension, Statement base) {
    return new RunBefores(
            base, extension.getAnnotatedMethods(BeforeClass.class), null);
}
项目:lightblue-hibernate-ogm    文件:BeforeAfterTestRule.java   
protected Statement prepareBefores(TestClass extension, Statement base, Object target) {
    return new RunBefores(
            base, extension.getAnnotatedMethods(Before.class), target);
}
项目:pinpoint    文件:AbstractPinpointPluginTestSuite.java   
@Override
protected Statement withBeforeClasses(Statement statement) {
    List<FrameworkMethod> befores= getTestClass().getAnnotatedMethods(BeforePinpointPluginTest.class);
    return befores.isEmpty() ? statement : new RunBefores(statement, befores, null);
}
项目:junit-hierarchicalcontextrunner    文件:BeforeClassStatementBuilder.java   
public Statement createStatement(final TestClass testClass, final Statement next,
                                 final Description description, final RunNotifier notifier) {
    final List<FrameworkMethod> befores = testClass.getAnnotatedMethods(BeforeClass.class);
    return befores.isEmpty() ? next : new RunBefores(next, befores, null);
}
项目:confit    文件:FeatureTestsRunner.java   
protected Statement withSetupTeardownBefores(Object target, Statement statement) {
    List<FrameworkMethod> befores = getMethods(target.getClass(), Before.class);
    return befores.isEmpty() ? statement : new RunBefores(statement, befores, target);
}
项目:confit    文件:FeatureTestsRunner.java   
protected Statement withBeforeSetupTeardownClasses(Object setupTeardown, Statement statement) {
    List<FrameworkMethod> befores = getMethods(setupTeardown.getClass(), BeforeClass.class);
    return befores.isEmpty() ? statement : new RunBefores(statement, befores, null);
}
项目:parameterized-suite    文件:ParentRunnerUtil.java   
/**
 * Returns a {@link Statement}: run all non-overridden {@code @BeforeClass} methods on this class
 * and superclasses before executing {@code statement}; if any throws an
 * Exception, stop execution and pass the exception on.
 * 
 * @see ParentRunner#withBeforeClasses(org.junit.runners.model.Statement)
 */
public static Statement withBeforeClasses(Statement statement, TestClass testClass) {
    List<FrameworkMethod> befores = testClass
            .getAnnotatedMethods(BeforeClass.class);
    return befores.isEmpty() ? statement :
            new RunBefores(statement, befores, null);
}