|
1
|
|
package junit.extensions.jfcunit.finder;
|
|
2
|
|
|
|
3
|
|
import junit.extensions.jfcunit.AbstractTestCase;
|
|
4
|
|
|
|
5
|
|
import javax.swing.Icon;
|
|
6
|
|
import javax.swing.ImageIcon;
|
|
7
|
|
import javax.swing.JButton;
|
|
8
|
|
import javax.swing.UIManager;
|
|
9
|
|
|
|
10
|
|
|
|
11
|
|
|
|
12
|
|
|
|
13
|
|
|
|
14
|
|
|
|
15
|
|
public class AbstractButtonFinderT extends AbstractTestCase {
|
|
16
|
|
|
|
17
|
|
|
|
18
|
|
|
|
19
|
|
|
|
20
|
|
private Icon m_validIcon = new ImageIcon(AbstractTestCase.class.getResource(
|
|
21
|
|
"images/duke2.gif"));
|
|
22
|
|
|
|
23
|
|
|
|
24
|
|
|
|
25
|
|
|
|
26
|
|
private Icon m_validIcon2 = new ImageIcon(AbstractTestCase.class.getResource(
|
|
27
|
|
"images/duke.gif"));
|
|
28
|
|
|
|
29
|
|
|
|
30
|
|
|
|
31
|
|
|
|
32
|
|
private Icon m_validIcon3 = UIManager.getIcon("FileView.floppyDriveIcon");
|
|
33
|
|
|
|
34
|
|
|
|
35
|
|
|
|
36
|
|
|
|
37
|
|
private Icon m_invalidIcon = new ImageIcon("images/invalid.gif");
|
|
38
|
|
|
|
39
|
|
|
|
40
|
|
|
|
41
|
|
|
|
42
|
|
|
|
43
|
|
|
|
44
|
12
|
public AbstractButtonFinderT(final String name) {
|
|
45
|
12
|
super(name);
|
|
46
|
|
}
|
|
47
|
|
|
|
48
|
|
|
|
49
|
|
|
|
50
|
|
|
|
51
|
1
|
public void testConsturctor() {
|
|
52
|
1
|
new AbstractButtonFinder("TEST");
|
|
53
|
1
|
new AbstractButtonFinder("test", false);
|
|
54
|
1
|
new AbstractButtonFinder("test", m_validIcon3);
|
|
55
|
1
|
new AbstractButtonFinder(m_validIcon);
|
|
56
|
1
|
new AbstractButtonFinder("Test", m_validIcon, false);
|
|
57
|
|
}
|
|
58
|
|
|
|
59
|
|
|
|
60
|
|
|
|
61
|
|
|
|
62
|
1
|
public void testComponentInvalidComponent() {
|
|
63
|
1
|
AbstractButtonFinder finder = new AbstractButtonFinder(null,
|
|
64
|
|
m_validIcon);
|
|
65
|
1
|
JButton button = new JButton("Some Text", m_validIcon);
|
|
66
|
1
|
setWindow(createJFrame(getName()));
|
|
67
|
1
|
getFrame().getContentPane().add(button);
|
|
68
|
1
|
packAndShow(getFrame());
|
|
69
|
1
|
assertFalse("Finder is not working", finder.testComponent(getFrame()));
|
|
70
|
|
}
|
|
71
|
|
|
|
72
|
|
|
|
73
|
|
|
|
74
|
|
|
|
75
|
1
|
public void testComponentNullLabelNullIcon() {
|
|
76
|
1
|
AbstractButtonFinder finder = new AbstractButtonFinder(null, null);
|
|
77
|
1
|
JButton button = new JButton();
|
|
78
|
1
|
setWindow(createJFrame(getName()));
|
|
79
|
1
|
getFrame().getContentPane().add(button);
|
|
80
|
1
|
packAndShow(getFrame());
|
|
81
|
1
|
assertTrue("Finder is not working", finder.testComponent(button));
|
|
82
|
|
}
|
|
83
|
|
|
|
84
|
|
|
|
85
|
|
|
|
86
|
|
|
|
87
|
1
|
public void testComponentNullLabelValidIcon() {
|
|
88
|
1
|
AbstractButtonFinder finder = new AbstractButtonFinder(null,
|
|
89
|
|
m_validIcon);
|
|
90
|
1
|
JButton button = new JButton("Some Text", m_validIcon);
|
|
91
|
1
|
setWindow(createJFrame(getName()));
|
|
92
|
1
|
getFrame().getContentPane().add(button);
|
|
93
|
1
|
packAndShow(getFrame());
|
|
94
|
1
|
assertTrue("Finder is not working", finder.testComponent(button));
|
|
95
|
|
}
|
|
96
|
|
|
|
97
|
|
|
|
98
|
|
|
|
99
|
|
|
|
100
|
1
|
public void testComponentNullLabelDifferentIcon() {
|
|
101
|
1
|
AbstractButtonFinder finder = new AbstractButtonFinder(null,
|
|
102
|
|
m_validIcon);
|
|
103
|
1
|
JButton button = new JButton("Some Text", m_validIcon2);
|
|
104
|
1
|
setWindow(createJFrame(getName()));
|
|
105
|
1
|
getFrame().getContentPane().add(button);
|
|
106
|
1
|
packAndShow(getFrame());
|
|
107
|
1
|
assertTrue("Finder is not working", !finder.testComponent(button));
|
|
108
|
|
}
|
|
109
|
|
|
|
110
|
|
|
|
111
|
|
|
|
112
|
|
|
|
113
|
1
|
public void testComponentInvalidLabelValidIcon() {
|
|
114
|
1
|
AbstractButtonFinder finder = new AbstractButtonFinder("Invalid Label",
|
|
115
|
|
m_validIcon);
|
|
116
|
1
|
JButton button = new JButton("Valid Label", m_validIcon);
|
|
117
|
1
|
setWindow(createJFrame(getName()));
|
|
118
|
1
|
getFrame().getContentPane().add(button);
|
|
119
|
1
|
packAndShow(getFrame());
|
|
120
|
1
|
assertFalse("Finder is not working", finder.testComponent(button));
|
|
121
|
|
}
|
|
122
|
|
|
|
123
|
|
|
|
124
|
|
|
|
125
|
|
|
|
126
|
1
|
public void testComponentValidLabelInvalidIcon() {
|
|
127
|
1
|
AbstractButtonFinder finder = new AbstractButtonFinder("Valid Label",
|
|
128
|
|
m_invalidIcon);
|
|
129
|
1
|
JButton button = new JButton("Valid Label", m_validIcon);
|
|
130
|
1
|
setWindow(createJFrame(getName()));
|
|
131
|
1
|
getFrame().getContentPane().add(button);
|
|
132
|
1
|
packAndShow(getFrame());
|
|
133
|
1
|
assertFalse("Finder is not working", finder.testComponent(button));
|
|
134
|
|
}
|
|
135
|
|
|
|
136
|
|
|
|
137
|
|
|
|
138
|
|
|
|
139
|
1
|
public void testComponentValidLabelValidIconCaseSensitive() {
|
|
140
|
1
|
AbstractButtonFinder finder = new AbstractButtonFinder("Valid Label",
|
|
141
|
|
m_validIcon);
|
|
142
|
1
|
JButton button = new JButton("Valid Label", m_validIcon);
|
|
143
|
1
|
setWindow(createJFrame(getName()));
|
|
144
|
1
|
getFrame().getContentPane().add(button);
|
|
145
|
1
|
packAndShow(getFrame());
|
|
146
|
1
|
assertTrue("Finder is not working", finder.testComponent(button));
|
|
147
|
|
}
|
|
148
|
|
|
|
149
|
|
|
|
150
|
|
|
|
151
|
|
|
|
152
|
1
|
public void testComponentValidLabelValidIconCaseInsensitive() {
|
|
153
|
1
|
AbstractButtonFinder finder = new AbstractButtonFinder("vaLId labEL",
|
|
154
|
|
m_validIcon, true);
|
|
155
|
1
|
JButton button = new JButton("Valid Label", m_validIcon);
|
|
156
|
1
|
setWindow(createJFrame(getName()));
|
|
157
|
1
|
getFrame().getContentPane().add(button);
|
|
158
|
1
|
packAndShow(getFrame());
|
|
159
|
1
|
assertTrue("Finder is not working", finder.testComponent(button));
|
|
160
|
|
}
|
|
161
|
|
|
|
162
|
|
|
|
163
|
|
|
|
164
|
|
|
|
165
|
1
|
public void testComponentValidLabelWrongIconCaseInsensitive() {
|
|
166
|
1
|
AbstractButtonFinder finder = new AbstractButtonFinder("vaLId labEL",
|
|
167
|
|
m_validIcon2, true);
|
|
168
|
1
|
JButton button = new JButton("Valid Label", m_validIcon);
|
|
169
|
1
|
setWindow(createJFrame(getName()));
|
|
170
|
1
|
getFrame().getContentPane().add(button);
|
|
171
|
1
|
packAndShow(getFrame());
|
|
172
|
1
|
assertTrue("Finder is not working", !finder.testComponent(button));
|
|
173
|
|
}
|
|
174
|
|
|
|
175
|
|
|
|
176
|
|
|
|
177
|
|
|
|
178
|
1
|
public void testText() {
|
|
179
|
1
|
AbstractButtonFinder finder = new AbstractButtonFinder("test");
|
|
180
|
1
|
assertEquals("test", finder.getText());
|
|
181
|
1
|
finder.setText("ABC");
|
|
182
|
1
|
assertEquals("ABC", finder.getText());
|
|
183
|
|
}
|
|
184
|
|
|
|
185
|
|
|
|
186
|
|
|
|
187
|
|
|
|
188
|
1
|
public void testIcon() {
|
|
189
|
1
|
AbstractButtonFinder finder = new AbstractButtonFinder(m_validIcon);
|
|
190
|
1
|
assertSame(m_validIcon, finder.getIcon());
|
|
191
|
1
|
finder.setIcon(m_validIcon2);
|
|
192
|
1
|
assertSame(m_validIcon2, finder.getIcon());
|
|
193
|
|
}
|
|
194
|
|
}
|
|
195
|
|
|