From a2d2793bd31961d14c3bcd93bbbfbcc221f35dee Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Thu, 25 Aug 2022 11:15:45 +0200 Subject: [PATCH] 205: test when two elements are selected Task-Url: https://github.com/pitest/pitclipse/issues/205 --- .../pageobjects/NoTestsFoundDialog.java | 41 +++++++++++++++++++ .../pageobjects/PackageExplorer.java | 6 +++ .../ui/tests/PitclipseUiRunnerTest.java | 10 +++++ 3 files changed, 57 insertions(+) create mode 100644 tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/NoTestsFoundDialog.java diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/NoTestsFoundDialog.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/NoTestsFoundDialog.java new file mode 100644 index 00000000..3552c220 --- /dev/null +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/NoTestsFoundDialog.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright 2022 Lorenzo Bettini and contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy + * of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + ******************************************************************************/ + +package org.pitest.pitclipse.ui.behaviours.pageobjects; + +import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; +import org.eclipse.swtbot.swt.finder.waits.Conditions; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; + +public class NoTestsFoundDialog { + + private final SWTWorkbenchBot bot; + + public NoTestsFoundDialog(SWTWorkbenchBot bot) { + this.bot = bot; + } + + public void assertAppears() { + SWTBotShell shell = bot.shell("Pitclipse"); + shell.activate(); + bot.label("No tests found"); + bot.button("OK").click(); + + // Ensure the project is fully created before moving on + bot.waitUntil(Conditions.shellCloses(shell)); + } + +} diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PackageExplorer.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PackageExplorer.java index ab7bfd9b..a4e77dfd 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PackageExplorer.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/behaviours/pageobjects/PackageExplorer.java @@ -119,6 +119,12 @@ public void selectClass(String className, String packageName, String projectName selectAndExpand(classItem); } + public void selectFiles(String projectName, String packageName, String... fileNames) { + SWTBotTreeItem project = getProject(projectName); + SWTBotTreeItem pkg = selectAndExpand(getPackageFromProject(project, packageName)); + pkg.select(fileNames); + } + public boolean doesClassExistInProject(String className, String packageName, String projectName) { SWTBotTreeItem project = getProject(projectName); SWTBotTreeItem pkg = selectAndExpand(getPackageFromProject(project, packageName)); diff --git a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java index 759919f3..2e9a4512 100644 --- a/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java +++ b/tests/org.pitest.pitclipse.ui.tests/src/org/pitest/pitclipse/ui/tests/PitclipseUiRunnerTest.java @@ -1,5 +1,7 @@ package org.pitest.pitclipse.ui.tests; +import static org.pitest.pitclipse.ui.behaviours.pageobjects.PageObjects.PAGES; + import java.util.Collections; import org.eclipse.core.runtime.CoreException; @@ -7,6 +9,7 @@ import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; +import org.pitest.pitclipse.ui.behaviours.pageobjects.NoTestsFoundDialog; /** * @author Lorenzo Bettini @@ -124,4 +127,11 @@ public void runPitAtPackageAndPackageRootAndProjectLevel() throws CoreException coverageReportGenerated(1, 100, 100, 2, 2); } + @Test + public void runPitOnTwoSelectedElementsShowDialogNoTestsFound() throws CoreException { + PAGES.getPackageExplorer().selectFiles(TEST_PROJECT, FOO_BAR_PACKAGE, + FOO_CLASS + ".java", FOO_TEST_CLASS + ".java"); + PAGES.getRunMenu().runPit(); + new NoTestsFoundDialog(bot).assertAppears(); + } }