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                @Override
035                protected String getName() {
036                    /*
037                     * #1320 The generated suite is not based on a real class so
038                     * only a 'null' description can be generated from it. This name
039                     * will be overridden here.
040                     */
041                    return "classes";
042                }
043            };
044        }
045    
046        /**
047         * Create a single-class runner for {@code testClass}, using {@code builder}
048         */
049        protected Runner getRunner(RunnerBuilder builder, Class<?> testClass) throws Throwable {
050            return builder.runnerForClass(testClass);
051        }
052    }