This repository has been archived by the owner on Dec 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
06_MyFirstTest.java
119 lines (90 loc) · 3.71 KB
/
06_MyFirstTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package org.eclipsecon.swtbot.example;
import static org.eclipse.swtbot.swt.finder.SWTBotAssert.assertTextContains;
import static org.hamcrest.Matchers.instanceOf;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.Widget;
import org.eclipse.swtbot.eclipse.finder.SWTEclipseBot;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEclipseEditor;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.eclipse.swtbot.swt.finder.utils.FileUtils;
import org.eclipse.swtbot.swt.finder.waits.Conditions;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotStyledText;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.osgi.framework.Bundle;
@RunWith(SWTBotJunit4ClassRunner.class)
public class MyFirstTest {
private static SWTEclipseBot bot;
@BeforeClass
public static void beforeClass() throws Exception {
bot = new SWTEclipseBot();
bot.view("Welcome").close();
}
@AfterClass
public static void sleep() {
bot.sleep(5000);
}
@AfterClass
public static void afterClass() throws Exception {
SWTBotView packageExplorerView = bot.view("Package Explorer");
packageExplorerView.show();
Composite packageExplorerComposite = (Composite) packageExplorerView.getWidget();
Tree swtTree = (Tree) bot.widget(instanceOf(Tree.class), packageExplorerComposite);
SWTBotTree tree = new SWTBotTree(swtTree);
tree.select("MyFirstProject");
bot.menu("Edit").menu("Delete").click();
// the project deletion confirmation dialog
SWTBotShell shell = bot.shell("Delete Resources");
shell.activate();
bot.checkBox("Delete project contents on disk (cannot be undone)").select();
bot.button("OK").click();
bot.waitUntil(Conditions.shellCloses(shell));
}
@Test
public void canCreateANewJavaProject() throws Exception {
bot.menu("File").menu("New").menu("Project...").click();
bot.shell("New Project").activate();
bot.tree().select("Java Project");
bot.button("Next >").click();
bot.textWithLabel("Project name:").setText("MyFirstProject");
bot.button("Finish").click();
// FIXME: assert that the project is actually created, for later
}
@Test
public void canCreateANewJavaClass() throws Exception {
bot.toolbarDropDownButtonWithTooltip("New Java Class").menuItem("Class").click();
bot.shell("New Java Class").activate();
bot.textWithLabel("Source folder:").setText("MyFirstProject/src");
bot.textWithLabel("Package:").setText("org.eclipsecon.project");
bot.textWithLabel("Name:").setText("HelloWorld");
bot.button("Finish").click();
// FIXME: assert that the class is actually created, for later
}
@Test
public void canTypeInTextInAJavaClass() throws Exception {
Bundle bundle = Activator.getDefault().getBundle();
String contents = FileUtils.read(bundle.getEntry("test-files/HelloWorld.java"));
SWTBotEclipseEditor editor = bot.editor("HelloWorld.java");
editor.setText(contents);
editor.save();
// FIXME: verify that the text is actually placed in the editor
}
@Test
public void canExecuteJavaApplication() throws Exception {
bot.menu("Run").menu("Run").click();
// FIXME, get rid of sleep
bot.sleep(5000);
SWTBotView view = bot.view("Console");
Widget consoleViewComposite = view.getWidget();
StyledText swtStyledText = (StyledText) bot.widget(instanceOf(StyledText.class), consoleViewComposite);
SWTBotStyledText styledText = new SWTBotStyledText(swtStyledText);
assertTextContains("Hello World", styledText);
}
}