Move some utility methods around to provide a cleaner separation of the base SWT tests.
diff --git a/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/keyboard/AbstractKeyboardTest.java b/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/keyboard/AbstractKeyboardTest.java
index 536cd2f..aa3921a 100644
--- a/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/keyboard/AbstractKeyboardTest.java
+++ b/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/keyboard/AbstractKeyboardTest.java
@@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.swtbot.swt.finder.keyboard;
+import static org.eclipse.swtbot.swt.finder.utils.SWTUtils.isMac;
+
import org.eclipse.swt.SWT;
import org.eclipse.swtbot.swt.finder.test.AbstractCustomControlExampleTest;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotStyledText;
diff --git a/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/test/AbstractSWTShellTest.java b/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/test/AbstractSWTShellTest.java
index 934ccfa..a904416 100644
--- a/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/test/AbstractSWTShellTest.java
+++ b/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/test/AbstractSWTShellTest.java
@@ -70,9 +70,6 @@
}
});
}
-
- protected boolean isCocoa() {
- return SWT.getPlatform().equals("cocoa");
- }
-
+
+
}
\ No newline at end of file
diff --git a/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/test/AbstractSWTTest.java b/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/test/AbstractSWTTest.java
index c0be28e..2c7ddfd 100644
--- a/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/test/AbstractSWTTest.java
+++ b/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/test/AbstractSWTTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 Ketan Padegaonkar and others.
+ * Copyright (c) 2010,2011 Ketan Padegaonkar and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -11,20 +11,12 @@
package org.eclipse.swtbot.swt.finder.test;
import org.apache.log4j.Logger;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Tree;
import org.eclipse.swtbot.swt.finder.RunUIThreadRule;
import org.eclipse.swtbot.swt.finder.SWTBot;
import org.eclipse.swtbot.swt.finder.finders.ControlFinder;
import org.eclipse.swtbot.swt.finder.finders.Finder;
import org.eclipse.swtbot.swt.finder.finders.MenuFinder;
-import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
-import org.eclipse.swtbot.swt.finder.results.WidgetResult;
import org.junit.Before;
import org.junit.Rule;
import org.junit.rules.MethodRule;
@@ -33,6 +25,7 @@
import org.junit.runners.model.Statement;
/**
+ *
* @author Ketan Padegaonkar <KetanPadegaonkar [at] gmail [dot] com>
* @version $Id$
*/
@@ -55,7 +48,7 @@
return new RunUIThreadRule(target).apply(base, method, target);
}
};
-
+
@Before
public final void setupSWTBot() {
bot = new SWTBot();
@@ -63,34 +56,4 @@
menuFinder = new MenuFinder();
finder = new Finder(controlFinder, menuFinder);
}
-
- protected static boolean isMac() {
- String swtPlatform = SWT.getPlatform();
- return ("carbon".equals(swtPlatform) || "cocoa".equals(swtPlatform));
- }
-
- protected Shell createShell(final String text) {
- return UIThreadRunnable.syncExec(new WidgetResult<Shell>() {
- public Shell run() {
- Shell shell = new Shell(Display.getCurrent());
- shell.setText(text);
- shell.setLayout(new GridLayout(1, false));
- shell.open();
- return shell;
- }
- });
- }
- protected Tree createTree(final Shell shell) {
- return UIThreadRunnable.syncExec(new WidgetResult<Tree>() {
- public Tree run() {
- Tree tree = new Tree(shell, SWT.SINGLE);
- tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- tree.setLinesVisible(true);
- tree.setHeaderVisible(true);
-
- shell.layout(true);
- return tree;
- }
- });
- }
}
diff --git a/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/waits/TreeHasRowsTest.java b/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/waits/TreeHasRowsTest.java
index 5b3bfc7..740859e 100644
--- a/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/waits/TreeHasRowsTest.java
+++ b/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/waits/TreeHasRowsTest.java
@@ -14,11 +14,16 @@
import static org.junit.Assert.assertTrue;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
import org.eclipse.swtbot.swt.finder.results.VoidResult;
+import org.eclipse.swtbot.swt.finder.results.WidgetResult;
import org.eclipse.swtbot.swt.finder.test.AbstractSWTShellTest;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
import org.junit.Test;
@@ -54,4 +59,43 @@
tree = createTree(createShell(TEXT));
}
+ protected static boolean isMac() {
+ return (isCarbon() || isCocoa());
+ }
+
+ private static boolean isCarbon() {
+ return "carbon".equals(SWT.getPlatform());
+ }
+
+ protected static boolean isCocoa() {
+ return SWT.getPlatform().equals("cocoa");
+ }
+
+ private Shell createShell(final String text) {
+ return UIThreadRunnable.syncExec(new WidgetResult<Shell>() {
+ public Shell run() {
+ Shell shell = new Shell(Display.getCurrent());
+ shell.setText(text);
+ shell.setLayout(new GridLayout(1, false));
+ shell.open();
+ return shell;
+ }
+ });
+ }
+
+ private Tree createTree(final Shell shell) {
+ return UIThreadRunnable.syncExec(new WidgetResult<Tree>() {
+ public Tree run() {
+ Tree tree = new Tree(shell, SWT.SINGLE);
+ tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ tree.setLinesVisible(true);
+ tree.setHeaderVisible(true);
+
+ shell.layout(true);
+ return tree;
+ }
+ });
+ }
+
+
}
diff --git a/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotComboTest.java b/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotComboTest.java
index 791e20d..49515ed 100644
--- a/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotComboTest.java
+++ b/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotComboTest.java
@@ -4,13 +4,14 @@
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* Ketan Padegaonkar - initial API and implementation
* Cédric Chabanois - http://swtbot.org/bugzilla/show_bug.cgi?id=17
*******************************************************************************/
package org.eclipse.swtbot.swt.finder.widgets;
+import static org.eclipse.swtbot.swt.finder.utils.SWTUtils.isCocoa;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
diff --git a/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/utils/SWTUtils.java b/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/utils/SWTUtils.java
index 663f633..8093575 100644
--- a/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/utils/SWTUtils.java
+++ b/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/utils/SWTUtils.java
@@ -495,4 +495,27 @@
public static boolean isUIThread() {
return isUIThread(display);
}
+
+
+ /**
+ * @return <code>true</code> if the current OS is macosx.
+ */
+ public static boolean isMac(){
+ return isCocoa() || isCarbon();
+ }
+
+ /**
+ * @return <code>true</code> if the current platform is {@code cocoa}
+ */
+ public static boolean isCocoa(){
+ return SWT.getPlatform().equals("cocoa");
+ }
+
+ /**
+ * @return <code>true</code> if the current platform is {@code carbon}
+ */
+ public static boolean isCarbon(){
+ return SWT.getPlatform().equals("carbon");
+ }
+
}