Bug 513756: [UnitTest] Starting Suites from the toolbar does not abort
Change-Id: I8d66c2f26bf80a5ee2b3d47f2eb5c4fb5d004121
diff --git a/plugins/org.eclipse.ease.modules.unittest.ui/src/org/eclipse/ease/modules/unittest/ui/handler/RunAllTests.java b/plugins/org.eclipse.ease.modules.unittest.ui/src/org/eclipse/ease/modules/unittest/ui/handler/RunAllTests.java
index a61c886..28ff36e 100644
--- a/plugins/org.eclipse.ease.modules.unittest.ui/src/org/eclipse/ease/modules/unittest/ui/handler/RunAllTests.java
+++ b/plugins/org.eclipse.ease.modules.unittest.ui/src/org/eclipse/ease/modules/unittest/ui/handler/RunAllTests.java
@@ -29,23 +29,26 @@
if (instance != null) {
final Object suite = instance.getCurrentState().get(TestSuiteSource.VARIABLE_TESTSUITE);
if (suite instanceof TestSuite) {
- updateSources((TestSuite) suite);
-
- ((TestSuite) suite).run();
+ if (updateSources((TestSuite) suite))
+ ((TestSuite) suite).run();
}
}
return null;
}
- protected void updateSources(final TestSuite suite) {
- PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().saveAllEditors(true);
+ protected boolean updateSources(final TestSuite suite) {
+ if (PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().saveAllEditors(true)) {
+ if (suite.getModel().isDirty()) {
+ final boolean reloadSuite = MessageDialog.openQuestion(Display.getDefault().getActiveShell(), "Test Suite change detected",
+ "Your test suite has changed.\nDo you want to reload suite data before test execution?");
+ if (reloadSuite)
+ suite.reset();
+ }
- if (suite.getModel().isDirty()) {
- final boolean reloadSuite = MessageDialog.openQuestion(Display.getDefault().getActiveShell(), "Test Suite change detected",
- "Your test suite has changed.\nDo you want to reload suite data before test execution?");
- if (reloadSuite)
- suite.reset();
- }
+ return true;
+
+ } else
+ return false;
}
}
diff --git a/plugins/org.eclipse.ease.modules.unittest.ui/src/org/eclipse/ease/modules/unittest/ui/handler/RunFailedTests.java b/plugins/org.eclipse.ease.modules.unittest.ui/src/org/eclipse/ease/modules/unittest/ui/handler/RunFailedTests.java
index 8ca2269..5f1861c 100644
--- a/plugins/org.eclipse.ease.modules.unittest.ui/src/org/eclipse/ease/modules/unittest/ui/handler/RunFailedTests.java
+++ b/plugins/org.eclipse.ease.modules.unittest.ui/src/org/eclipse/ease/modules/unittest/ui/handler/RunFailedTests.java
@@ -28,16 +28,15 @@
if (instance != null) {
final Object suite = instance.getCurrentState().get(TestSuiteSource.VARIABLE_TESTSUITE);
if (suite instanceof TestSuite) {
+ if (updateSources((TestSuite) suite)) {
+ ((TestSuite) suite).run(new ITestSetFilter() {
- updateSources((TestSuite) suite);
-
- ((TestSuite) suite).run(new ITestSetFilter() {
-
- @Override
- public boolean matches(final TestFile set) {
- return (set.getStatus() != TestStatus.PASS);
- }
- });
+ @Override
+ public boolean matches(final TestFile set) {
+ return (set.getStatus() != TestStatus.PASS);
+ }
+ });
+ }
}
}
diff --git a/plugins/org.eclipse.ease.modules.unittest.ui/src/org/eclipse/ease/modules/unittest/ui/handler/RunSelectedTests.java b/plugins/org.eclipse.ease.modules.unittest.ui/src/org/eclipse/ease/modules/unittest/ui/handler/RunSelectedTests.java
index 211f8dc..ed54c5b 100644
--- a/plugins/org.eclipse.ease.modules.unittest.ui/src/org/eclipse/ease/modules/unittest/ui/handler/RunSelectedTests.java
+++ b/plugins/org.eclipse.ease.modules.unittest.ui/src/org/eclipse/ease/modules/unittest/ui/handler/RunSelectedTests.java
@@ -38,55 +38,56 @@
final ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection) {
// save dirty editors
- PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().saveAllEditors(true);
+ if (PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().saveAllEditors(true)) {
- // collect test files to run
- final Collection<TestFile> testFiles = new HashSet<TestFile>();
- for (final Object element : ((IStructuredSelection) selection).toArray()) {
- if (element instanceof TestFile)
- testFiles.add((TestFile) element);
+ // collect test files to run
+ final Collection<TestFile> testFiles = new HashSet<>();
+ for (final Object element : ((IStructuredSelection) selection).toArray()) {
+ if (element instanceof TestFile)
+ testFiles.add((TestFile) element);
- else if (element instanceof TestSuite)
- testFiles.addAll(((TestSuite) element).getChildren());
+ else if (element instanceof TestSuite)
+ testFiles.addAll(((TestSuite) element).getChildren());
- else if (element instanceof IPath) {
- // we need to contact the context provider and extract all child nodes
- final IWorkbenchPart part = HandlerUtil.getActivePart(event);
- if (part instanceof UnitTestView) {
- final IContentProvider contentProvider = ((UnitTestView) part).getFileTreeViewer().getContentProvider();
+ else if (element instanceof IPath) {
+ // we need to contact the context provider and extract all child nodes
+ final IWorkbenchPart part = HandlerUtil.getActivePart(event);
+ if (part instanceof UnitTestView) {
+ final IContentProvider contentProvider = ((UnitTestView) part).getFileTreeViewer().getContentProvider();
- final LinkedList<Object> parentElements = new LinkedList<Object>();
- parentElements.add(element);
+ final LinkedList<Object> parentElements = new LinkedList<>();
+ parentElements.add(element);
- // iterate over tree nodes looking for leaves
- while (!parentElements.isEmpty()) {
- final Object parent = parentElements.removeFirst();
- for (final Object child : ((ITreeContentProvider) contentProvider).getChildren(parent)) {
- if (child instanceof TestFile)
- testFiles.add((TestFile) child);
- else
- parentElements.add(child);
+ // iterate over tree nodes looking for leaves
+ while (!parentElements.isEmpty()) {
+ final Object parent = parentElements.removeFirst();
+ for (final Object child : ((ITreeContentProvider) contentProvider).getChildren(parent)) {
+ if (child instanceof TestFile)
+ testFiles.add((TestFile) child);
+ else
+ parentElements.add(child);
+ }
}
}
}
}
- }
- // run test sets
- final TestSuiteSource instance = TestSuiteSource.getActiveInstance();
- if (instance != null) {
- final Object suite = instance.getCurrentState().get(TestSuiteSource.VARIABLE_TESTSUITE);
- if (suite instanceof TestSuite) {
+ // run test sets
+ final TestSuiteSource instance = TestSuiteSource.getActiveInstance();
+ if (instance != null) {
+ final Object suite = instance.getCurrentState().get(TestSuiteSource.VARIABLE_TESTSUITE);
+ if (suite instanceof TestSuite) {
- updateSources((TestSuite) suite);
+ updateSources((TestSuite) suite);
- ((TestSuite) suite).run(new ITestSetFilter() {
+ ((TestSuite) suite).run(new ITestSetFilter() {
- @Override
- public boolean matches(final TestFile set) {
- return testFiles.contains(set);
- }
- });
+ @Override
+ public boolean matches(final TestFile set) {
+ return testFiles.contains(set);
+ }
+ });
+ }
}
}
}