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 javax.swing.BasicSwingTestCase;
023: import javax.swing.text.StyleContext.SmallAttributeSet;
024: import junit.framework.TestCase;
025:
026: /**
027: * Tests for addAttributes method of StyleContext.
028: *
029: */
030: public class StyleContext_AddAttrsTest extends TestCase {
031: private StyleContext sc;
032:
033: public void testAddAttributesNine() {
034: AttributeSet as1 = StyleContextTest.addAttribute(5);
035: AttributeSet as2 = StyleContextTest.addAttribute(null, 5, 4);
036: AttributeSet test = sc.addAttributes(as1, as2);
037: assertEquals(9, test.getAttributeCount());
038: assertTrue(test instanceof SmallAttributeSet);
039: }
040:
041: public void testAddAttributesNineAndNine() {
042: AttributeSet as1 = StyleContextTest.addAttribute(9);
043: AttributeSet as2 = StyleContextTest.addAttribute(9);
044: AttributeSet test = sc.addAttributes(as1, as2);
045: assertEquals(9, test.getAttributeCount());
046: if (!BasicSwingTestCase.isHarmony()) {
047: assertTrue(test instanceof SimpleAttributeSet);
048: } else {
049: assertTrue(test instanceof SmallAttributeSet);
050: }
051: }
052:
053: public void testAddAttributesNineFull() {
054: AttributeSet as1 = StyleContextTest.addAttribute(8);
055: AttributeSet as2 = StyleContextTest.addAttribute(9);
056: AttributeSet test = sc.addAttributes(as1, as2);
057: assertEquals(9, test.getAttributeCount());
058: if (!BasicSwingTestCase.isHarmony()) {
059: assertTrue(test instanceof SimpleAttributeSet);
060: } else {
061: assertTrue(test instanceof SmallAttributeSet);
062: }
063: }
064:
065: public void testAddAttributesSameValues() {
066: AttributeSet as1 = StyleContextTest.addAttribute(2);
067: AttributeSet as2 = new SimpleAttributeSet(StyleContextTest
068: .addAttribute(2));
069: assertNotSame(as1, as2);
070: assertEquals(2, as2.getAttributeCount());
071: AttributeSet test = sc.addAttributes(as1, as2);
072: assertSame(as1, test);
073: assertEquals(2, test.getAttributeCount());
074: }
075:
076: public void testAddAttributesTen() {
077: AttributeSet as1 = StyleContextTest.addAttribute(5);
078: AttributeSet as2 = StyleContextTest.addAttribute(null, 5, 5);
079: AttributeSet test = sc.addAttributes(as1, as2);
080: assertEquals(10, test.getAttributeCount());
081: assertTrue(test instanceof SimpleAttributeSet);
082: }
083:
084: public void testAddAttributesTenFull() {
085: AttributeSet as1 = StyleContextTest.addAttribute(9);
086: AttributeSet as2 = StyleContextTest.addAttribute(9);
087: as2 = sc.addAttribute(as2, StyleConstants.LineSpacing,
088: new Float(0.5));
089: AttributeSet test = sc.addAttributes(as1, as2);
090: assertEquals(10, test.getAttributeCount());
091: assertTrue(test instanceof SimpleAttributeSet);
092: }
093:
094: public void testAddAttributesThreeSame() {
095: AttributeSet as = sc.addAttributes(StyleContextTest
096: .addAttribute(3), StyleContextTest.addAttribute(1));
097: assertEquals(3, as.getAttributeCount());
098: }
099:
100: public void testAddAttributesThreeSameKey() {
101: AttributeSet as = sc.addAttributes(StyleContextTest
102: .addAttribute(3), sc.addAttribute(sc.getEmptySet(),
103: StyleContextTest.attr[0], Boolean.FALSE));
104: assertEquals(3, as.getAttributeCount());
105: assertEquals(Boolean.FALSE, as
106: .getAttribute(StyleContextTest.attr[0]));
107: }
108:
109: public void testAddAttributesWithoutCache() {
110: AttributeSet as1 = StyleContextTest.addAttribute(5);
111: AttributeSet as2 = StyleContextTest.addAttribute(null, 5, 3);
112: as2 = sc.addAttribute(as2, StyleConstants.LineSpacing,
113: new Float(0.5));
114: AttributeSet test = sc.addAttributes(as1, as2);
115: assertEquals(9, test.getAttributeCount());
116: assertTrue(test instanceof SmallAttributeSet);
117: }
118:
119: @Override
120: protected void setUp() throws Exception {
121: sc = StyleContextTest.sc = new StyleContext();
122: }
123: }
|