Search in sources :

Example 16 with Statement

use of org.junit.runners.model.Statement in project neo4j by neo4j.

the class Neo4jWithSocket method apply.

@Override
public Statement apply(final Statement statement, final Description description) {
    Statement testMethod = new Statement() {

        @Override
        public void evaluate() throws Throwable {
            // If this is used as class rule then getMethodName() returns null, so use
            // getClassName() instead.
            String name = description.getMethodName() != null ? description.getMethodName() : description.getClassName();
            workingDirectory = testDirectory.directory(name);
            ensureDatabase(settings -> {
            });
            try {
                statement.evaluate();
            } finally {
                shutdownDatabase();
            }
        }
    };
    Statement testMethodWithBeforeAndAfter = super.apply(testMethod, description);
    return testDirectory.apply(testMethodWithBeforeAndAfter, description);
}
Also used : Statement(org.junit.runners.model.Statement)

Example 17 with Statement

use of org.junit.runners.model.Statement in project pinpoint by naver.

the class PinpointJUnit4ClassRunner method withBefores.

@Override
protected Statement withBefores(FrameworkMethod method, final Object target, Statement statement) {
    Statement before = super.withBefores(method, target, statement);
    BeforeCallbackStatement callbackStatement = new BeforeCallbackStatement(before, new Statement() {

        @Override
        public void evaluate() throws Throwable {
            setupBaseTest(target);
        }
    });
    return callbackStatement;
}
Also used : Statement(org.junit.runners.model.Statement)

Example 18 with Statement

use of org.junit.runners.model.Statement in project zipkin by openzipkin.

the class ExecJarRule method apply.

@Override
public Statement apply(Statement base, Description description) {
    return new Statement() {

        public void evaluate() throws Throwable {
            try {
                ProcessBuilder bootBuilder = new ProcessBuilder("java", "-jar", execJar);
                bootBuilder.environment().put("SERVER_PORT", String.valueOf(port()));
                bootBuilder.environment().putAll(environment);
                bootBuilder.redirectErrorStream(true);
                bootApp = bootBuilder.start();
                CountDownLatch startedOrCrashed = new CountDownLatch(1);
                Thread consoleReader = new Thread(() -> {
                    boolean foundStartMessage = false;
                    try (BufferedReader reader = new BufferedReader(new InputStreamReader(bootApp.getInputStream()))) {
                        String line;
                        while ((line = reader.readLine()) != null) {
                            if (line.indexOf("JVM running for") != -1) {
                                foundStartMessage = true;
                                startedOrCrashed.countDown();
                            }
                            console.add(line);
                        }
                    } catch (Exception e) {
                    } finally {
                        if (!foundStartMessage)
                            startedOrCrashed.countDown();
                    }
                });
                consoleReader.setDaemon(true);
                consoleReader.start();
                if (!startedOrCrashed.await(10, TimeUnit.SECONDS)) {
                    throw new AssumptionViolatedException("Took too long to start or crash");
                }
                base.evaluate();
            } finally {
                bootApp.destroy();
            }
        }
    };
}
Also used : InputStreamReader(java.io.InputStreamReader) AssumptionViolatedException(org.junit.AssumptionViolatedException) Statement(org.junit.runners.model.Statement) BufferedReader(java.io.BufferedReader) CountDownLatch(java.util.concurrent.CountDownLatch) AssumptionViolatedException(org.junit.AssumptionViolatedException) IOException(java.io.IOException)

Example 19 with Statement

use of org.junit.runners.model.Statement in project querydsl by querydsl.

the class HibernateTestRunner method rules.

@Override
protected List<MethodRule> rules(Object test) {
    verify(test instanceof HibernateTest, "In order to use the %s for %s, it should (directly or indirectly) implement %s", HibernateTestRunner.class.getSimpleName(), test.getClass(), HibernateTest.class);
    List<MethodRule> rules = super.rules(test);
    rules.add(new MethodRule() {

        @Override
        public Statement apply(final Statement base, FrameworkMethod method, final Object target) {
            return new Statement() {

                @Override
                public void evaluate() throws Throwable {
                    ((HibernateTest) target).setSession(session);
                    base.evaluate();
                }
            };
        }
    });
    return rules;
}
Also used : MethodRule(org.junit.rules.MethodRule) Statement(org.junit.runners.model.Statement) HibernateTest(com.querydsl.jpa.HibernateTest) FrameworkMethod(org.junit.runners.model.FrameworkMethod)

Example 20 with Statement

use of org.junit.runners.model.Statement in project querydsl by querydsl.

the class JPATestRunner method rules.

@Override
protected List<MethodRule> rules(Object test) {
    verify(test instanceof JPATest, "In order to use the %s for %s, it should (directly or indirectly) implement %s", JPATestRunner.class.getSimpleName(), test.getClass(), JPATest.class);
    List<MethodRule> rules = super.rules(test);
    rules.add(new MethodRule() {

        @Override
        public Statement apply(final Statement base, FrameworkMethod method, final Object target) {
            return new Statement() {

                @Override
                public void evaluate() throws Throwable {
                    ((JPATest) target).setEntityManager(entityManager);
                    base.evaluate();
                }
            };
        }
    });
    return rules;
}
Also used : JPATest(com.querydsl.jpa.JPATest) MethodRule(org.junit.rules.MethodRule) Statement(org.junit.runners.model.Statement) FrameworkMethod(org.junit.runners.model.FrameworkMethod)

Aggregations

Statement (org.junit.runners.model.Statement)129 Test (org.junit.Test)22 FrameworkMethod (org.junit.runners.model.FrameworkMethod)15 Method (java.lang.reflect.Method)10 AssumptionViolatedException (org.junit.internal.AssumptionViolatedException)10 Fail (org.junit.internal.runners.statements.Fail)9 TestRule (org.junit.rules.TestRule)7 Description (org.junit.runner.Description)7 MethodRule (org.junit.rules.MethodRule)6 MultipleFailureException (org.junit.runners.model.MultipleFailureException)6 ExecutorService (java.util.concurrent.ExecutorService)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 ReflectiveCallable (org.junit.internal.runners.model.ReflectiveCallable)5 ArrayList (java.util.ArrayList)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 EmptyStatement (com.hazelcast.util.EmptyStatement)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 TestExecutorService (org.apache.beam.fn.harness.test.TestExecutors.TestExecutorService)3 CompositeConfiguration (org.apache.logging.log4j.core.config.composite.CompositeConfiguration)3 LoggerContextRule (org.apache.logging.log4j.junit.LoggerContextRule)3