From 694753438180c31b0ccd478e073ea4f0b48a1c3e Mon Sep 17 00:00:00 2001 From: Ondrej Dockal Date: Tue, 6 Sep 2022 12:44:29 +0200 Subject: [PATCH] Fix another batch of tests and patches for 2022-09 eclipse. fixes #2156 Signed-off-by: Ondrej Dockal --- .../jdt/ui/wizards/NewClassWizardPage.java | 58 +++++++++++++++++-- .../wizards/NewClassCreationWizardTest.java | 28 +++++---- .../NewInterfaceCreationWizardTest.java | 17 +++--- .../browser/WebBrowserPreferencePageTest.java | 1 - .../ui/view/ModifyModulesDialogTest.java | 10 +++- .../wst/server/ui/view/ServerModuleTest.java | 21 ++++--- .../server/ui/view/ServersViewTestCase.java | 2 +- .../server/ui/view/TestServerBehaviour.java | 2 - 8 files changed, 100 insertions(+), 39 deletions(-) diff --git a/plugins/org.eclipse.reddeer.eclipse/src/org/eclipse/reddeer/eclipse/jdt/ui/wizards/NewClassWizardPage.java b/plugins/org.eclipse.reddeer.eclipse/src/org/eclipse/reddeer/eclipse/jdt/ui/wizards/NewClassWizardPage.java index 93833aadd2..eb60a6249f 100644 --- a/plugins/org.eclipse.reddeer.eclipse/src/org/eclipse/reddeer/eclipse/jdt/ui/wizards/NewClassWizardPage.java +++ b/plugins/org.eclipse.reddeer.eclipse/src/org/eclipse/reddeer/eclipse/jdt/ui/wizards/NewClassWizardPage.java @@ -13,7 +13,7 @@ import org.eclipse.reddeer.core.reference.ReferencedComposite; import org.eclipse.reddeer.swt.impl.button.CheckBox; -import org.eclipse.reddeer.swt.impl.button.LabeledCheckBox; +import org.eclipse.reddeer.swt.impl.button.RadioButton; import org.eclipse.reddeer.swt.impl.text.LabeledText; /** @@ -53,7 +53,7 @@ public boolean getStaticMainMethodCheckboxState() { * @return boolean state of the abstract checkbox */ public boolean getAbstractModifierCheckboxState() { - return new CheckBox(this, "abstract").isChecked(); + return getAbstactModifierCheckBox().isChecked(); } /** @@ -62,7 +62,7 @@ public boolean getAbstractModifierCheckboxState() { * @param toggle abstract modifier checkbox */ public NewClassWizardPage toggleAbstractModifierCheckbox(boolean toggle) { - new CheckBox(this, "abstract").toggle(toggle); + getAbstactModifierCheckBox().toggle(toggle); return this; } @@ -72,7 +72,7 @@ public NewClassWizardPage toggleAbstractModifierCheckbox(boolean toggle) { * @return boolean state of the final checkbox */ public boolean getFinalModifierCheckboxState() { - return new CheckBox(this, "final").isChecked(); + return getFinalModifierCheckBox().isChecked(); } /** @@ -81,7 +81,7 @@ public boolean getFinalModifierCheckboxState() { * @param toggle final modifier checkbox */ public NewClassWizardPage toggleFinalModifierCheckbox(boolean toggle) { - new CheckBox(this, "final").toggle(toggle); + getFinalModifierCheckBox().toggle(toggle); return this; } @@ -103,4 +103,52 @@ public NewClassWizardPage setSuperclassName(String superclassName) { public String getSuperclassName() { return new LabeledText(this, "Superclass:").getText(); } + + /** + * Return "abstract" check box object + * @return CheckBox for abstract modifier + */ + public CheckBox getAbstactModifierCheckBox() { + return new CheckBox(this, "abstract"); + } + + /** + * Return "final" check box object + * @return CheckBox for final modifier + */ + public CheckBox getFinalModifierCheckBox() { + return new CheckBox(this, "final"); + } + + /** + * Return "final" radio button object + * @return RadioButton for final modifier + */ + public RadioButton getFinalModifierRadioButton() { + return new RadioButton(this, "final"); + } + + /** + * Return "none" radio button object + * @return RadioButton for none modifier + */ + public RadioButton getNoneModifierRadioButton() { + return new RadioButton(this, "none"); + } + + /** + * Return "sealed" radio button object + * @return RadioButton for sealed modifier + */ + public RadioButton getSealedModifierRadioButton() { + return new RadioButton(this, "sealed"); + } + + /** + * Return "non-sealed" radio button object + * @return RadioButton for non-sealed modifier + */ + public RadioButton getNonSealedModifierRadioButton() { + return new RadioButton(this, "non-sealed"); + } } diff --git a/tests/org.eclipse.reddeer.eclipse.test/src/org/eclipse/reddeer/eclipse/test/jdt/ui/wizards/NewClassCreationWizardTest.java b/tests/org.eclipse.reddeer.eclipse.test/src/org/eclipse/reddeer/eclipse/test/jdt/ui/wizards/NewClassCreationWizardTest.java index 7fd4dbd32a..dabc8dad07 100644 --- a/tests/org.eclipse.reddeer.eclipse.test/src/org/eclipse/reddeer/eclipse/test/jdt/ui/wizards/NewClassCreationWizardTest.java +++ b/tests/org.eclipse.reddeer.eclipse.test/src/org/eclipse/reddeer/eclipse/test/jdt/ui/wizards/NewClassCreationWizardTest.java @@ -12,6 +12,8 @@ package org.eclipse.reddeer.eclipse.test.jdt.ui.wizards; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -173,10 +175,20 @@ public void testSettingAndGettingInputAndCheckboxValues() { classPage.toggleAbstractModifierCheckbox(true).getAbstractModifierCheckboxState()); assertTrue("State of abstract modifier should be 'false', but is not.", !classPage.toggleAbstractModifierCheckbox(false).getAbstractModifierCheckboxState()); - assertTrue("State of final modifier should be 'true', but is not.", - classPage.toggleFinalModifierCheckbox(true).getFinalModifierCheckboxState()); - assertTrue("State of final modifier should be 'false', but is not.", - !classPage.toggleFinalModifierCheckbox(false).getFinalModifierCheckboxState()); + + classPage.getFinalModifierRadioButton().click(); + assertTrue("State of final modifier should be 'true', but is not.", + classPage.getFinalModifierRadioButton().isSelected()); + classPage.getNoneModifierRadioButton().click(); + assertTrue("State of none modifier should be 'true', but is not.", + classPage.getNoneModifierRadioButton().isSelected()); + assertFalse("State of final modifier should be 'false', but is not.", + classPage.getFinalModifierRadioButton().isSelected()); + + // check some modifier objects creation + assertNotNull(classPage.getAbstactModifierCheckBox()); + assertNotNull(classPage.getNonSealedModifierRadioButton()); + assertNotNull(classPage.getFinalModifierCheckBox()); // test toggling the checkbox for creating main method in newly created class assertTrue("State of checkbox for creating main method should be 'disabled', but is not.", @@ -247,14 +259,6 @@ public void testAddingAndRemovingNonexistingAndNotFullySpecifiedInterfaces() { new PushButton("Cancel").click(); } - // try to add an extended interface, that is not fully specified by its name - try { - classPage.addExtendedInterface("Acl"); - fail("RedDeer exception was not thrown when trying to add an extended interface, that is not fully specified by its name."); - } catch (RedDeerException e) { - new PushButton("Cancel").click(); - } - // try to remove an extended interface, that is not on the list try { classPage.removeExtendedInterface("javax.accessibility.AccessibleAction"); diff --git a/tests/org.eclipse.reddeer.eclipse.test/src/org/eclipse/reddeer/eclipse/test/jdt/ui/wizards/NewInterfaceCreationWizardTest.java b/tests/org.eclipse.reddeer.eclipse.test/src/org/eclipse/reddeer/eclipse/test/jdt/ui/wizards/NewInterfaceCreationWizardTest.java index 47fe0ced4b..ded791aa57 100644 --- a/tests/org.eclipse.reddeer.eclipse.test/src/org/eclipse/reddeer/eclipse/test/jdt/ui/wizards/NewInterfaceCreationWizardTest.java +++ b/tests/org.eclipse.reddeer.eclipse.test/src/org/eclipse/reddeer/eclipse/test/jdt/ui/wizards/NewInterfaceCreationWizardTest.java @@ -19,8 +19,11 @@ import java.util.List; import org.eclipse.reddeer.common.exception.RedDeerException; +import org.eclipse.reddeer.common.matcher.RegexMatcher; import org.eclipse.reddeer.common.wait.TimePeriod; import org.eclipse.reddeer.common.wait.WaitUntil; +import org.eclipse.reddeer.common.wait.WaitWhile; +import org.eclipse.reddeer.core.matcher.WithTextMatcher; import org.eclipse.reddeer.eclipse.jdt.ui.wizards.JavaProjectWizard; import org.eclipse.reddeer.eclipse.jdt.ui.wizards.NewInterfaceCreationWizard; import org.eclipse.reddeer.eclipse.jdt.ui.wizards.NewInterfaceCreationWizardPage; @@ -29,6 +32,7 @@ import org.eclipse.reddeer.eclipse.ui.perspectives.JavaPerspective; import org.eclipse.reddeer.junit.runner.RedDeerSuite; import org.eclipse.reddeer.requirements.openperspective.OpenPerspectiveRequirement.OpenPerspective; +import org.eclipse.reddeer.swt.condition.ShellIsAvailable; import org.eclipse.reddeer.swt.impl.button.PushButton; import org.eclipse.reddeer.workbench.condition.EditorWithTitleIsActive; import org.eclipse.reddeer.workbench.handler.EditorHandler; @@ -62,6 +66,11 @@ public static void setup() { @After public void closeAllEditors() { + ShellIsAvailable shell = new ShellIsAvailable(new WithTextMatcher(new RegexMatcher("[Extended|Implemented].*Interfaces Selection"))); + new WaitWhile(shell, TimePeriod.SHORT, false); + if (shell.getResult() != null) { + shell.getResult().close(); + } EditorHandler.getInstance().closeAll(true); } @@ -226,14 +235,6 @@ public void testAddingAndRemovingNonexistingAndNotFullySpecifiedInterfaces() { new PushButton("Cancel").click(); } - // try to add an extended interface, that is not fully specified by its name - try { - interfacePage.addExtendedInterface("Acl"); - fail("RedDeer exception was not thrown when trying to add an extended interface, that is not fully specified by its name."); - } catch (RedDeerException e) { - new PushButton("Cancel").click(); - } - // try to remove an extended interface, that is not on the list try { interfacePage.removeExtendedInterface("javax.accessibility.AccessibleAction"); diff --git a/tests/org.eclipse.reddeer.eclipse.test/src/org/eclipse/reddeer/eclipse/test/ui/browser/WebBrowserPreferencePageTest.java b/tests/org.eclipse.reddeer.eclipse.test/src/org/eclipse/reddeer/eclipse/test/ui/browser/WebBrowserPreferencePageTest.java index f0c4c698df..10b92d3c83 100644 --- a/tests/org.eclipse.reddeer.eclipse.test/src/org/eclipse/reddeer/eclipse/test/ui/browser/WebBrowserPreferencePageTest.java +++ b/tests/org.eclipse.reddeer.eclipse.test/src/org/eclipse/reddeer/eclipse/test/ui/browser/WebBrowserPreferencePageTest.java @@ -42,7 +42,6 @@ public void setup() { @Test public void testBrowserPreferencePage() { - assertEquals("1", Preferences.get(BROWSER_PLUGIN, BROWSER_KEY)); page.toggleExternalBrowser(); page.apply(); assertEquals("1", Preferences.get(BROWSER_PLUGIN, BROWSER_KEY)); diff --git a/tests/org.eclipse.reddeer.eclipse.test/src/org/eclipse/reddeer/eclipse/test/wst/server/ui/view/ModifyModulesDialogTest.java b/tests/org.eclipse.reddeer.eclipse.test/src/org/eclipse/reddeer/eclipse/test/wst/server/ui/view/ModifyModulesDialogTest.java index 504141a793..2e214bb43b 100644 --- a/tests/org.eclipse.reddeer.eclipse.test/src/org/eclipse/reddeer/eclipse/test/wst/server/ui/view/ModifyModulesDialogTest.java +++ b/tests/org.eclipse.reddeer.eclipse.test/src/org/eclipse/reddeer/eclipse/test/wst/server/ui/view/ModifyModulesDialogTest.java @@ -13,7 +13,9 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertTrue; +import java.util.Arrays; import java.util.List; import org.eclipse.reddeer.eclipse.core.resources.DefaultProject; @@ -71,12 +73,14 @@ public void addAll_removeTwo(){ ModifyModulesPage page = new ModifyModulesPage(dialog); page.addAll(); dialog.finish(); + List expectedBefore = Arrays.asList(PROJECT_1, PROJECT_2, PROJECT_3); List modules = server.getModules(); assertThat(modules.size(), is(3)); - assertThat(modules.get(0).getLabel().getName(), is(PROJECT_1)); - assertThat(modules.get(1).getLabel().getName(), is(PROJECT_2)); - assertThat(modules.get(2).getLabel().getName(), is(PROJECT_3)); + + modules.stream().forEach(mod -> { + assertTrue(expectedBefore.contains(mod.getLabel().getName())); + }); dialog = server.addAndRemoveModules(); page = new ModifyModulesPage(dialog); diff --git a/tests/org.eclipse.reddeer.eclipse.test/src/org/eclipse/reddeer/eclipse/test/wst/server/ui/view/ServerModuleTest.java b/tests/org.eclipse.reddeer.eclipse.test/src/org/eclipse/reddeer/eclipse/test/wst/server/ui/view/ServerModuleTest.java index 767ff51cb9..2b247f75c5 100644 --- a/tests/org.eclipse.reddeer.eclipse.test/src/org/eclipse/reddeer/eclipse/test/wst/server/ui/view/ServerModuleTest.java +++ b/tests/org.eclipse.reddeer.eclipse.test/src/org/eclipse/reddeer/eclipse/test/wst/server/ui/view/ServerModuleTest.java @@ -13,8 +13,10 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.*; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import java.util.Arrays; import java.util.List; import org.eclipse.reddeer.eclipse.wst.server.ui.cnf.Server; @@ -76,19 +78,24 @@ public void removeServerModule() { ModifyModulesPage page = new ModifyModulesPage(dialog); page.addAll(); dialog.finish(); + List expectedBefore = Arrays.asList(PROJECT_1, PROJECT_2, PROJECT_3); + List expectedAfter = Arrays.asList(PROJECT_1, PROJECT_3); List modules = server.getModules(); assertThat(modules.size(), is(3)); - assertThat(modules.get(0).getLabel().getName(), is(PROJECT_1)); - assertThat(modules.get(1).getLabel().getName(), is(PROJECT_2)); - assertThat(modules.get(2).getLabel().getName(), is(PROJECT_3)); + modules.stream().forEach(mod -> { + assertTrue(expectedBefore.contains(mod.getLabel().getName())); + }); - modules.get(0).remove(); + ServerModule module = modules.stream().filter(item -> item.getLabel().getName().equals(PROJECT_2)).findFirst().orElse(null); + assertNotNull(module); + module.remove(); modules = server.getModules(); assertThat(modules.size(), is(2)); - assertThat(modules.get(0).getLabel().getName(), is(PROJECT_2)); - assertThat(modules.get(1).getLabel().getName(), is(PROJECT_3)); + modules.stream().forEach(mod -> { + assertTrue(expectedAfter.contains(mod.getLabel().getName())); + }); } @Test diff --git a/tests/org.eclipse.reddeer.eclipse.test/src/org/eclipse/reddeer/eclipse/test/wst/server/ui/view/ServersViewTestCase.java b/tests/org.eclipse.reddeer.eclipse.test/src/org/eclipse/reddeer/eclipse/test/wst/server/ui/view/ServersViewTestCase.java index dedc691ce5..f27fc224ed 100644 --- a/tests/org.eclipse.reddeer.eclipse.test/src/org/eclipse/reddeer/eclipse/test/wst/server/ui/view/ServersViewTestCase.java +++ b/tests/org.eclipse.reddeer.eclipse.test/src/org/eclipse/reddeer/eclipse/test/wst/server/ui/view/ServersViewTestCase.java @@ -70,7 +70,7 @@ protected static void createServer(String name) { NewServerWizardPage newServerPage = new NewServerWizardPage(wizardDialog); newServerPage.selectType("Basic", TestServer.NAME); - newServerPage.setName(name); + newServerPage.setName(name); wizardDialog.finish(); diff --git a/tests/org.eclipse.reddeer.eclipse.test/src/org/eclipse/reddeer/eclipse/test/wst/server/ui/view/TestServerBehaviour.java b/tests/org.eclipse.reddeer.eclipse.test/src/org/eclipse/reddeer/eclipse/test/wst/server/ui/view/TestServerBehaviour.java index 21f05c74d6..fbd36b5a6e 100644 --- a/tests/org.eclipse.reddeer.eclipse.test/src/org/eclipse/reddeer/eclipse/test/wst/server/ui/view/TestServerBehaviour.java +++ b/tests/org.eclipse.reddeer.eclipse.test/src/org/eclipse/reddeer/eclipse/test/wst/server/ui/view/TestServerBehaviour.java @@ -78,6 +78,4 @@ public void stopModule(IModule[] module, IProgressMonitor monitor) throws CoreEx AbstractWait.sleep(TimePeriod.SHORT); setModuleState(module, IServer.STATE_STOPPED); } - - }