-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for PMD Preferences / Rule Configuration
- Loading branch information
Showing
1 changed file
with
104 additions
and
0 deletions.
There are no files selected for viewing
104 changes: 104 additions & 0 deletions
104
...t/src/main/java/net/sourceforge/pmd/eclipse/ui/preferences/br/PMDPreferencePage2Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<IStatus> 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<Button> matcher = allOf(widgetOfType(Button.class), | ||
withMnemonic("Use global rule management"), | ||
withStyle(SWT.CHECK, "SWT.CHECK")); | ||
WaitForObjectCondition<Button> waitForWidget = waitForWidget(matcher); | ||
preferencesDialog.bot().waitUntil(waitForWidget, TimeUnit.SECONDS.toMillis(15)); | ||
SWTBotCheckBox globalRuleManagementCheckbox = new SWTBotCheckBox(waitForWidget.get(0), matcher); | ||
globalRuleManagementCheckbox.click(); | ||
|
||
SWTBotTree ruleTable = preferencesDialog.bot().tree(1); | ||
int rowCount = ruleTable.rowCount(); | ||
assertTrue(rowCount > 0); | ||
|
||
// select first rule | ||
ruleTable.getAllItems()[0].click(); | ||
|
||
preferencesDialog.bot().button("Cancel").click(); | ||
|
||
if (!errors.isEmpty()) { | ||
fail("There are " + errors.size() + " errors:\n" | ||
+ errors.stream().map(IStatus::getMessage).collect(Collectors.joining("\n"))); | ||
} | ||
} | ||
} |