Home | History | Annotate | Download | only in junit
      1 /*
      2  * Copyright (C) 2016 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package android.icu.junit;
     18 
     19 import org.junit.runners.ParentRunner;
     20 import org.junit.runners.model.InitializationError;
     21 
     22 /**
     23  * Extends {@link ParentRunner} to prevent it from trying to create an instance of
     24  * {@link org.junit.runners.model.TestClass} for the supplied {@code testClass} because that
     25  * requires that the {@code testClass} has only a single constructor and at least one ICU test
     26  * ({@code android.icu.dev.test.serializable.CoverageTest}) has more than one constructor.
     27  *
     28  * <p>This provides a dummy class and overrides the {@link #getName()} method to return the
     29  * correct name. The consequence of this is that it is not possible to use JUnit 4 annotations
     30  * related to the class, like {@link org.junit.BeforeClass}, {@link org.junit.ClassRule}, etc.
     31  */
     32 abstract class IcuTestParentRunner<T> extends ParentRunner<T> {
     33 
     34     private final Class<?> testClass;
     35 
     36     IcuTestParentRunner(Class<?> testClass) throws InitializationError {
     37         super(DummyTestClass.class);
     38         this.testClass = testClass;
     39     }
     40 
     41     @Override
     42     protected String getName() {
     43         return testClass.getName();
     44     }
     45 
     46     /**
     47      * A dummy test class to pass to {@link ParentRunner} for it to validate and check for
     48      * annotations.
     49      *
     50      * <p>Must be public.
     51      */
     52     public static class DummyTestClass {
     53 
     54     }
     55 }
     56