1 /******************************************************************************* 2 * Copyright (c) 2006, 2019 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 * David Saff (saff@mit.edu) - initial API and implementation 14 * (bug 102632: [JUnit] Support for JUnit 4.) 15 *******************************************************************************/ 16 17 package org.eclipse.jdt.internal.junit.runner; 18 19 import java.util.ArrayList; 20 import java.util.Iterator; 21 22 public class TestExecution { 23 private boolean fShouldStop = false; 24 25 private IListensToTestExecutions fExecutionListener; 26 27 private IClassifiesThrowables fClassifier; 28 29 private ArrayList<IStopListener> fStopListeners = new ArrayList<IStopListener>(); 30 TestExecution(IListensToTestExecutions listener, IClassifiesThrowables classifier)31 public TestExecution(IListensToTestExecutions listener, 32 IClassifiesThrowables classifier) { 33 fClassifier = classifier; 34 fExecutionListener = listener; 35 } 36 run(ITestReference[] suites)37 public void run(ITestReference[] suites) { 38 for (int i = 0; i < suites.length; i++) { 39 if (fShouldStop) 40 return; 41 suites[i].run(this); 42 } 43 } 44 shouldStop()45 public boolean shouldStop() { 46 return fShouldStop; 47 } 48 stop()49 public void stop() { 50 fShouldStop = true; 51 for (Iterator<IStopListener> iter = fStopListeners.iterator(); iter.hasNext();) { 52 IStopListener listener = iter.next(); 53 listener.stop(); 54 } 55 } 56 getListener()57 public IListensToTestExecutions getListener() { 58 return fExecutionListener; 59 } 60 getClassifier()61 public IClassifiesThrowables getClassifier() { 62 return fClassifier; 63 } 64 addStopListener(IStopListener listener)65 public void addStopListener(IStopListener listener) { 66 fStopListeners.add(listener); 67 } 68 } 69