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: package javax.accessibility;
019:
020: import java.beans.PropertyChangeEvent;
021: import java.beans.PropertyChangeListener;
022: import java.util.Locale;
023:
024: import junit.framework.TestCase;
025:
026: public class AccessibleContextTest extends TestCase {
027: private AccessibleContext context;
028:
029: private PropertyChangeListenerImpl propertyChangeListener;
030:
031: @Override
032: public void setUp() {
033: context = new AccessibleContext() {
034: @Override
035: public AccessibleRole getAccessibleRole() {
036: return null;
037: }
038:
039: @Override
040: public AccessibleStateSet getAccessibleStateSet() {
041: return null;
042: }
043:
044: @Override
045: public int getAccessibleIndexInParent() {
046: return 0;
047: }
048:
049: @Override
050: public int getAccessibleChildrenCount() {
051: return 0;
052: }
053:
054: @Override
055: public Accessible getAccessibleChild(int i) {
056: return null;
057: }
058:
059: @Override
060: public Locale getLocale() {
061: return Locale.ENGLISH;
062: }
063: };
064: propertyChangeListener = new PropertyChangeListenerImpl();
065: context.addPropertyChangeListener(propertyChangeListener);
066: }
067:
068: @Override
069: public void tearDown() {
070: context = null;
071: propertyChangeListener.lastEvent = null;
072: }
073:
074: public void testSetGetAccessibleName() {
075: String name = "componentName";
076: context.setAccessibleName(name);
077: assertEquals(AccessibleContext.ACCESSIBLE_NAME_PROPERTY,
078: propertyChangeListener.lastEvent.getPropertyName());
079: assertEquals(name, propertyChangeListener.lastEvent
080: .getNewValue());
081: assertEquals(name, context.getAccessibleName());
082: assertEquals(name, context.accessibleName);
083: }
084:
085: public void testSetGetAccessibleDescription() {
086: String description = "componentDescription";
087: context.setAccessibleDescription(description);
088: assertEquals(AccessibleContext.ACCESSIBLE_DESCRIPTION_PROPERTY,
089: propertyChangeListener.lastEvent.getPropertyName());
090: assertEquals(description, propertyChangeListener.lastEvent
091: .getNewValue());
092: assertEquals(description, context.getAccessibleDescription());
093: assertEquals(description, context.accessibleDescription);
094: }
095:
096: public void testSetGetAccessibleParent() {
097: Accessible parent = new Accessible() {
098: private String name = "parentName";
099:
100: public AccessibleContext getAccessibleContext() {
101: return null;
102: }
103:
104: @Override
105: public String toString() {
106: return name;
107: }
108: };
109: context.setAccessibleParent(parent);
110: assertEquals(parent, context.getAccessibleParent());
111: assertEquals(parent, context.accessibleParent);
112: assertNull(propertyChangeListener.lastEvent);
113: }
114:
115: public void testGetAccessibleOthers() {
116: assertNull(context.getAccessibleAction());
117: assertNull(context.getAccessibleComponent());
118: assertNull(context.getAccessibleSelection());
119: assertNull(context.getAccessibleText());
120: assertNull(context.getAccessibleEditableText());
121: assertNull(context.getAccessibleValue());
122: assertNull(context.getAccessibleIcon());
123: assertSame(context.getAccessibleRelationSet(), context
124: .getAccessibleRelationSet());
125: assertNull(context.getAccessibleTable());
126: assertNull(propertyChangeListener.lastEvent);
127: }
128:
129: private static class PropertyChangeListenerImpl implements
130: PropertyChangeListener {
131: PropertyChangeEvent lastEvent;
132:
133: PropertyChangeListenerImpl() {
134: super ();
135: }
136:
137: public void propertyChange(PropertyChangeEvent event) {
138: this.lastEvent = event;
139: }
140: }
141: }
|