Search in sources :

Example 31 with Statement

use of org.junit.runners.model.Statement in project alchemy-test by SirWellington.

the class AlchemyTestRunner method withBefores.

@Override
protected Statement withBefores(FrameworkMethod method, Object target, Statement statement) {
    Statement superStatement = super.withBefores(method, target, statement);
    return new Statement() {

        @Override
        public void evaluate() throws Throwable {
            if (shouldInitMocks) {
                MockitoAnnotations.initMocks(target);
            }
            TestClassInjectors.populateGeneratedFields(getTestClass(), target);
            superStatement.evaluate();
        }
    };
}
Also used : Statement(org.junit.runners.model.Statement)

Example 32 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 33 with Statement

use of org.junit.runners.model.Statement in project intellij-community by JetBrains.

the class GuiTestRunner method methodBlock.

@Override
protected Statement methodBlock(FrameworkMethod method) {
    FrameworkMethod newMethod;
    try {
        if (Arrays.stream(getTestClass().getAnnotations()).anyMatch(annotation -> annotation instanceof ParentPlugin)) {
            loadClassesWithNewPluginClassLoader();
        } else {
            loadClassesWithIdeClassLoader();
        }
        Method methodFromClassLoader = myTestClass.getJavaClass().getMethod(method.getName());
        newMethod = new FrameworkMethod(methodFromClassLoader);
    } catch (Exception e) {
        return new Fail(e);
    }
    Object test;
    try {
        test = new ReflectiveCallable() {

            @Override
            protected Object runReflectiveCall() throws Throwable {
                return createTest();
            }
        }.run();
    } catch (Throwable e) {
        return new Fail(e);
    }
    Statement statement = methodInvoker(newMethod, test);
    List<FrameworkMethod> beforeMethods = myTestClass.getAnnotatedMethods(Before.class);
    if (!beforeMethods.isEmpty()) {
        statement = new RunBefores(statement, beforeMethods, test);
    }
    List<FrameworkMethod> afterMethods = myTestClass.getAnnotatedMethods(After.class);
    if (!afterMethods.isEmpty()) {
        statement = new RunAfters(statement, afterMethods, test);
    }
    return statement;
}
Also used : RunAfters(org.junit.internal.runners.statements.RunAfters) ReflectiveCallable(org.junit.internal.runners.model.ReflectiveCallable) Statement(org.junit.runners.model.Statement) Method(java.lang.reflect.Method) FrameworkMethod(org.junit.runners.model.FrameworkMethod) RunBefores(org.junit.internal.runners.statements.RunBefores) FrameworkMethod(org.junit.runners.model.FrameworkMethod) AssumptionViolatedException(org.junit.internal.AssumptionViolatedException) Fail(org.junit.internal.runners.statements.Fail)

Example 34 with Statement

use of org.junit.runners.model.Statement in project beam by apache.

the class TestExecutorsTest method testSuccessfulTermination.

@Test
public void testSuccessfulTermination() throws Throwable {
    ExecutorService service = Executors.newSingleThreadExecutor();
    final TestExecutorService testService = TestExecutors.from(() -> service);
    final AtomicBoolean taskRan = new AtomicBoolean();
    testService.apply(new Statement() {

        @Override
        public void evaluate() throws Throwable {
            testService.submit(() -> taskRan.set(true));
        }
    }, null).evaluate();
    assertTrue(service.isTerminated());
    assertTrue(taskRan.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Statement(org.junit.runners.model.Statement) TestExecutorService(org.apache.beam.fn.harness.test.TestExecutors.TestExecutorService) TestExecutorService(org.apache.beam.fn.harness.test.TestExecutors.TestExecutorService) ExecutorService(java.util.concurrent.ExecutorService) Test(org.junit.Test)

Example 35 with Statement

use of org.junit.runners.model.Statement in project beam by apache.

the class TestExecutorsTest method testStatementFailurePropagatedCleanly.

@Test
public void testStatementFailurePropagatedCleanly() throws Throwable {
    ExecutorService service = Executors.newSingleThreadExecutor();
    final TestExecutorService testService = TestExecutors.from(() -> service);
    final RuntimeException exceptionToThrow = new RuntimeException();
    try {
        testService.apply(new Statement() {

            @Override
            public void evaluate() throws Throwable {
                throw exceptionToThrow;
            }
        }, null).evaluate();
        fail();
    } catch (RuntimeException thrownException) {
        assertSame(exceptionToThrow, thrownException);
    }
    assertTrue(service.isShutdown());
}
Also used : Statement(org.junit.runners.model.Statement) TestExecutorService(org.apache.beam.fn.harness.test.TestExecutors.TestExecutorService) TestExecutorService(org.apache.beam.fn.harness.test.TestExecutors.TestExecutorService) ExecutorService(java.util.concurrent.ExecutorService) Test(org.junit.Test)

Aggregations

Statement (org.junit.runners.model.Statement)138 Test (org.junit.Test)22 FrameworkMethod (org.junit.runners.model.FrameworkMethod)15 Method (java.lang.reflect.Method)11 AssumptionViolatedException (org.junit.internal.AssumptionViolatedException)11 Fail (org.junit.internal.runners.statements.Fail)9 Description (org.junit.runner.Description)8 TestRule (org.junit.rules.TestRule)7 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 MethodRule (org.junit.rules.MethodRule)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