1 /******************************************************************************* 2 * Copyright (c) 2000, 2010 IBM Corporation and others. 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * IBM Corporation - initial API and implementation 13 *******************************************************************************/ 14 package org.eclipse.jdt.internal.junit.util; 15 16 import java.lang.reflect.InvocationTargetException; 17 import java.util.HashSet; 18 import java.util.Set; 19 20 import org.eclipse.core.runtime.CoreException; 21 import org.eclipse.core.runtime.IProgressMonitor; 22 23 import org.eclipse.jface.operation.IRunnableContext; 24 import org.eclipse.jface.operation.IRunnableWithProgress; 25 26 import org.eclipse.jdt.core.IJavaElement; 27 import org.eclipse.jdt.core.IType; 28 29 import org.eclipse.jdt.internal.junit.launcher.ITestKind; 30 31 32 /** 33 * Custom Search engine for suite() methods 34 * @see CoreTestSearchEngine 35 */ 36 public class TestSearchEngine extends CoreTestSearchEngine { 37 findTests(IRunnableContext context, final IJavaElement element, final ITestKind testKind)38 public static IType[] findTests(IRunnableContext context, final IJavaElement element, final ITestKind testKind) throws InvocationTargetException, InterruptedException { 39 final Set<IType> result= new HashSet<>(); 40 41 IRunnableWithProgress runnable= new IRunnableWithProgress() { 42 @Override 43 public void run(IProgressMonitor pm) throws InterruptedException, InvocationTargetException { 44 try { 45 testKind.getFinder().findTestsInContainer(element, result, pm); 46 } catch (CoreException e) { 47 throw new InvocationTargetException(e); 48 } 49 } 50 }; 51 context.run(true, true, runnable); 52 return result.toArray(new IType[result.size()]); 53 } 54 55 } 56