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 junit.framework.TestCase;
023:
024: public class AbstractDocument_AttributeContextTest extends TestCase {
025: private AbstractDocument.AttributeContext context;
026:
027: /*
028: * @see TestCase#setUp()
029: */
030: @Override
031: protected void setUp() throws Exception {
032: super .setUp();
033: context = StyleContext.getDefaultStyleContext();
034: }
035:
036: public void testGetEmptySet() {
037: AttributeSet as = context.getEmptySet();
038: assertFalse(as.containsAttribute("key", "value"));
039: MutableAttributeSet sas = new SimpleAttributeSet();
040: sas.addAttribute("key", "value");
041: assertFalse(as.containsAttributes(sas));
042: assertEquals(as, SimpleAttributeSet.EMPTY);
043: assertNull(as.getAttribute("key"));
044: assertFalse(as.isDefined("key"));
045: assertTrue(as.isEqual(SimpleAttributeSet.EMPTY));
046: assertNotNull(as.toString());
047: assertEquals(SimpleAttributeSet.EMPTY, as.copyAttributes());
048: assertEquals(0, as.getAttributeCount());
049: assertFalse(as.getAttributeNames().hasMoreElements());
050: assertNull(as.getResolveParent());
051: }
052:
053: public void testReclaim() {
054: AttributeSet as = context.getEmptySet();
055: context.reclaim(as);
056: }
057:
058: public void testRemoveAttribute() {
059: AttributeSet as = context.getEmptySet();
060: String key = "key", value = "value";
061: context.addAttribute(as, key, value);
062: AttributeSet attr = context.removeAttribute(as, key);
063: assertEquals(0, attr.getAttributeCount());
064: assertEquals(context.getEmptySet(), attr);
065: }
066:
067: /*
068: * AttributeSet removeAttributes(AttributeSet, Enumeration)
069: */
070: public void testRemoveAttributesAttributeSetEnumeration() {
071: AttributeSet as = getFilledAttributeSet();
072: AttributeSet result = context.removeAttributes(as, as
073: .getAttributeNames());
074: assertEquals(context.getEmptySet(), result);
075: }
076:
077: /**
078: * Returns non-empty attribute set.
079: * @return
080: */
081: private AttributeSet getFilledAttributeSet() {
082: AttributeSet as = context.getEmptySet();
083: context.addAttribute(as, "key", "value");
084: context.addAttribute(as, "key1", "value1");
085: context.addAttribute(as, "key2", "value2");
086: return as;
087: }
088:
089: public void testAddAttributes() {
090: AttributeSet as = getFilledAttributeSet();
091: AttributeSet test = context.getEmptySet();
092: AttributeSet result = context.addAttributes(test, as);
093: assertEquals(test, result);
094: }
095:
096: /*
097: * AttributeSet removeAttributes(AttributeSet, AttributeSet)
098: */
099: public void testRemoveAttributesAttributeSetAttributeSet() {
100: AttributeSet as = getFilledAttributeSet();
101: AttributeSet result = context.removeAttributes(as, as);
102: assertEquals(context.getEmptySet(), result);
103: }
104:
105: public void testAddAttribute() {
106: AttributeSet as = context.getEmptySet();
107: String key = "key", value = "value";
108: AttributeSet result = context.addAttribute(as, key, value);
109: assertTrue(result.containsAttribute(key, value));
110: assertEquals(1, result.getAttributeCount());
111: }
112: }
|