001: /*
002: * $Id$
003: *
004: * ---------------------------------------------------------------------------
005: *
006: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
007: *
008: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
009: *
010: * The contents of this file are subject to the terms of either the GNU
011: * General Public License Version 2 only ("GPL") or the Common
012: * Development and Distribution License("CDDL") (collectively, the
013: * "License"). You may not use this file except in compliance with the
014: * License. You can obtain a copy of the License at
015: * http://www.netbeans.org/cddl-gplv2.html
016: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
017: * specific language governing permissions and limitations under the
018: * License. When distributing the software, include this License Header
019: * Notice in each file and include the License file at
020: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
021: * particular file as subject to the "Classpath" exception as provided
022: * by Sun in the GPL Version 2 section of the License file that
023: * accompanied this code. If applicable, add the following below the
024: * License Header, with the fields enclosed by brackets [] replaced by
025: * your own identifying information:
026: * "Portions Copyrighted [year] [name of copyright owner]"
027: *
028: * Contributor(s): Manfred Riem (mriem@netbeans.org).
029: *
030: * The Original Software is the Jemmy library. The Initial Developer of the
031: * Original Software is Alexandre Iline. All Rights Reserved.
032: *
033: * If you wish your version of this file to be governed by only the CDDL
034: * or only the GPL Version 2, indicate your decision by adding
035: * "[Contributor] elects to include this software in this distribution
036: * under the [CDDL or GPL Version 2] license." If you do not indicate a
037: * single choice of license, a recipient has the option to distribute
038: * your version of this file under either the CDDL, the GPL Version 2 or
039: * to extend the choice of license to its licensees as provided above.
040: * However, if you add GPL Version 2 code and therefore, elected the GPL
041: * Version 2 license, then the option applies only if the new code is
042: * made subject to such option by the copyright holder.
043: *
044: * ---------------------------------------------------------------------------
045: *
046: */
047: package org.netbeans.jemmy.operators;
048:
049: import java.awt.Checkbox;
050: import java.awt.Frame;
051: import java.awt.event.ItemEvent;
052: import java.awt.event.ItemListener;
053: import junit.framework.Test;
054: import junit.framework.TestCase;
055: import junit.framework.TestSuite;
056: import org.netbeans.jemmy.util.NameComponentChooser;
057:
058: /**
059: * A JUnit test for CheckboxOperator.
060: *
061: * @author Manfred Riem (mriem@netbeans.org)
062: * @version $Revision$
063: */
064: public class CheckboxOperatorTest extends TestCase {
065: /**
066: * Stores the frame we use for testing.
067: */
068: private Frame frame;
069:
070: /**
071: * Stores the button we use for testing.
072: */
073: private Checkbox checkbox;
074:
075: /**
076: * Constructor.
077: */
078: public CheckboxOperatorTest(String testName) {
079: super (testName);
080: }
081:
082: /**
083: * Setup before testing.
084: *
085: * @throws Exception when a major problem occurs.
086: */
087: protected void setUp() throws Exception {
088: frame = new Frame();
089: checkbox = new Checkbox("CheckboxOperatorTest");
090: checkbox.setName("CheckboxOperatorTest");
091: frame.add(checkbox);
092: frame.pack();
093: }
094:
095: /**
096: * Cleanup after testing.
097: *
098: * @throws Exception when a major problem occurs.
099: */
100: protected void tearDown() throws Exception {
101: frame.setVisible(false);
102: frame.dispose();
103: frame = null;
104: }
105:
106: /**
107: * Suite method.
108: */
109: public static Test suite() {
110: TestSuite suite = new TestSuite(CheckboxOperatorTest.class);
111:
112: return suite;
113: }
114:
115: /**
116: * Test constructor.
117: */
118: public void testConstructor() {
119: frame.setVisible(true);
120:
121: FrameOperator operator = new FrameOperator();
122: assertNotNull(operator);
123:
124: CheckboxOperator operator1 = new CheckboxOperator(operator);
125: assertNotNull(operator1);
126:
127: CheckboxOperator operator2 = new CheckboxOperator(operator,
128: "CheckboxOperatorTest");
129: assertNotNull(operator2);
130:
131: CheckboxOperator operator3 = new CheckboxOperator(operator,
132: new NameComponentChooser("CheckboxOperatorTest"));
133: assertNotNull(operator3);
134: }
135:
136: /**
137: * Test findCheckbox method.
138: */
139: public void testFindCheckbox() {
140: frame.setVisible(true);
141:
142: Checkbox checkbox1 = CheckboxOperator.findCheckbox(frame,
143: "CheckboxOperatorTest", false, false);
144: assertNotNull(checkbox1);
145:
146: Checkbox checkbox2 = CheckboxOperator.findCheckbox(frame,
147: new NameComponentChooser("CheckboxOperatorTest"));
148: assertNotNull(checkbox2);
149: }
150:
151: /**
152: * Test waitCheckbox method.
153: */
154: public void testWaitCheckbox() {
155: frame.setVisible(true);
156:
157: Checkbox checkbox1 = CheckboxOperator.waitCheckbox(frame,
158: "CheckboxOperatorTest", false, false);
159: assertNotNull(checkbox1);
160:
161: Checkbox checkbox2 = CheckboxOperator.waitCheckbox(frame,
162: new NameComponentChooser("CheckboxOperatorTest"));
163: assertNotNull(checkbox2);
164: }
165:
166: /**
167: * Test changeSelection method.
168: */
169: public void testChangeSelection() {
170: frame.setVisible(true);
171:
172: FrameOperator operator = new FrameOperator();
173: assertNotNull(operator);
174:
175: CheckboxOperator operator1 = new CheckboxOperator(operator);
176: assertNotNull(operator1);
177:
178: operator1.setState(false);
179: operator1.changeSelectionNoBlock(true);
180:
181: operator1.setState(true);
182: operator1.changeSelection(false);
183: }
184:
185: /**
186: * Test changeSelectionNoBlock method.
187: */
188: public void testChangeSelectionNoBlock() {
189: frame.setVisible(true);
190:
191: FrameOperator operator = new FrameOperator();
192: assertNotNull(operator);
193:
194: CheckboxOperator operator1 = new CheckboxOperator(operator);
195: assertNotNull(operator1);
196:
197: operator1.changeSelectionNoBlock(true);
198: }
199:
200: /**
201: * Test waitSelected method.
202: */
203: public void testWaitSelected() {
204: frame.setVisible(true);
205:
206: FrameOperator operator = new FrameOperator();
207: assertNotNull(operator);
208:
209: CheckboxOperator operator1 = new CheckboxOperator(operator);
210: assertNotNull(operator1);
211:
212: operator1.waitSelected(false);
213: operator1.setState(true);
214: operator1.waitSelected(true);
215: }
216:
217: /**
218: * Test getDump method.
219: */
220: public void testGetDump() {
221: frame.setVisible(true);
222:
223: FrameOperator operator = new FrameOperator();
224: assertNotNull(operator);
225:
226: CheckboxOperator operator1 = new CheckboxOperator(operator);
227: assertNotNull(operator1);
228:
229: operator1.getDump();
230: }
231:
232: /**
233: * Test addItemListener method.
234: */
235: public void testAddItemListener() {
236: frame.setVisible(true);
237:
238: FrameOperator operator = new FrameOperator();
239: assertNotNull(operator);
240:
241: CheckboxOperator operator1 = new CheckboxOperator(operator);
242: assertNotNull(operator1);
243:
244: ItemListenerTest listener = new ItemListenerTest();
245: operator1.addItemListener(listener);
246: operator1.removeItemListener(listener);
247: }
248:
249: /**
250: * Inner class needed for testing.
251: */
252: public class ItemListenerTest implements ItemListener {
253: public void itemStateChanged(ItemEvent e) {
254: }
255: }
256:
257: /**
258: * Test getCheckboxGroup method.
259: */
260: public void testGetCheckboxGroup() {
261: frame.setVisible(true);
262:
263: FrameOperator operator = new FrameOperator();
264: assertNotNull(operator);
265:
266: CheckboxOperator operator1 = new CheckboxOperator(operator);
267: assertNotNull(operator1);
268:
269: operator1.getCheckboxGroup();
270: }
271:
272: /**
273: * Test getLabel method.
274: */
275: public void testGetLabel() {
276: frame.setVisible(true);
277:
278: FrameOperator operator = new FrameOperator();
279: assertNotNull(operator);
280:
281: CheckboxOperator operator1 = new CheckboxOperator(operator);
282: assertNotNull(operator1);
283:
284: operator1.getLabel();
285: }
286:
287: /**
288: * Test getState method.
289: */
290: public void testGetState() {
291: frame.setVisible(true);
292:
293: FrameOperator operator = new FrameOperator();
294: assertNotNull(operator);
295:
296: CheckboxOperator operator1 = new CheckboxOperator(operator);
297: assertNotNull(operator1);
298:
299: operator1.getState();
300: }
301:
302: /**
303: * Test setCheckboxGroup method.
304: */
305: public void testSetCheckboxGroup() {
306: frame.setVisible(true);
307:
308: FrameOperator operator = new FrameOperator();
309: assertNotNull(operator);
310:
311: CheckboxOperator operator1 = new CheckboxOperator(operator);
312: assertNotNull(operator1);
313:
314: operator1.setCheckboxGroup(operator1.getCheckboxGroup());
315: }
316:
317: /**
318: * Test setLabel method.
319: */
320: public void testSetLabel() {
321: frame.setVisible(true);
322:
323: FrameOperator operator = new FrameOperator();
324: assertNotNull(operator);
325:
326: CheckboxOperator operator1 = new CheckboxOperator(operator);
327: assertNotNull(operator1);
328:
329: operator1.setLabel(operator1.getLabel());
330: }
331:
332: /**
333: * Test setState method.
334: */
335: public void testSetState() {
336: frame.setVisible(true);
337:
338: FrameOperator operator = new FrameOperator();
339: assertNotNull(operator);
340:
341: CheckboxOperator operator1 = new CheckboxOperator(operator);
342: assertNotNull(operator1);
343:
344: operator1.setState(operator1.getState());
345: }
346: }
|