diff options
| author | Jens Baumgart | 2010-09-23 22:24:41 +0000 |
|---|---|---|
| committer | Matthias Sohn | 2010-09-23 22:24:41 +0000 |
| commit | c47d2a967ab03bf5a75ce670a0c002045347b05a (patch) | |
| tree | 09a2acb563b277006e66ff1d42a649b2f426f341 | |
| parent | 68fcf8eb66c797c8a5d20a9540b3dc79f559a0ee (diff) | |
| download | egit-c47d2a967ab03bf5a75ce670a0c002045347b05a.tar.gz egit-c47d2a967ab03bf5a75ce670a0c002045347b05a.tar.xz egit-c47d2a967ab03bf5a75ce670a0c002045347b05a.zip | |
Avoid logged SWTException in ShowInTest
ShowInTest was changed to avoid that an SWTException is logged
during test execution.
Change-Id: I19175c7f6aeb4262646b4ecb3b6cb82bb98a1399
Signed-off-by: Jens Baumgart <jens.baumgart@sap.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
| -rw-r--r-- | org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/ContextMenuHelper.java | 78 | ||||
| -rw-r--r-- | org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/ShowInTest.java | 26 |
2 files changed, 68 insertions, 36 deletions
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/ContextMenuHelper.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/ContextMenuHelper.java index 2608fedfd1..22b582dfac 100644 --- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/ContextMenuHelper.java +++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/ContextMenuHelper.java @@ -17,6 +17,7 @@ import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.instanceOf; import java.util.Arrays; +import java.util.concurrent.atomic.AtomicBoolean; import org.eclipse.swt.SWT; import org.eclipse.swt.SWTException; @@ -54,23 +55,7 @@ public class ContextMenuHelper { .syncExec(new WidgetResult<MenuItem>() { @SuppressWarnings("unchecked") public MenuItem run() { - MenuItem theItem = null; - Control control = (Control) bot.widget; - // for dynamic menus, we need to issue this event - control.notifyListeners(SWT.MenuDetect, new Event()); - Menu menu = control.getMenu(); - for (String text : texts) { - Matcher<?> matcher = allOf( - instanceOf(MenuItem.class), - withMnemonic(text)); - theItem = show(menu, matcher); - if (theItem != null) { - menu = theItem.getMenu(); - } else { - hide(menu); - break; - } - } + MenuItem theItem = getMenuItem(bot, texts); if (theItem != null && !theItem.isEnabled()) throw new IllegalStateException( "Menu item is diabled"); @@ -94,6 +79,65 @@ public class ContextMenuHelper { }); } + private static MenuItem getMenuItem(final AbstractSWTBot<?> bot, + final String... texts) { + MenuItem theItem = null; + Control control = (Control) bot.widget; + // for dynamic menus, we need to issue this event + control.notifyListeners(SWT.MenuDetect, new Event()); + Menu menu = control.getMenu(); + for (String text : texts) { + Matcher<?> matcher = allOf(instanceOf(MenuItem.class), + withMnemonic(text)); + theItem = show(menu, matcher); + if (theItem != null) { + menu = theItem.getMenu(); + } else { + hide(menu); + break; + } + } + return theItem; + } + + /** + * Checks if the context menu matching the text is enabled + * + * @param bot + * + * @param texts + * the text on the context menu. + * @return true if the context menu is enabled + * @throws WidgetNotFoundException + * if the widget is not found. + */ + public static boolean isContextMenuItemEnabled(final AbstractSWTBot<?> bot, + final String... texts) { + + final AtomicBoolean enabled = new AtomicBoolean(false); + // show + final MenuItem menuItem = UIThreadRunnable + .syncExec(new WidgetResult<MenuItem>() { + @SuppressWarnings("unchecked") + public MenuItem run() { + MenuItem theItem = getMenuItem(bot, texts); + if (theItem != null && theItem.isEnabled()) + enabled.set(true); + return theItem; + } + }); + if (menuItem == null) { + throw new WidgetNotFoundException("Could not find menu: " + + Arrays.asList(texts)); + } + // hide + UIThreadRunnable.syncExec(new VoidResult() { + public void run() { + hide(menuItem.getParent()); + } + }); + return enabled.get(); + } private static MenuItem show(final Menu menu, final Matcher<?> matcher) { if (menu != null) { diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/ShowInTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/ShowInTest.java index e33146c55d..b0489baa62 100644 --- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/ShowInTest.java +++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/ShowInTest.java @@ -10,13 +10,11 @@ *******************************************************************************/ package org.eclipse.egit.ui.test.team.actions; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.Assert.assertFalse; import org.eclipse.egit.ui.common.LocalRepositoryTestCase; import org.eclipse.egit.ui.internal.repository.RepositoriesView; import org.eclipse.egit.ui.test.ContextMenuHelper; -import org.eclipse.swt.SWTException; import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotPerspective; import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; @@ -74,14 +72,9 @@ public class ShowInTest extends LocalRepositoryTestCase { projectExplorerTree.select(0, 1); String menuString = util .getPluginLocalizedValue("ShowResourceInHistoryAction_label"); - try { - ContextMenuHelper.clickContextMenu(projectExplorerTree, "Team", - menuString); - fail("This should have failed"); - } catch (SWTException e) { - // expected - assertTrue(e.getCause() instanceof IllegalStateException); - } + // Team->show in history must be disabled on a multiple selection + assertFalse(ContextMenuHelper.isContextMenuItemEnabled(projectExplorerTree, "Team", + menuString)); } @Test @@ -110,14 +103,9 @@ public class ShowInTest extends LocalRepositoryTestCase { projectExplorerTree.select(0, 1); String menuString = util .getPluginLocalizedValue("ShowRepositoryAction_label"); - try { - ContextMenuHelper.clickContextMenu(projectExplorerTree, "Team", - menuString); - fail("This should have failed"); - } catch (SWTException e) { - // expected - assertTrue(e.getCause() instanceof IllegalStateException); - } + // Team->show in repository must be disabled on a multiple selection + assertFalse(ContextMenuHelper.isContextMenuItemEnabled(projectExplorerTree, "Team", + menuString)); } } |
