001 package org.junit.runner; 002 003 import org.junit.runners.Suite; 004 import org.junit.runners.model.InitializationError; 005 import org.junit.runners.model.RunnerBuilder; 006 007 /** 008 * Represents a strategy for computing runners and suites. 009 * WARNING: this class is very likely to undergo serious changes in version 4.8 and 010 * beyond. 011 * 012 * @since 4.6 013 */ 014 public class Computer { 015 /** 016 * Returns a new default computer, which runs tests in serial order 017 */ 018 public static Computer serial() { 019 return new Computer(); 020 } 021 022 /** 023 * Create a suite for {@code classes}, building Runners with {@code builder}. 024 * Throws an InitializationError if Runner construction fails 025 */ 026 public Runner getSuite(final RunnerBuilder builder, 027 Class<?>[] classes) throws InitializationError { 028 return new Suite(new RunnerBuilder() { 029 @Override 030 public Runner runnerForClass(Class<?> testClass) throws Throwable { 031 return getRunner(builder, testClass); 032 } 033 }, classes); 034 } 035 036 /** 037 * Create a single-class runner for {@code testClass}, using {@code builder} 038 */ 039 protected Runner getRunner(RunnerBuilder builder, Class<?> testClass) throws Throwable { 040 return builder.runnerForClass(testClass); 041 } 042 }