Search in sources :

Example 6 with Statement

use of org.junit.runners.model.Statement in project buck by facebook.

the class BuckBlockJUnit4ClassRunner method methodBlock.

/**
   * Override the default timeout behavior so that when no timeout is specified in the {@link Test}
   * annotation, the timeout specified by the constructor will be used (if it has been set).
   */
@Override
protected Statement methodBlock(FrameworkMethod method) {
    Statement statement = super.methodBlock(method);
    // If the test class has a Timeout @Rule, then that should supersede the default timeout. The
    // same applies if it has a timeout value for the @Test annotation.
    long timeout = getTimeout(method);
    return new SameThreadFailOnTimeout(executor.get(), timeout, testName(method), statement);
}
Also used : Statement(org.junit.runners.model.Statement)

Example 7 with Statement

use of org.junit.runners.model.Statement in project hibernate-orm by hibernate.

the class CustomRunner method methodBlock.

@Override
protected Statement methodBlock(FrameworkMethod method) {
    log.info(Test.class.getSimpleName() + ": " + method.getName());
    final Statement originalMethodBlock = super.methodBlock(method);
    final ExtendedFrameworkMethod extendedFrameworkMethod = (ExtendedFrameworkMethod) method;
    return new FailureExpectedHandler(originalMethodBlock, testClassMetadata, extendedFrameworkMethod, testInstance);
}
Also used : Test(org.junit.Test) Statement(org.junit.runners.model.Statement)

Example 8 with Statement

use of org.junit.runners.model.Statement in project jsonschema2pojo by joelittlejohn.

the class Jsonschema2PojoRule method apply.

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

        @Override
        public void evaluate() throws Throwable {
            active = true;
            diagnostics = new ArrayList<Diagnostic<? extends JavaFileObject>>();
            boolean captureDiagnosticsStart = captureDiagnostics;
            try {
                File testRoot = methodNameDir(classNameDir(rootDirectory(), description.getClassName()), description.getMethodName());
                generateDir = new File(testRoot, "generate");
                compileDir = new File(testRoot, "compile");
                base.evaluate();
            } finally {
                generateDir = null;
                compileDir = null;
                classLoader = null;
                sourceDirInitialized = false;
                classesDirInitialized = false;
                captureDiagnostics = captureDiagnosticsStart;
                diagnostics = null;
                active = false;
            }
        }
    };
}
Also used : JavaFileObject(javax.tools.JavaFileObject) Statement(org.junit.runners.model.Statement) Diagnostic(javax.tools.Diagnostic) File(java.io.File)

Example 9 with Statement

use of org.junit.runners.model.Statement in project junit4 by junit-team.

the class ExpectExceptionTest method whenExpectingAssumptionViolatedExceptionStatementsThrowingSubclassShouldPass.

@Test
public void whenExpectingAssumptionViolatedExceptionStatementsThrowingSubclassShouldPass() {
    Statement delegate = new Fail(new AssumptionViolatedExceptionSubclass("expected"));
    ExpectException expectException = new ExpectException(delegate, AssumptionViolatedException.class);
    try {
        expectException.evaluate();
    // then no exception should be thrown
    } catch (Throwable e) {
        fail("should not throw anything, but was thrown: " + e);
    }
}
Also used : Statement(org.junit.runners.model.Statement) Test(org.junit.Test)

Example 10 with Statement

use of org.junit.runners.model.Statement in project junit4 by junit-team.

the class ExternalResourceRuleTest method shouldThrowMultipleFailureExceptionWhenTestFailsAndClosingResourceFails.

@Test
public void shouldThrowMultipleFailureExceptionWhenTestFailsAndClosingResourceFails() throws Throwable {
    // given
    ExternalResource resourceRule = new ExternalResource() {

        @Override
        protected void after() {
            throw new RuntimeException("simulating resource tear down failure");
        }
    };
    Statement failingTest = new Fail(new RuntimeException("simulated test failure"));
    Description dummyDescription = Description.createTestDescription("dummy test class name", "dummy test name");
    try {
        resourceRule.apply(failingTest, dummyDescription).evaluate();
        fail("ExternalResource should throw");
    } catch (MultipleFailureException e) {
        assertThat(e.getMessage(), allOf(containsString("simulated test failure"), containsString("simulating resource tear down failure")));
    }
}
Also used : Description(org.junit.runner.Description) MultipleFailureException(org.junit.runners.model.MultipleFailureException) Statement(org.junit.runners.model.Statement) Fail(org.junit.internal.runners.statements.Fail) Test(org.junit.Test)

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