Search in sources :

Example 1 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 2 with Statement

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

the class ResourceTestRule method apply.

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

        @Override
        public void evaluate() throws Throwable {
            DropwizardTestResourceConfig.CONFIGURATION_REGISTRY.put(configuration.getId(), configuration);
            try {
                test = new JerseyTest() {

                    @Override
                    protected TestContainerFactory getTestContainerFactory() {
                        return configuration.testContainerFactory;
                    }

                    @Override
                    protected DeploymentContext configureDeployment() {
                        return ServletDeploymentContext.builder(new DropwizardTestResourceConfig(configuration)).initParam(ServletProperties.JAXRS_APPLICATION_CLASS, DropwizardTestResourceConfig.class.getName()).initParam(DropwizardTestResourceConfig.CONFIGURATION_ID, configuration.getId()).build();
                    }

                    @Override
                    protected void configureClient(ClientConfig clientConfig) {
                        final JacksonJsonProvider jsonProvider = new JacksonJsonProvider();
                        jsonProvider.setMapper(configuration.mapper);
                        configuration.clientConfigurator.accept(clientConfig);
                        clientConfig.register(jsonProvider);
                    }
                };
                test.setUp();
                base.evaluate();
            } finally {
                DropwizardTestResourceConfig.CONFIGURATION_REGISTRY.remove(configuration.getId());
                test.tearDown();
            }
        }
    };
}
Also used : DeploymentContext(org.glassfish.jersey.test.DeploymentContext) ServletDeploymentContext(org.glassfish.jersey.test.ServletDeploymentContext) JerseyTest(org.glassfish.jersey.test.JerseyTest) Statement(org.junit.runners.model.Statement) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) ClientConfig(org.glassfish.jersey.client.ClientConfig) TestContainerFactory(org.glassfish.jersey.test.spi.TestContainerFactory) InMemoryTestContainerFactory(org.glassfish.jersey.test.inmemory.InMemoryTestContainerFactory)

Example 3 with Statement

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

the class SessionRule method apply.

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

        @Override
        public void evaluate() throws Throwable {
            Map<Setting<?>, String> config = new HashMap<>();
            config.put(GraphDatabaseSettings.auth_enabled, Boolean.toString(authEnabled));
            gdb = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newImpermanentDatabase(config);
            DependencyResolver resolver = gdb.getDependencyResolver();
            Authentication authentication = authentication(resolver.resolveDependency(AuthManager.class), resolver.resolveDependency(UserManagerSupplier.class));
            boltFactory = new BoltFactoryImpl(gdb, new UsageData(null), NullLogService.getInstance(), resolver.resolveDependency(ThreadToStatementContextBridge.class), authentication, BoltConnectionTracker.NOOP, Config.defaults());
            boltFactory.start();
            try {
                base.evaluate();
            } finally {
                try {
                    if (runningMachines != null) {
                        runningMachines.forEach(BoltStateMachine::close);
                    }
                } catch (Throwable e) {
                    e.printStackTrace();
                }
                gdb.shutdown();
            }
        }
    };
}
Also used : UsageData(org.neo4j.udc.UsageData) HashMap(java.util.HashMap) AuthManager(org.neo4j.kernel.api.security.AuthManager) Statement(org.junit.runners.model.Statement) Setting(org.neo4j.graphdb.config.Setting) UserManagerSupplier(org.neo4j.kernel.api.security.UserManagerSupplier) DependencyResolver(org.neo4j.graphdb.DependencyResolver) BoltFactoryImpl(org.neo4j.bolt.v1.runtime.BoltFactoryImpl) BoltStateMachine(org.neo4j.bolt.v1.runtime.BoltStateMachine) Authentication(org.neo4j.bolt.security.auth.Authentication) BasicAuthentication(org.neo4j.bolt.security.auth.BasicAuthentication) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory)

Example 4 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 5 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)

Aggregations

Statement (org.junit.runners.model.Statement)406 Test (org.junit.Test)173 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)31 FrameworkMethod (org.junit.runners.model.FrameworkMethod)28 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)22 CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)19 Description (org.junit.runner.Description)19 TestRule (org.junit.rules.TestRule)17 ArrayList (java.util.ArrayList)16 AssumptionViolatedException (org.junit.internal.AssumptionViolatedException)15 Method (java.lang.reflect.Method)14 ExecutorService (java.util.concurrent.ExecutorService)14 Issue (org.jvnet.hudson.test.Issue)13 ByteArrayOutputStream (java.io.ByteArrayOutputStream)12 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)12 File (java.io.File)11 TimeUnit (java.util.concurrent.TimeUnit)10 MultipleFailureException (org.junit.runners.model.MultipleFailureException)9 HashMap (java.util.HashMap)8 AtomicReference (java.util.concurrent.atomic.AtomicReference)8