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 Alexey A. Ivanov
019: * @version $Revision$
020: */package javax.swing.text;
021:
022: import java.util.Enumeration;
023: import java.util.NoSuchElementException;
024: import javax.swing.BasicSwingTestCase;
025: import junit.framework.TestCase;
026:
027: public class EmptyAttributeSetTest extends TestCase {
028: /**
029: * Shared instance of EmptyAttributeSet class.
030: */
031: private static final AttributeSet empty = SimpleAttributeSet.EMPTY;
032:
033: /**
034: * Shared instance of SimpleAttributeSet class.
035: */
036: private static final SimpleAttributeSet simple = new SimpleAttributeSet();
037:
038: /**
039: * Shared instance of StyleContext.SmallAttributeSet class.
040: */
041: private static final StyleContext.SmallAttributeSet small = new StyleContext().new SmallAttributeSet(
042: empty);
043:
044: public EmptyAttributeSetTest(final String name) {
045: super (name);
046: }
047:
048: public void testEmptySet() {
049: // Assert that both classes return the same attribute set
050: assertSame(new StyleContext().getEmptySet(),
051: SimpleAttributeSet.EMPTY);
052: }
053:
054: public void testHashCode() {
055: assertEquals(0, empty.hashCode());
056: }
057:
058: public void testGetAttribute() {
059: assertNull(empty.getAttribute("key"));
060: }
061:
062: public void testGetAttributeCount() {
063: assertEquals(0, empty.getAttributeCount());
064: }
065:
066: public void testContainsAttribute() {
067: assertFalse(empty.containsAttribute("key", "value"));
068: }
069:
070: public void testEqualsObject() {
071: assertFalse(empty.equals(new Object()));
072: assertTrue(empty.equals(empty));
073: assertTrue(empty.equals(simple));
074: assertTrue(empty.equals(small));
075: }
076:
077: public void testIsEqual() {
078: assertTrue(empty.isEqual(empty));
079: assertTrue(empty.isEqual(simple));
080: assertTrue(empty.isEqual(small));
081: }
082:
083: public void testGetAttributeNames() {
084: Enumeration<?> names = empty.getAttributeNames();
085: assertNotNull(names);
086: assertFalse(names.hasMoreElements());
087: try {
088: names.nextElement();
089: fail("NoSuchElementException should be thrown");
090: } catch (NoSuchElementException e) {
091: }
092: }
093:
094: public void testGetResolveParent() {
095: assertNull(empty.getResolveParent());
096: assertNull(empty.getAttribute(AttributeSet.ResolveAttribute));
097: }
098:
099: public void testIsDefined() {
100: assertFalse(empty.isDefined("key"));
101: }
102:
103: public void testCopyAttributes() {
104: assertSame(empty, empty.copyAttributes());
105: }
106:
107: public void testContainsAttributes() {
108: assertTrue(empty.containsAttributes(empty));
109: assertTrue(empty.containsAttributes(small));
110: assertTrue(empty.containsAttributes(simple));
111: }
112:
113: public void testToString() {
114: final String expected;
115: expected = BasicSwingTestCase.isHarmony() ? "javax.swing.text.EmptyAttributeSet@0"
116: : "javax.swing.text.SimpleAttributeSet$EmptyAttributeSet@0";
117: assertEquals(expected, empty.toString());
118: }
119: }
|