• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 vogar.target.junit;
18 
19 import java.lang.annotation.Annotation;
20 import java.util.ArrayList;
21 import java.util.List;
22 import java.util.Set;
23 import junit.framework.TestCase;
24 import org.junit.runner.Runner;
25 import vogar.target.junit.junit3.TestCaseRunnerFactory;
26 
27 /**
28  * Extends {@link TestCaseRunnerFactory} to add support for explicitly requested methods.
29  */
30 public class VogarTestCaseRunnerFactory extends TestCaseRunnerFactory {
31 
32     private static final Annotation[] NO_ANNOTATIONS = new Annotation[0];
33     private final RunnerParams runnerParams;
34 
VogarTestCaseRunnerFactory(RunnerParams runnerParams)35     public VogarTestCaseRunnerFactory(RunnerParams runnerParams) {
36         super(runnerParams);
37         this.runnerParams = runnerParams;
38     }
39 
40     @Override
eagerClassValidation()41     public boolean eagerClassValidation() {
42         return false;
43     }
44 
45     @Override
createSuite( Class<? extends TestCase> testClass, List<DescribableStatement> tests)46     public Runner createSuite(
47             Class<? extends TestCase> testClass, List<DescribableStatement> tests) {
48 
49         Set<String> requestedMethodNames = JUnitUtils.mergeQualificationAndArgs(
50                 runnerParams.getQualification(), runnerParams.getArgs());
51         if (!requestedMethodNames.isEmpty()) {
52             // Ignore the tests list provided and create our own.
53             tests = new ArrayList<>();
54             for (String methodName : requestedMethodNames) {
55                 tests.add(createTest(testClass, methodName, NO_ANNOTATIONS));
56             }
57         }
58 
59         return super.createSuite(testClass, tests);
60     }
61 }
62