1 package org.junit.runner;
2 
3 import org.junit.runners.Suite;
4 import org.junit.runners.model.InitializationError;
5 import org.junit.runners.model.RunnerBuilder;
6 
7 /**
8  * Represents a strategy for computing runners and suites.
9  * WARNING: this class is very likely to undergo serious changes in version 4.8 and
10  * beyond.
11  *
12  * @since 4.6
13  */
14 public class Computer {
15     /**
16      * Returns a new default computer, which runs tests in serial order
17      */
serial()18     public static Computer serial() {
19         return new Computer();
20     }
21 
22     /**
23      * Create a suite for {@code classes}, building Runners with {@code builder}.
24      * Throws an InitializationError if Runner construction fails
25      */
getSuite(final RunnerBuilder builder, Class<?>[] classes)26     public Runner getSuite(final RunnerBuilder builder,
27             Class<?>[] classes) throws InitializationError {
28         return new Suite(new RunnerBuilder() {
29             @Override
30             public Runner runnerForClass(Class<?> testClass) throws Throwable {
31                 return getRunner(builder, testClass);
32             }
33         }, classes) {
34             @Override
35             protected String getName() {
36                 /*
37                  * #1320 The generated suite is not based on a real class so
38                  * only a 'null' description can be generated from it. This name
39                  * will be overridden here.
40                  */
41                 return "classes";
42             }
43         };
44     }
45 
46     /**
47      * Create a single-class runner for {@code testClass}, using {@code builder}
48      */
49     protected Runner getRunner(RunnerBuilder builder, Class<?> testClass) throws Throwable {
50         return builder.runnerForClass(testClass);
51     }
52 }
53