Consolidated all SWTBot-related helpers into ProtobufBot.
diff --git a/com.google.eclipse.protobuf.ui.functional.test/src/com/google/eclipse/protobuf/ui/editor/Formatter_Test.java b/com.google.eclipse.protobuf.ui.functional.test/src/com/google/eclipse/protobuf/ui/editor/Formatter_Test.java
index 2628aae..eadabcf 100644
--- a/com.google.eclipse.protobuf.ui.functional.test/src/com/google/eclipse/protobuf/ui/editor/Formatter_Test.java
+++ b/com.google.eclipse.protobuf.ui.functional.test/src/com/google/eclipse/protobuf/ui/editor/Formatter_Test.java
@@ -14,13 +14,12 @@
import java.util.List;
import org.eclipse.swt.SWT;
-import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEclipseEditor;
import org.junit.*;
import com.google.eclipse.protobuf.formatting.ProtobufFormatter;
import com.google.eclipse.protobuf.ui.junit.core.CommentReaderRule;
-import com.google.eclipse.protobuf.ui.swtbot.*;
+import com.google.eclipse.protobuf.ui.swtbot.ProtobufBot;
/**
* Tests for <code>{@link ProtobufFormatter}</code>.
@@ -28,19 +27,15 @@
* @author alruiz@google.com (Alex Ruiz)
*/
public class Formatter_Test {
- private static SWTWorkbenchBot robot;
- private static FileFactory fileFactory;
+ private static ProtobufBot robot;
public @Rule CommentReaderRule commentReader = new CommentReaderRule();
@BeforeClass public static void setUpOnce() throws Exception {
- robot = new SWTWorkbenchBot();
- Workbench workbench = new Workbench(robot);
- workbench.initialize();
- ProjectFactory projectFactory = new ProjectFactory(robot);
- projectFactory.createGeneralProject("FormatterTest");
- fileFactory = new FileFactory(robot);
- SWTBotEclipseEditor editor = fileFactory.createFile("dummy.proto");
+ robot = new ProtobufBot();
+ robot.resetAll();
+ robot.createGeneralProject("FormatterTest");
+ SWTBotEclipseEditor editor = robot.createFile("dummy.proto");
editor.setText("syntax = 'proto2';");
editor.saveAndClose();
}
@@ -50,7 +45,7 @@
// import 'dummy.proto';
// import 'google/protobuf/descriptor.proto';
@Test public void should_add_line_wrap_after_normal_import() throws Exception {
- SWTBotEclipseEditor editor = fileFactory.createFile("formatNormalImport.proto");
+ SWTBotEclipseEditor editor = robot.createFile("formatNormalImport.proto");
Comments comments = commentsAbove();
editor.setText(comments.beforeFormatting);
formatAndSave(editor);
@@ -62,7 +57,7 @@
// import public 'dummy.proto';
// import 'google/protobuf/descriptor.proto';
@Test public void should_add_line_wrap_after_public_import() throws Exception {
- SWTBotEclipseEditor editor = fileFactory.createFile("formatPublicImport.proto");
+ SWTBotEclipseEditor editor = robot.createFile("formatPublicImport.proto");
Comments comments = commentsAbove();
editor.setText(comments.beforeFormatting);
formatAndSave(editor);
@@ -79,8 +74,7 @@
}
@After public void tearDown() {
- robot.saveAllEditors();
- robot.closeAllEditors();
+ robot.saveAndCloseAllEditors();
}
private static class Comments {
diff --git a/com.google.eclipse.protobuf.ui.functional.test/src/com/google/eclipse/protobuf/ui/swtbot/FileFactory.java b/com.google.eclipse.protobuf.ui.functional.test/src/com/google/eclipse/protobuf/ui/swtbot/FileFactory.java
deleted file mode 100644
index 5332925..0000000
--- a/com.google.eclipse.protobuf.ui.functional.test/src/com/google/eclipse/protobuf/ui/swtbot/FileFactory.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (c) 2012 Google Inc.
- *
- * 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
- *
- * http://www.eclipse.org/legal/epl-v10.html
- */
-package com.google.eclipse.protobuf.ui.swtbot;
-
-import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
-import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEclipseEditor;
-import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
-
-/**
- * @author alruiz@google.com (Alex Ruiz)
- */
-public class FileFactory {
-
- private final SWTWorkbenchBot robot;
-
- public FileFactory(SWTWorkbenchBot robot) {
- this.robot = robot;
- }
-
- public SWTBotEclipseEditor createFile(String name) {
- robot.menu("File").menu("New").menu("File").click();
- SWTBotShell shell = robot.shell("New File");
- shell.activate();
- robot.textWithLabel("File name:").setText(name);
- robot.button("Finish").click();
- return robot.editorByTitle(name).toTextEditor();
- }
-}
diff --git a/com.google.eclipse.protobuf.ui.functional.test/src/com/google/eclipse/protobuf/ui/swtbot/ProjectFactory.java b/com.google.eclipse.protobuf.ui.functional.test/src/com/google/eclipse/protobuf/ui/swtbot/ProjectFactory.java
deleted file mode 100644
index 87eb6af..0000000
--- a/com.google.eclipse.protobuf.ui.functional.test/src/com/google/eclipse/protobuf/ui/swtbot/ProjectFactory.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (c) 2012 Google Inc.
- *
- * 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
- *
- * http://www.eclipse.org/legal/epl-v10.html
- */
-package com.google.eclipse.protobuf.ui.swtbot;
-
-import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
-import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
-
-/**
- * @author alruiz@google.com (Alex Ruiz)
- */
-public class ProjectFactory {
- private final SWTWorkbenchBot robot;
-
- public ProjectFactory(SWTWorkbenchBot robot) {
- this.robot = robot;
- }
-
- public void createGeneralProject(String name) {
- robot.menu("File").menu("New").menu("Project...").click();
- SWTBotShell shell = robot.shell("New Project");
- shell.activate();
- robot.tree().expandNode("General").select("Project");
- robot.button("Next >").click();
- robot.textWithLabel("Project name:").setText(name);
- robot.button("Finish").click();
- }
-}
diff --git a/com.google.eclipse.protobuf.ui.functional.test/src/com/google/eclipse/protobuf/ui/swtbot/ProtobufBot.java b/com.google.eclipse.protobuf.ui.functional.test/src/com/google/eclipse/protobuf/ui/swtbot/ProtobufBot.java
new file mode 100644
index 0000000..fd32469
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui.functional.test/src/com/google/eclipse/protobuf/ui/swtbot/ProtobufBot.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2012 Google Inc.
+ *
+ * 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
+ *
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+package com.google.eclipse.protobuf.ui.swtbot;
+
+import static com.google.eclipse.protobuf.ui.util.Workspaces.workspaceRoot;
+
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.*;
+import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
+import org.eclipse.swtbot.eclipse.finder.widgets.*;
+import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
+
+/**
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public class ProtobufBot extends SWTWorkbenchBot {
+ private static final NullProgressMonitor NULL_MONITOR = new NullProgressMonitor();
+
+ public void resetAll() throws CoreException {
+ resetWorkbench();
+ deleteProjects();
+ closeWelcomeView();
+ }
+
+ private void deleteProjects() throws CoreException {
+ for (IProject project : workspaceRoot().getProjects()) {
+ project.delete(true, true, NULL_MONITOR);
+ }
+ }
+
+ private void closeWelcomeView() {
+ try {
+ viewByTitle("Welcome").close();
+ } catch (WidgetNotFoundException ignored) {}
+ }
+
+ public void createGeneralProject(String name) {
+ menu("File").menu("New").menu("Project...").click();
+ SWTBotShell shell = shell("New Project");
+ shell.activate();
+ tree().expandNode("General").select("Project");
+ button("Next >").click();
+ textWithLabel("Project name:").setText(name);
+ button("Finish").click();
+ }
+
+ public SWTBotEclipseEditor createFile(String name) {
+ menu("File").menu("New").menu("File").click();
+ SWTBotShell shell = shell("New File");
+ shell.activate();
+ textWithLabel("File name:").setText(name);
+ button("Finish").click();
+ return editorByTitle(name).toTextEditor();
+ }
+
+ public void saveAndCloseAllEditors() {
+ List<? extends SWTBotEditor> editors = editors();
+ for (SWTBotEditor editor : editors) {
+ editor.saveAndClose();
+ }
+ }
+}
diff --git a/com.google.eclipse.protobuf.ui.functional.test/src/com/google/eclipse/protobuf/ui/swtbot/Workbench.java b/com.google.eclipse.protobuf.ui.functional.test/src/com/google/eclipse/protobuf/ui/swtbot/Workbench.java
deleted file mode 100644
index 50bdc11..0000000
--- a/com.google.eclipse.protobuf.ui.functional.test/src/com/google/eclipse/protobuf/ui/swtbot/Workbench.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (c) 2012 Google Inc.
- *
- * 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
- *
- * http://www.eclipse.org/legal/epl-v10.html
- */
-package com.google.eclipse.protobuf.ui.swtbot;
-
-import static com.google.eclipse.protobuf.ui.util.Workspaces.workspaceRoot;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.*;
-import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
-import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
-
-/**
- * @author alruiz@google.com (Alex Ruiz)
- */
-public final class Workbench {
- private static final NullProgressMonitor NULL_MONITOR = new NullProgressMonitor();
-
- private final SWTWorkbenchBot robot;
-
- public Workbench(SWTWorkbenchBot robot) {
- this.robot = robot;
- }
-
- public void initialize() throws CoreException {
- robot.closeAllShells();
- closeWelcomeView();
- deleteAllProjects();
- }
-
- private void closeWelcomeView() {
- try {
- robot.viewByTitle("Welcome").close();
- } catch (WidgetNotFoundException ignored) {}
- }
-
- private void deleteAllProjects() throws CoreException {
- for (IProject project : workspaceRoot().getProjects()) {
- project.delete(true, true, NULL_MONITOR);
- }
- }
-}