-
Notifications
You must be signed in to change notification settings - Fork 43
/
TitleAreaDialogTest.java
170 lines (137 loc) · 4.95 KB
/
TitleAreaDialogTest.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*******************************************************************************
* Copyright (c) 2017 Red Hat, Inc and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc - initial API and implementation
*******************************************************************************/
package org.eclipse.reddeer.jface.test.dialogs;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.reddeer.common.util.Display;
import org.eclipse.reddeer.core.exception.CoreLayerException;
import org.eclipse.reddeer.eclipse.selectionwizard.NewMenuWizard;
import org.eclipse.reddeer.jface.dialogs.MessageTypeEnum;
import org.eclipse.reddeer.jface.dialogs.TitleAreaDialog;
import org.eclipse.reddeer.jface.test.Activator;
import org.eclipse.reddeer.jface.test.dialogs.impl.TestingNewWizard;
import org.eclipse.reddeer.jface.test.dialogs.impl.TestingTitleAreaDialog;
import org.eclipse.reddeer.swt.impl.button.PushButton;
import org.eclipse.swt.widgets.Shell;
import org.junit.After;
import org.junit.Test;
public class TitleAreaDialogTest {
private static TestingTitleAreaDialog tt;
private Shell s;
private NewWizardDialogImpl nw;
@Test
public void titleAreaMessagesAndImages() {
openTitleAreaDialog();
TitleAreaDialogImpl dialog = new TitleAreaDialogImpl();
assertEquals(TestingTitleAreaDialog.DEFAULT_MESSAGE, dialog.getMessage());
assertEquals(MessageTypeEnum.NONE, dialog.getMessageType());
assertEquals(TestingTitleAreaDialog.TITLE, dialog.getTitle());
assertNull(dialog.getMessageImage());
assertEquals(Activator.getDefault().getImageRegistry().get(Activator.REDDEER_ICON), dialog.getTitleImage());
dialog.errorButton();
assertEquals(TestingTitleAreaDialog.ERROR_MESSAGE, dialog.getMessage());
assertEquals(MessageTypeEnum.ERROR, dialog.getMessageType());
assertEquals(JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_ERROR), dialog.getMessageImage());
dialog.warningButton();
assertEquals(TestingTitleAreaDialog.WARNING_MESSAGE, dialog.getMessage());
assertEquals(MessageTypeEnum.WARNING, dialog.getMessageType());
assertEquals(JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_WARNING), dialog.getMessageImage());
dialog.infoButton();
assertEquals(TestingTitleAreaDialog.INFO_MESSAGE, dialog.getMessage());
assertEquals(MessageTypeEnum.INFO, dialog.getMessageType());
assertEquals(JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_INFO), dialog.getMessageImage());
dialog.noneButton();
assertEquals(TestingTitleAreaDialog.NONE_MESSAGE, dialog.getMessage());
assertEquals(MessageTypeEnum.NONE, dialog.getMessageType());
assertNull(dialog.getMessageImage());
dialog.errorWithoutProviderButton();
assertEquals(TestingTitleAreaDialog.ERROR_MESSAGE_WITHOUT_PROVIDER, dialog.getMessage());
assertEquals(MessageTypeEnum.ERROR, dialog.getMessageType());
}
// check if WizardDialog can be used as TitleAreaDialog
@Test
public void testWizardDialogAsTitleAreaDialog() {
nw = new NewWizardDialogImpl();
nw.open();
new TitleAreaDialog(TestingNewWizard.NAME);
}
// basic shell cannot be used as TitleAreaDialog
@Test(expected = CoreLayerException.class)
public void testShellAsTitleAreaDialog() {
Display.asyncExec(new Runnable() {
@Override
public void run() {
s = new Shell();
s.setText("Testing shell");
s.open();
}
});
new TitleAreaDialog("Testing shell");
}
public void openTitleAreaDialog() {
Display.asyncExec(new Runnable() {
@Override
public void run() {
tt = new TestingTitleAreaDialog(null);
tt.create();
tt.open();
}
});
}
@After
public void closeShell() {
Display.syncExec(new Runnable() {
@Override
public void run() {
if (s != null) {
s.dispose();
}
if (tt != null) {
tt.close();
}
}
});
if(nw != null && nw.isOpen()){
nw.cancel();
}
}
private class TitleAreaDialogImpl extends TitleAreaDialog {
public TitleAreaDialogImpl() {
super(TestingTitleAreaDialog.TEXT);
}
public void errorButton() {
clickButton(TestingTitleAreaDialog.ERROR_MESSAGE);
}
public void warningButton() {
clickButton(TestingTitleAreaDialog.WARNING_MESSAGE);
}
public void infoButton() {
clickButton(TestingTitleAreaDialog.INFO_MESSAGE);
}
public void noneButton() {
clickButton(TestingTitleAreaDialog.NONE_MESSAGE);
}
public void errorWithoutProviderButton() {
clickButton(TestingTitleAreaDialog.ERROR_MESSAGE_WITHOUT_PROVIDER);
}
private void clickButton(String text) {
new PushButton(text).click();
}
}
private class NewWizardDialogImpl extends NewMenuWizard {
public NewWizardDialogImpl() {
super(TestingNewWizard.NAME, TestingNewWizard.CATEGORY, TestingNewWizard.NAME);
}
}
}