Source Code Cross Referenced for StyleContext_AddAttrTest.java in  » Apache-Harmony-Java-SE » javax-package » javax » swing » text » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » javax package » javax.swing.text 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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 addAttribute method.
028:         *
029:         */
030:        public class StyleContext_AddAttrTest extends TestCase {
031:            private StyleContext sc;
032:
033:            /**
034:             * Add two same attributes into two sets using different order.
035:             * The cache should return the same objects.
036:             */
037:            public void testAddAttributeCacheDiffOrder() {
038:                AttributeSet as1 = sc.addAttribute(sc.getEmptySet(),
039:                        StyleConstants.Bold, Boolean.TRUE);
040:                AttributeSet as2 = sc.addAttribute(as1, StyleConstants.Italic,
041:                        Boolean.FALSE);
042:                AttributeSet as12 = sc.addAttribute(sc.getEmptySet(),
043:                        StyleConstants.Italic, Boolean.FALSE);
044:                AttributeSet as22 = sc.addAttribute(as12, StyleConstants.Bold,
045:                        Boolean.TRUE);
046:                assertSame(as2, as22);
047:                assertEquals(2, as2.getAttributeCount());
048:            }
049:
050:            /**
051:             * Add two same attributes into two sets using the same order.
052:             * The cache should return the same objects.
053:             */
054:            public void testAddAttributeCacheSameOrder() {
055:                AttributeSet as11 = sc.addAttribute(sc.getEmptySet(),
056:                        StyleConstants.Bold, Boolean.TRUE);
057:                AttributeSet as21 = sc.addAttribute(as11,
058:                        StyleConstants.Italic, Boolean.FALSE);
059:                AttributeSet as12 = sc.addAttribute(sc.getEmptySet(),
060:                        StyleConstants.Bold, Boolean.TRUE);
061:                AttributeSet as22 = sc.addAttribute(as12,
062:                        StyleConstants.Italic, Boolean.FALSE);
063:                assertSame(as11, as12);
064:                assertSame(as21, as22);
065:                assertEquals(1, as11.getAttributeCount());
066:                assertEquals(2, as21.getAttributeCount());
067:            }
068:
069:            /**
070:             * Add two different key/value pair to an empty set.
071:             * Check the return instances are different.
072:             */
073:            public void testAddAttributeDiff() {
074:                AttributeSet as1 = sc.addAttribute(sc.getEmptySet(),
075:                        StyleConstants.Bold, Boolean.TRUE);
076:                AttributeSet as2 = sc.addAttribute(sc.getEmptySet(),
077:                        StyleConstants.Bold, Boolean.FALSE);
078:                assertNotSame(as1, as2);
079:            }
080:
081:            /**
082:             * Add nine attributes into a set.
083:             */
084:            public void testAddAttributeNine() {
085:                AttributeSet as = StyleContextTest.addAttribute(9);
086:                assertEquals(9, as.getAttributeCount());
087:                assertTrue(as instanceof  SmallAttributeSet);
088:            }
089:
090:            /**
091:             * Add nine attributes into a set, and try to add the tenth one
092:             * which is already in the set.
093:             */
094:            public void testAddAttributeNineSameValue() {
095:                AttributeSet as = StyleContextTest.addAttribute(9);
096:                as = sc.addAttribute(as, StyleConstants.Bold, Boolean.TRUE);
097:                assertEquals(9, as.getAttributeCount());
098:                if (!BasicSwingTestCase.isHarmony()) {
099:                    assertTrue(as instanceof  SimpleAttributeSet);
100:                } else {
101:                    assertTrue(as instanceof  SmallAttributeSet);
102:                }
103:            }
104:
105:            /**
106:             * Add the same key/value pair to an empty set.
107:             * Check the returned instances are the same.
108:             */
109:            public void testAddAttributeSame() {
110:                AttributeSet as1 = StyleContextTest.addAttribute(null, 1);
111:                AttributeSet as2 = StyleContextTest.addAttribute(null, 1);
112:                assertSame(as1, as2);
113:            }
114:
115:            /**
116:             * Add the same attribute value but with different objects.
117:             * Check the returned sets are the same.
118:             */
119:            public void testAddAttributeSimilar() {
120:                AttributeSet as1 = sc.addAttribute(sc.getEmptySet(),
121:                        StyleConstants.FontSize, new Integer(10));
122:                AttributeSet as2 = sc.addAttribute(sc.getEmptySet(),
123:                        StyleConstants.FontSize, new Integer(10));
124:                assertSame(as1, as2);
125:            }
126:
127:            /**
128:             * Add the value into an attribute set twice using two
129:             * different objects.
130:             */
131:            public void testAddAttributeSimilarTwice() {
132:                AttributeSet as1 = sc.addAttribute(sc.getEmptySet(),
133:                        StyleConstants.FontSize, new Integer(10));
134:                AttributeSet as2 = sc.addAttribute(as1,
135:                        StyleConstants.FontSize, new Integer(10));
136:                assertSame(as1, as2);
137:                assertEquals(1, as1.getAttributeCount());
138:            }
139:
140:            /**
141:             * Add ten attributes into a set.
142:             */
143:            public void testAddAttributeTen() {
144:                AttributeSet as = StyleContextTest.addAttribute(10);
145:                assertEquals(10, as.getAttributeCount());
146:                assertTrue(as instanceof  SimpleAttributeSet);
147:            }
148:
149:            /**
150:             * Add three attributes into a set.
151:             */
152:            public void testAddAttributeThree() {
153:                AttributeSet as = StyleContextTest.addAttribute(3);
154:                assertEquals(3, as.getAttributeCount());
155:                assertTrue(as instanceof  SmallAttributeSet);
156:            }
157:
158:            /**
159:             * Add four attributes into a set, but one of them is used twice,
160:             * so the returned attribute set should contain only three ones.
161:             */
162:            public void testAddAttributeThreeSameKey() {
163:                AttributeSet as = StyleContextTest.addAttribute(3);
164:                as = sc.addAttribute(as, StyleConstants.Bold, Boolean.FALSE);
165:                assertEquals(3, as.getAttributeCount());
166:                assertTrue(as instanceof  SmallAttributeSet);
167:            }
168:
169:            /**
170:             * Add two attributes into a set.
171:             */
172:            public void testAddAttributeTwo() {
173:                AttributeSet as = StyleContextTest.addAttribute(2);
174:                assertEquals(2, as.getAttributeCount());
175:                assertTrue(as instanceof  SmallAttributeSet);
176:            }
177:
178:            /**
179:             * Create an attribute set of two elements. Then create the same
180:             * set using MutableAttributeSet implementor.
181:             */
182:            public void testAddMutable() {
183:                AttributeSet as = StyleContextTest.addAttribute(3);
184:                SimpleAttributeSet sas = new SimpleAttributeSet();
185:                int i;
186:                for (i = 0; i < 4; i += 2) {
187:                    sas.addAttribute(StyleContextTest.attr[i],
188:                            StyleContextTest.attr[i + 1]);
189:                }
190:                AttributeSet set = sc.addAttribute(sas,
191:                        StyleContextTest.attr[i], StyleContextTest.attr[i + 1]);
192:                assertEquals(3, set.getAttributeCount());
193:                assertSame(as, set);
194:            }
195:
196:            @Override
197:            protected void setUp() {
198:                sc = StyleContextTest.sc = new StyleContext();
199:            }
200:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.