1 /* 2 * Copyright (C) 2022 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 package vogar.target.testng; 17 18 import vogar.monitor.TargetMonitor; 19 import vogar.target.RunnerFactory; 20 import vogar.target.TargetRunner; 21 import vogar.target.TestEnvironment; 22 23 import java.util.concurrent.atomic.AtomicReference; 24 25 import javax.annotation.Nullable; 26 27 public class TestNgRunnerFactory implements RunnerFactory { 28 29 @Nullable 30 @Override newRunner( TargetMonitor monitor, String qualification, Class<?> klass, AtomicReference<String> skipPastReference, TestEnvironment testEnvironment, int timeoutSeconds, String[] excludeFilters, String[] args)31 public TargetRunner newRunner( 32 TargetMonitor monitor, 33 String qualification, 34 Class<?> klass, 35 AtomicReference<String> skipPastReference, 36 TestEnvironment testEnvironment, 37 int timeoutSeconds, 38 String[] excludeFilters, 39 String[] args) { 40 if (supports(klass)) { 41 return new TestNgTargetRunner( 42 monitor, 43 skipPastReference, 44 testEnvironment, 45 timeoutSeconds, 46 klass, 47 qualification, 48 excludeFilters, 49 args); 50 } else { 51 return null; 52 } 53 } 54 supports(Class<?> klass)55 private static boolean supports(Class<?> klass) { 56 return TestNg.isTestNgTest(klass); 57 } 58 } 59