Search in sources :

Example 36 with Statement

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

the class RedirectStdIn method apply.

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

        @Override
        public void evaluate() throws Throwable {
            final InputStream originalStdIn = System.in;
            initPipe();
            System.setIn(emulatedSystemIn);
            try {
                base.evaluate();
            } finally {
                System.setIn(originalStdIn);
                closePipe();
            }
        }
    };
}
Also used : Statement(org.junit.runners.model.Statement) PipedInputStream(java.io.PipedInputStream) InputStream(java.io.InputStream)

Example 37 with Statement

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

the class CustomRunner method methodBlock.

@Override
protected Statement methodBlock(final FrameworkMethod method) {
    return new Statement() {

        @Override
        public void evaluate() throws Throwable {
            if (isClassUnderTestLoaded) {
                throw new RuntimeException("Test Class should not be loaded");
            }
            final HelperTestRunner helperTestRunner = new HelperTestRunner(bootstrappedTestClass);
            final Method bootstrappedMethod = bootstrappedTestClass.getMethod(method.getName());
            final Statement statement = helperTestRunner.methodBlock(new FrameworkMethod(bootstrappedMethod));
            statement.evaluate();
        }
    };
}
Also used : Statement(org.junit.runners.model.Statement) FrameworkMethod(org.junit.runners.model.FrameworkMethod) Method(java.lang.reflect.Method) FrameworkMethod(org.junit.runners.model.FrameworkMethod)

Example 38 with Statement

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

the class AbstractHazelcastClassRunner method methodBlock.

@Override
protected Statement methodBlock(FrameworkMethod method) {
    Statement statement = super.methodBlock(method);
    Repeat repeatable = getRepeatable(method);
    if (repeatable == null || repeatable.value() < 2) {
        return statement;
    }
    return new TestRepeater(statement, method.getMethod(), repeatable.value());
}
Also used : Statement(org.junit.runners.model.Statement) EmptyStatement(com.hazelcast.util.EmptyStatement) Repeat(com.hazelcast.test.annotation.Repeat)

Example 39 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 40 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)

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