001    package org.junit.experimental.runners;
002    
003    import java.lang.reflect.Modifier;
004    import java.util.ArrayList;
005    import java.util.List;
006    
007    import org.junit.runners.Suite;
008    import org.junit.runners.model.RunnerBuilder;
009    
010    /**
011     * If you put tests in inner classes, Ant, for example, won't find them. By running the outer class
012     * with Enclosed, the tests in the inner classes will be run. You might put tests in inner classes
013     * to group them for convenience or to share constants. Abstract inner classes are ignored.
014     * <p>
015     * So, for example:
016     * <pre>
017     * &#064;RunWith(Enclosed.class)
018     * public class ListTests {
019     *     ...useful shared stuff...
020     *     public static class OneKindOfListTest {...}
021     *     public static class AnotherKind {...}
022     *     abstract public static class Ignored {...}
023     * }
024     * </pre>
025     */
026    public class Enclosed extends Suite {
027        /**
028         * Only called reflectively. Do not use programmatically.
029         */
030        public Enclosed(Class<?> klass, RunnerBuilder builder) throws Throwable {
031            super(builder, klass, filterAbstractClasses(klass.getClasses()));
032        }
033        
034        private static Class<?>[] filterAbstractClasses(final Class<?>[] classes) {     
035            final List<Class<?>> filteredList= new ArrayList<Class<?>>(classes.length);
036    
037            for (final Class<?> clazz : classes) {
038                if (!Modifier.isAbstract(clazz.getModifiers())) {
039                    filteredList.add(clazz);
040                }
041            }
042            
043            return filteredList.toArray(new Class<?>[filteredList.size()]);
044        }   
045    }