Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make tests consistent #175

Merged
merged 7 commits into from
Aug 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void renameClass(String newClassName) {

private void clickRename() {
SWTBotMenuHelper menuHelper = new SWTBotMenuHelper();
menuHelper.findMenu(bot.menu(REFACTOR), RENAME).click();
menuHelper.findMenu(menuHelper.findWorkbenchMenu(bot, REFACTOR), RENAME).click();
JKutscha marked this conversation as resolved.
Show resolved Hide resolved
}

public void renamePackage(String packageName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,14 @@ public RunMenu(SWTWorkbenchBot bot) {

public void runJUnit() {
SWTBotMenuHelper menuHelper = new SWTBotMenuHelper();
menuHelper.findMenu(bot.menu(RUN).menu(RUN_AS), JUNIT_TEST).click();
menuHelper.findMenu(menuHelper.findWorkbenchMenu(bot, RUN).menu(RUN_AS), JUNIT_TEST).click();
}

public void runPit() {
// focus package explorer to ensure the menu is found
bot.viewByTitle("Package Explorer").setFocus();
SWTBotMenuHelper menuHelper = new SWTBotMenuHelper();
SWTBotMenu runAsMenu = bot.menu(RUN)
.menu(RUN_AS);
SWTBotMenu runAsMenu = menuHelper.findWorkbenchMenu(bot, RUN).menu(RUN_AS);
menuHelper.findMenu(runAsMenu, PIT_MUTATION_TEST)
.click();

Expand Down Expand Up @@ -81,7 +80,7 @@ private void ensureSelectTestConfigurationDialogIsClosed() {

public List<PitRunConfiguration> runConfigurations() {
SWTBotMenuHelper menuHelper = new SWTBotMenuHelper();
menuHelper.findMenu(bot.menu(RUN), RUN_CONFIGURATIONS).click();
menuHelper.findMenu(menuHelper.findWorkbenchMenu(bot, RUN), RUN_CONFIGURATIONS).click();
return runConfigurationSelector.getConfigurations();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
import org.eclipse.swtbot.swt.finder.widgets.TimeoutException;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
Expand Down Expand Up @@ -166,23 +164,10 @@ private void runPitAndWaitForIt(Runnable runnable) {
assertNoErrorsInWorkspace();
// reset Summary result
PitSummary.INSTANCE.resetSummary();
int retryCount = 20;
int counter = 0;
while (counter < retryCount) {
try {
runnable.run();
PAGES.getRunMenu().runPit();
// wait for pit to finish
PitSummary.INSTANCE.waitForPitToFinish();
return;
} catch (TimeoutException te) {
counter++;
te.printStackTrace();
} catch (WidgetNotFoundException wfne) {
counter++;
wfne.printStackTrace();
}
}
runnable.run();
PAGES.getRunMenu().runPit();
// wait for pit to finish
PitSummary.INSTANCE.waitForPitToFinish();
}

public void assertNoErrorsInWorkspace() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@

import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
import org.eclipse.swtbot.swt.finder.results.Result;
import org.eclipse.swtbot.swt.finder.results.WidgetResult;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;

public class SWTBotMenuHelper {

private static final class MenuFinder implements WidgetResult<MenuItem> {
private final SWTBotMenu parentMenu;
private final String searchString;
Expand Down Expand Up @@ -64,4 +69,29 @@ public SWTBotMenu findMenu(final SWTBotMenu parentMenu,
return new SWTBotMenu(menuItem);
}
}

/**
* This method does not rely on the focus and gets the workbench shell and from
* that the asked menu. With this we can avoid to wait for focus and be sure we
* are getting the correct shell for the menus.
* @param bot which is used to get the display
* @param menuString which identifies the menu
* @return the asked menu
*/
public SWTBotMenu findWorkbenchMenu(final SWTWorkbenchBot bot, final String menuString) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be the case to write a well-documenting Javadoc here, in particular, the problems it fixes

return (new SWTBotShell(getActiveWorkbenchWindowShell(bot))).menu().menu(menuString);
}

private IWorkbenchWindow getActiveWorkbenchWindow(SWTWorkbenchBot bot) {
return UIThreadRunnable.syncExec(bot.getDisplay(), new Result<IWorkbenchWindow>() {
@Override
public IWorkbenchWindow run() {
return PlatformUI.getWorkbench().getActiveWorkbenchWindow();
}
});
}

private Shell getActiveWorkbenchWindowShell(SWTWorkbenchBot bot) {
return getActiveWorkbenchWindow(bot).getShell();
}
}