Search in sources :

Example 91 with Statement

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

the class RandomizedRunner method wrapExpectedExceptions.

/**
   * Wrap the given statement into another catching the expected exception, if declared.
   */
private Statement wrapExpectedExceptions(final Statement s, TestCandidate c) {
    Test ann = c.method.getAnnotation(Test.class);
    if (ann == null) {
        return s;
    }
    // If there's no expected class, don't wrap. Eh, None is package-private...
    final Class<? extends Throwable> expectedClass = ann.expected();
    if (expectedClass.getName().equals("org.junit.Test$None")) {
        return s;
    }
    return new Statement() {

        @Override
        public void evaluate() throws Throwable {
            try {
                s.evaluate();
            } catch (Throwable t) {
                if (!expectedClass.isInstance(t)) {
                    throw t;
                }
                // We caught something that was expected. No worries then.
                return;
            }
            // If we're here this means we passed the test that expected a failure.
            Assert.fail("Expected an exception but the test passed: " + expectedClass.getName());
        }
    };
}
Also used : Test(org.junit.Test) Statement(org.junit.runners.model.Statement)

Example 92 with Statement

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

the class SandboxTestRunner method classBlock.

@Override
protected Statement classBlock(RunNotifier notifier) {
    final Statement statement = childrenInvoker(notifier);
    return new Statement() {

        @Override
        public void evaluate() throws Throwable {
            try {
                statement.evaluate();
                for (Class<?> testClass : loadedTestClasses) {
                    invokeAfterClass(testClass);
                }
            } finally {
                afterClass();
                loadedTestClasses.clear();
            }
        }
    };
}
Also used : Statement(org.junit.runners.model.Statement)

Example 93 with Statement

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

the class GraphStoreFixture method apply.

@Override
public Statement apply(final Statement base, Description description) {
    final TestDirectory directory = TestDirectory.testDirectory(description.getTestClass());
    return super.apply(directory.apply(new Statement() {

        @Override
        public void evaluate() throws Throwable {
            GraphStoreFixture.this.directory = directory.graphDbDir();
            try {
                generateInitialData();
                start(GraphStoreFixture.this.directory);
                try {
                    base.evaluate();
                } finally {
                    stop();
                }
            } finally {
                GraphStoreFixture.this.directory = null;
            }
        }
    }, description), description);
}
Also used : TestDirectory(org.neo4j.test.rule.TestDirectory) Statement(org.junit.runners.model.Statement)

Example 94 with Statement

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

the class PinpointPluginTestSuite method classBlock.

protected Statement classBlock(final RunNotifier notifier) {
    Statement statement = childrenInvoker(notifier);
    if (!areAllChildrenIgnored()) {
        statement = withBeforeClasses(statement);
        statement = withAfterClasses(statement);
        statement = withClassRules(statement);
    }
    return statement;
}
Also used : Statement(org.junit.runners.model.Statement)

Example 95 with Statement

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

the class ForkedPinpointPluginTestRunner method methodBlock.

@Override
protected Statement methodBlock(FrameworkMethod method) {
    final Statement fromSuper = super.methodBlock(method);
    final boolean manageTraceObject = this.manageTraceObject && (method.getAnnotation(TraceObjectManagable.class) == null);
    return new Statement() {

        @Override
        public void evaluate() throws Throwable {
            PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
            verifier.initialize(manageTraceObject);
            try {
                fromSuper.evaluate();
            } finally {
                verifier.cleanUp(manageTraceObject);
            }
        }
    };
}
Also used : Statement(org.junit.runners.model.Statement) PluginTestVerifier(com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier)

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