@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); }
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); } }
/** * 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; }
/** * 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); }
/** * 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); }
@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); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
@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); }
@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))); }
@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); }
@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); }
@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); }
/** * 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; }
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); }
protected Statement prepareBeforeClasses(TestClass extension, Statement base) { return new RunBefores( base, extension.getAnnotatedMethods(BeforeClass.class), null); }
protected Statement prepareBefores(TestClass extension, Statement base, Object target) { return new RunBefores( base, extension.getAnnotatedMethods(Before.class), target); }
@Override protected Statement withBeforeClasses(Statement statement) { List<FrameworkMethod> befores= getTestClass().getAnnotatedMethods(BeforePinpointPluginTest.class); return befores.isEmpty() ? statement : new RunBefores(statement, befores, null); }
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); }
protected Statement withSetupTeardownBefores(Object target, Statement statement) { List<FrameworkMethod> befores = getMethods(target.getClass(), Before.class); return befores.isEmpty() ? statement : new RunBefores(statement, befores, target); }
protected Statement withBeforeSetupTeardownClasses(Object setupTeardown, Statement statement) { List<FrameworkMethod> befores = getMethods(setupTeardown.getClass(), BeforeClass.class); return befores.isEmpty() ? statement : new RunBefores(statement, befores, null); }
/** * 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); }