From f010f9ba4ab142ac087335e471e518ac7faf9bf8 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 19 Apr 2024 13:35:44 +0200 Subject: [PATCH] Add test for PMD Preferences / Rule Configuration --- .../br/PMDPreferencePage2Test.java | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 net.sourceforge.pmd.eclipse.plugin.test/src/main/java/net/sourceforge/pmd/eclipse/ui/preferences/br/PMDPreferencePage2Test.java diff --git a/net.sourceforge.pmd.eclipse.plugin.test/src/main/java/net/sourceforge/pmd/eclipse/ui/preferences/br/PMDPreferencePage2Test.java b/net.sourceforge.pmd.eclipse.plugin.test/src/main/java/net/sourceforge/pmd/eclipse/ui/preferences/br/PMDPreferencePage2Test.java new file mode 100644 index 00000000..0a8f82bb --- /dev/null +++ b/net.sourceforge.pmd.eclipse.plugin.test/src/main/java/net/sourceforge/pmd/eclipse/ui/preferences/br/PMDPreferencePage2Test.java @@ -0,0 +1,104 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + + +package net.sourceforge.pmd.eclipse.ui.preferences.br; + +import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.allOf; +import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.widgetOfType; +import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.withMnemonic; +import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.withStyle; +import static org.eclipse.swtbot.swt.finder.waits.Conditions.waitForWidget; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; + +import org.eclipse.core.runtime.ILogListener; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Platform; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swtbot.swt.finder.waits.WaitForObjectCondition; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; +import org.eclipse.ui.PlatformUI; +import org.hamcrest.Matcher; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import net.sourceforge.pmd.eclipse.AbstractSWTBotTest; + +public class PMDPreferencePage2Test extends AbstractSWTBotTest { + private List errors; + private ILogListener logListener; + + @Before + public void setup() { + errors = new ArrayList<>(); + logListener = new ILogListener() { + @Override + public void logging(IStatus status, String plugin) { + if (status.getSeverity() != IStatus.ERROR) { + return; + } + + String statusText = status.toString().toLowerCase(Locale.ROOT); + if (statusText.contains("pmd") || statusText.contains("unhandled event loop exception")) { + errors.add(status); + } + } + }; + Platform.getLog(PlatformUI.class).addLogListener(logListener); + } + + @After + public void cleanup() { + Platform.getLog(PlatformUI.class).removeLogListener(logListener); + } + + /** + * Simple smoke test to open the rule configuration preference pages. + * @see PMDPreferencePage2 + */ + @Test + public void openPMDRuleConfiguration() { + bot.menu().menu("Window", "Preferences").click(); + SWTBotShell preferencesDialog = bot.shell("Preferences"); + SWTBotTreeItem pmdItem = preferencesDialog.bot().tree(0).getTreeItem("PMD"); + pmdItem.click(); + pmdItem.expand(); + pmdItem.getNode("Rule Configuration").click(); + + + Matcher