diff --git a/tests/org.eclipse.emf.parsley.tests.swtbot.cdo/src/org/eclipse/emf/parsley/tests/swtbot/cdo/EmfParsleyCdoSWTBotTests.java b/tests/org.eclipse.emf.parsley.tests.swtbot.cdo/src/org/eclipse/emf/parsley/tests/swtbot/cdo/EmfParsleyCdoSWTBotTests.java index ad98804ba..aa38ce9dd 100644 --- a/tests/org.eclipse.emf.parsley.tests.swtbot.cdo/src/org/eclipse/emf/parsley/tests/swtbot/cdo/EmfParsleyCdoSWTBotTests.java +++ b/tests/org.eclipse.emf.parsley.tests.swtbot.cdo/src/org/eclipse/emf/parsley/tests/swtbot/cdo/EmfParsleyCdoSWTBotTests.java @@ -33,11 +33,13 @@ import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; import org.eclipse.swtbot.swt.finder.results.ListResult; import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences; +import org.eclipse.swtbot.swt.finder.waits.DefaultCondition; 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.ISaveablePart; import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IViewReference; import org.eclipse.ui.PlatformUI; import org.junit.AfterClass; import org.junit.Assert; @@ -110,9 +112,9 @@ public void testDirtyForSelectedBook() { libraryNode.select("Book Domain Specific Languages"); botView.bot().textWithLabel("Title").setText("My Tyltle"); someSleep(); - Assert.assertTrue(isLibraryViewDirty(TEST_CDO_FORM_VIEW)); + assertLibraryViewDirty(TEST_CDO_FORM_VIEW, true); forceSaveView(botView); - Assert.assertFalse(isLibraryViewDirty(TEST_CDO_FORM_VIEW)); + assertLibraryViewDirty(TEST_CDO_FORM_VIEW, false); } private void someSleep() { @@ -156,8 +158,21 @@ public static void checkCDOServer(String host, String user, String password, Str session.close(); } - private boolean isLibraryViewDirty(String id) { - return getLibraryView(id).getViewReference().isDirty(); + private void assertLibraryViewDirty(final String id, final boolean expectedDirty) { + final IViewReference viewReference = getLibraryView(id).getViewReference(); + bot.waitUntil(new DefaultCondition() { + @Override + public boolean test() throws Exception { + boolean dirty = viewReference.isDirty(); + return dirty == expectedDirty; + } + + @Override + public String getFailureMessage() { + return "expected dirty: " + expectedDirty + + ", but was " + viewReference.isDirty(); + } + }); } private static SWTBotView openTestView(String libraryView) { diff --git a/tests/org.eclipse.emf.parsley.tests.swtbot/src/org/eclipse/emf/parsley/tests/swtbot/EmfParsleySWTBotAbstractTests.java b/tests/org.eclipse.emf.parsley.tests.swtbot/src/org/eclipse/emf/parsley/tests/swtbot/EmfParsleySWTBotAbstractTests.java index 43b987eaf..559e5f303 100644 --- a/tests/org.eclipse.emf.parsley.tests.swtbot/src/org/eclipse/emf/parsley/tests/swtbot/EmfParsleySWTBotAbstractTests.java +++ b/tests/org.eclipse.emf.parsley.tests.swtbot/src/org/eclipse/emf/parsley/tests/swtbot/EmfParsleySWTBotAbstractTests.java @@ -73,6 +73,7 @@ import org.eclipse.swtbot.swt.finder.results.ListResult; import org.eclipse.swtbot.swt.finder.results.WidgetResult; import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences; +import org.eclipse.swtbot.swt.finder.waits.DefaultCondition; import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox; import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu; import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; @@ -1188,14 +1189,28 @@ protected void assertDialogControlsOfWriterNode(boolean editable) { } protected SWTBotEditor assertEditorNotDirty(String editorName) { - SWTBotEditor editor = getEditor(editorName); - assertTrue("editor should NOT be in dirty state", !editor.isDirty()); - return editor; + return assertEditorDirtyState(editorName, false); } protected SWTBotEditor assertEditorDirty(String editorName) { - SWTBotEditor editor = getEditor(editorName); - assertTrue("editor should be in dirty state", editor.isDirty()); + return assertEditorDirtyState(editorName, true); + } + + private SWTBotEditor assertEditorDirtyState(String editorName, final boolean expectedDirtyState) { + final SWTBotEditor editor = getEditor(editorName); + bot.waitUntil(new DefaultCondition() { + @Override + public boolean test() throws Exception { + boolean dirty = editor.isDirty(); + return dirty == expectedDirtyState; + } + + @Override + public String getFailureMessage() { + return "expected dirty: " + expectedDirtyState + + ", but was " + editor.isDirty(); + } + }); return editor; } @@ -1212,9 +1227,21 @@ protected void assertDirtyThenSaveAndAssertNotDirty(String viewName) { saveViewAndAssertNotDirty(viewName); } - protected void assertSaveableViewIsDirty(boolean isDirty, String viewName) { - ISaveablePart viewAsSaveablePart = getViewAsSaveablePart(viewName); - assertEquals(isDirty, viewAsSaveablePart.isDirty()); + protected void assertSaveableViewIsDirty(final boolean expectedDirty, String viewName) { + final ISaveablePart viewAsSaveablePart = getViewAsSaveablePart(viewName); + bot.waitUntil(new DefaultCondition() { + @Override + public boolean test() throws Exception { + boolean dirty = viewAsSaveablePart.isDirty(); + return dirty == expectedDirty; + } + + @Override + public String getFailureMessage() { + return "expected dirty: " + expectedDirty + + ", but was " + viewAsSaveablePart.isDirty(); + } + }); } protected ISaveablePart getViewAsSaveablePart(String viewName) {