All Downloads are FREE. Search and download functionalities are using the official Maven repository.

patterntesting.concurrent.junit.internal.ParallelBuilder Maven / Gradle / Ivy

/*
 * $Id: ParallelBuilder.java,v 1.2 2012/07/08 19:04:05 oboehm Exp $
 *
 * Copyright (c) 2012 by Oliver Boehm
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express orimplied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * (c)reated 30.12.2011 by oliver ([email protected])
 */

package patterntesting.concurrent.junit.internal;

import org.junit.runner.Runner;
import org.junit.runners.model.RunnerBuilder;

import patterntesting.runtime.junit.internal.SmokeBuilder;
import patterntesting.runtime.util.Environment;

/**
 * This builder will return an Runner which start the JUnit test in background,
 * records the result and presents it, when they are needed
 * (http://hwellmann.blogspot.com/2009/12/running-parameterized-junit-tests-in.html
 * would be another approach to do it).
 * 
* If threads are disabled (see {@link Environment#areThreadsAllowed()} a * normal runner is used. I.e. in this case the JUnit test will be started * normal (and not in the background). * * @author oliver * @since 1.2 (30.12.2011) */ public class ParallelBuilder extends SmokeBuilder { /** * Instantiates a new parallel builder. * * @param builder the builder */ public ParallelBuilder(final RunnerBuilder builder) { super(builder); } /** * Runner for class. * * @param testClass the test class * @return the runner * @throws Throwable the throwable * @see patterntesting.runtime.junit.internal.SmokeBuilder#runnerForClass(java.lang.Class) */ @Override public Runner runnerForClass(Class testClass) throws Throwable { Runner runner = super.runnerForClass(testClass); if (Environment.areThreadsAllowed()) { BackgroundRunner bgRunner = new BackgroundRunner(runner); bgRunner.startRunner(); return bgRunner; } else { return runner; } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy