001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Dmitry A. Durnev
019: * @version $Revision$
020: */package java.awt;
021:
022: import java.awt.Checkbox.AccessibleAWTCheckbox;
023: import java.awt.event.ItemEvent;
024: import java.awt.event.ItemListener;
025: import java.beans.PropertyChangeEvent;
026: import java.beans.PropertyChangeListener;
027:
028: import javax.accessibility.AccessibleAction;
029: import javax.accessibility.AccessibleContext;
030: import javax.accessibility.AccessibleRole;
031: import javax.accessibility.AccessibleState;
032: import javax.accessibility.AccessibleStateSet;
033: import javax.accessibility.AccessibleValue;
034:
035: import junit.framework.TestCase;
036:
037: /**
038: * AccessibleAWTCheckboxTest
039: */
040: public class AccessibleAWTCheckboxTest extends TestCase {
041:
042: private Checkbox checkbox;
043: private AccessibleContext ac;
044: private PropertyChangeEvent lastPropEvent;
045: private PropertyChangeListener propListener;
046:
047: @Override
048: protected void setUp() throws Exception {
049: super .setUp();
050: checkbox = new Checkbox();
051: assertEquals(0, checkbox.getItemListeners().length);
052: ac = checkbox.getAccessibleContext();
053: assertSame(ac, checkbox.getItemListeners()[0]);
054: lastPropEvent = null;
055: assertNotNull(ac);
056:
057: propListener = new PropertyChangeListener() {
058:
059: public void propertyChange(PropertyChangeEvent pce) {
060: lastPropEvent = pce;
061: }
062: };
063: }
064:
065: public final void testGetAccessibleAction() {
066: AccessibleAction aa = ac.getAccessibleAction();
067: assertNotNull(aa);
068: assertTrue(aa instanceof AccessibleAWTCheckbox);
069: }
070:
071: public final void testGetAccessibleRole() {
072: assertSame(AccessibleRole.CHECK_BOX, ac.getAccessibleRole());
073: }
074:
075: public final void testGetAccessibleStateSet() {
076: AccessibleStateSet ass = ac.getAccessibleStateSet();
077: assertFalse(ass.contains(AccessibleState.CHECKED));
078: checkbox.setState(true);
079: ass = ac.getAccessibleStateSet();
080: assertTrue(ass.contains(AccessibleState.CHECKED));
081:
082: }
083:
084: public final void testGetAccessibleValue() {
085: AccessibleValue av = ac.getAccessibleValue();
086: assertNotNull(av);
087: assertTrue(av instanceof AccessibleAWTCheckbox);
088: }
089:
090: public final void testAccessibleAWTCheckbox() {
091: assertEquals(1, checkbox.getItemListeners().length);
092: ac = checkbox.new AccessibleAWTCheckbox();
093: // constructor has side-effect:
094: // item listener is added
095: assertEquals(2, checkbox.getItemListeners().length);
096: assertSame(ac, checkbox.getItemListeners()[1]);
097: }
098:
099: public final void testItemStateChanged() {
100: ac.addPropertyChangeListener(propListener);
101: assertNull(lastPropEvent);
102: ((ItemListener) ac).itemStateChanged(new ItemEvent(checkbox,
103: ItemEvent.ITEM_STATE_CHANGED, checkbox,
104: ItemEvent.DESELECTED));
105: assertNotNull(lastPropEvent);
106: assertSame(AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
107: lastPropEvent.getPropertyName());
108: }
109:
110: public final void testGetAccessibleActionCount() {
111: assertEquals("no accessible actions", 0, ac
112: .getAccessibleAction().getAccessibleActionCount());
113: }
114:
115: public final void testDoAccessibleAction() {
116: assertFalse(ac.getAccessibleAction().doAccessibleAction(0));
117: }
118:
119: public final void testGetAccessibleActionDescription() {
120: assertNull(ac.getAccessibleAction()
121: .getAccessibleActionDescription(0));
122: }
123:
124: public final void testGetCurrentAccessibleValue() {
125: assertNull(ac.getAccessibleValue().getCurrentAccessibleValue());
126: }
127:
128: public final void testGetMaximumAccessibleValue() {
129: assertNull(ac.getAccessibleValue().getMaximumAccessibleValue());
130: }
131:
132: public final void testGetMinimumAccessibleValue() {
133: assertNull(ac.getAccessibleValue().getMinimumAccessibleValue());
134: }
135:
136: public final void testSetCurrentAccessibleValue() {
137: AccessibleValue av = ac.getAccessibleValue();
138: assertFalse(av.setCurrentAccessibleValue(new Integer(0)));
139: assertFalse(av.setCurrentAccessibleValue(new Integer(1)));
140:
141: }
142: }
|