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.html;
021:
022: import javax.swing.text.Style;
023: import javax.swing.text.html.CSS.Attribute;
024:
025: import junit.framework.TestCase;
026:
027: public class StyleSheet_StyleSheetsTest extends TestCase {
028: private StyleSheet ss;
029: private StyleSheet second;
030: private StyleSheet third;
031: private StyleSheet[] sheets;
032: private Style rule;
033:
034: protected void setUp() throws Exception {
035: super .setUp();
036: ss = new StyleSheet();
037: }
038:
039: public void testGetStyleSheets() {
040: sheets = ss.getStyleSheets();
041: assertNull(sheets);
042:
043: second = new StyleSheet();
044: ss.addStyleSheet(second);
045: sheets = ss.getStyleSheets();
046: assertEquals(1, sheets.length);
047: assertSame(second, sheets[0]);
048: }
049:
050: public void testAddStyleSheet() {
051: second = new StyleSheet();
052: third = new StyleSheet();
053: ss.addStyleSheet(second);
054: ss.addStyleSheet(third);
055:
056: sheets = ss.getStyleSheets();
057: assertEquals(2, sheets.length);
058: assertSame(third, sheets[0]);
059: assertSame(second, sheets[1]);
060: }
061:
062: public void testAddStyleSheetDuplicate() {
063: second = new StyleSheet();
064: ss.addStyleSheet(second);
065: assertEquals(1, ss.getStyleSheets().length);
066: ss.addStyleSheet(second);
067: assertEquals(1, ss.getStyleSheets().length);
068: }
069:
070: public void testAddStyleSheetUpdateRule() {
071: rule = ss.getRule("p");
072: second = new StyleSheet();
073: second.addRule("p { color: red }");
074: ss.addStyleSheet(second);
075:
076: assertEquals(2, rule.getAttributeCount());
077: assertEquals("red", rule.getAttribute(Attribute.COLOR)
078: .toString());
079:
080: third = new StyleSheet();
081: third.addRule("p { color: blue }");
082: ss.addStyleSheet(third);
083:
084: assertEquals(4, rule.getAttributeCount());
085: assertEquals("blue", rule.getAttribute(Attribute.COLOR)
086: .toString());
087: }
088:
089: public void testAddStyleSheetOverrideRule() {
090: ss.addRule("p { color: black }");
091: rule = ss.getRule("p");
092: assertEquals("black", rule.getAttribute(Attribute.COLOR)
093: .toString());
094:
095: second = new StyleSheet();
096: second.addRule("p { color: red }");
097: ss.addStyleSheet(second);
098: assertEquals("black", rule.getAttribute(Attribute.COLOR)
099: .toString());
100: }
101:
102: public void testRemoveStyleSheet() {
103: second = new StyleSheet();
104: third = new StyleSheet();
105: ss.addStyleSheet(second);
106: ss.addStyleSheet(third);
107:
108: assertEquals(2, ss.getStyleSheets().length);
109:
110: ss.removeStyleSheet(second);
111: assertEquals(1, ss.getStyleSheets().length);
112: assertEquals(third, ss.getStyleSheets()[0]);
113:
114: ss.removeStyleSheet(second);
115: assertEquals(1, ss.getStyleSheets().length);
116:
117: ss.removeStyleSheet(third);
118: assertNull(ss.getStyleSheets());
119: }
120:
121: public void testRemoveStyleSheetRuleChange() {
122: rule = ss.getRule("p");
123: second = new StyleSheet();
124: second.addRule("p { color: red }");
125: ss.addStyleSheet(second);
126:
127: third = new StyleSheet();
128: third.addRule("p { color: blue }");
129: ss.addStyleSheet(third);
130: assertEquals("blue", rule.getAttribute(Attribute.COLOR)
131: .toString());
132:
133: ss.removeStyleSheet(third);
134: assertEquals("red", rule.getAttribute(Attribute.COLOR)
135: .toString());
136:
137: ss.removeStyleSheet(second);
138: assertEquals(0, rule.getAttributeCount());
139: assertNull(rule.getAttribute(Attribute.COLOR));
140: }
141: }
|