Source Code Cross Referenced for TitledBorderTest.java in  » Apache-Harmony-Java-SE » javax-package » javax » swing » border » 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.border 
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 Alexander T. Simbirtsev
019:         * @version $Revision$
020:         * Created on 02.12.2004
021:
022:         */package javax.swing.border;
023:
024:        import java.awt.Color;
025:        import java.awt.Component;
026:        import java.awt.Dimension;
027:        import java.awt.Font;
028:        import java.awt.FontMetrics;
029:        import java.awt.Insets;
030:        import javax.swing.JComponent;
031:        import javax.swing.JPanel;
032:        import javax.swing.SwingTestCase;
033:        import javax.swing.UIManager;
034:
035:        public class TitledBorderTest extends SwingTestCase {
036:            protected JComponent panel;
037:
038:            @Override
039:            protected void setUp() throws Exception {
040:                super .setUp();
041:                panel = new JPanel() {
042:                    private static final long serialVersionUID = 1L;
043:
044:                    @Override
045:                    public FontMetrics getFontMetrics(Font font) {
046:                        return TitledBorderTest.this .getFontMetrics(font);
047:                    }
048:                };
049:            }
050:
051:            @Override
052:            protected void tearDown() throws Exception {
053:                panel = null;
054:            }
055:
056:            /*
057:             * Class under test for void TitledBorder(Border, String, int, int, Font, Color)
058:             */
059:            public void testTitledBorderBorderStringintintFontColor() {
060:                Color color1 = Color.GREEN;
061:                Color color2 = null;
062:                Font font1 = new Font(null, Font.TRUETYPE_FONT, 30);
063:                Font font2 = null;
064:                String string1 = "string1";
065:                String string2 = null;
066:                Border border3 = new EmptyBorder(1, 1, 1, 1);
067:                Border border4 = null;
068:                int just1 = 1;
069:                int just2 = 2;
070:                int pos1 = 1;
071:                int pos2 = 2;
072:                TitledBorder border1 = new TitledBorder(border3, string1,
073:                        just1, pos1, font1, color1);
074:                TitledBorder border2 = new TitledBorder(border4, string2,
075:                        just2, pos2, font2, color2);
076:                assertEquals("title field initialized correctly ", string1,
077:                        border1.getTitle());
078:                assertEquals("border field initialized correctly ", border3,
079:                        border1.getBorder());
080:                assertEquals("color field initialized correctly ", color1,
081:                        border1.getTitleColor());
082:                assertEquals("font field initialized correctly ", font1,
083:                        border1.getTitleFont());
084:                assertEquals("position field initialized correctly ", pos1,
085:                        border1.getTitlePosition());
086:                assertEquals("justification field initialized correctly ",
087:                        just1, border1.getTitleJustification());
088:                assertEquals("title field initialized correctly ", string2,
089:                        border2.getTitle());
090:                assertEquals("border field initialized correctly ", UIManager
091:                        .getDefaults().getBorder("TitledBorder.border"),
092:                        border2.getBorder());
093:                assertEquals("color field initialized correctly ", UIManager
094:                        .getDefaults().getColor("TitledBorder.titleColor"),
095:                        border2.getTitleColor());
096:                assertEquals("font field initialized correctly ", UIManager
097:                        .getDefaults().getFont("TitledBorder.font"), border2
098:                        .getTitleFont());
099:                assertEquals("position field initialized correctly ", pos2,
100:                        border2.getTitlePosition());
101:                assertEquals("justification field initialized correctly ",
102:                        just2, border2.getTitleJustification());
103:            }
104:
105:            /*
106:             * Class under test for void TitledBorder(Border, String, int, int, Font)
107:             */
108:            public void testTitledBorderBorderStringintintFont() {
109:                Font font1 = new Font(null, Font.TRUETYPE_FONT, 30);
110:                Font font2 = null;
111:                String string1 = "string1";
112:                String string2 = null;
113:                Border border3 = new EmptyBorder(1, 1, 1, 1);
114:                Border border4 = null;
115:                int just1 = 1;
116:                int just2 = 2;
117:                int pos1 = 1;
118:                int pos2 = 2;
119:                TitledBorder border1 = new TitledBorder(border3, string1,
120:                        just1, pos1, font1);
121:                TitledBorder border2 = new TitledBorder(border4, string2,
122:                        just2, pos2, font2);
123:                assertEquals("title field initialized correctly ", string1,
124:                        border1.getTitle());
125:                assertEquals("border field initialized correctly ", border3,
126:                        border1.getBorder());
127:                assertEquals("color field initialized correctly ", UIManager
128:                        .getDefaults().getColor("TitledBorder.titleColor"),
129:                        border1.getTitleColor());
130:                assertEquals("font field initialized correctly ", font1,
131:                        border1.getTitleFont());
132:                assertEquals("position field initialized correctly ", pos1,
133:                        border1.getTitlePosition());
134:                assertEquals("justification field initialized correctly ",
135:                        just1, border1.getTitleJustification());
136:                assertEquals("title field initialized correctly ", string2,
137:                        border2.getTitle());
138:                assertEquals("border field initialized correctly ", UIManager
139:                        .getDefaults().getBorder("TitledBorder.border"),
140:                        border2.getBorder());
141:                assertEquals("color field initialized correctly ", UIManager
142:                        .getDefaults().getColor("TitledBorder.titleColor"),
143:                        border2.getTitleColor());
144:                assertEquals("font field initialized correctly ", UIManager
145:                        .getDefaults().getFont("TitledBorder.font"), border2
146:                        .getTitleFont());
147:                assertEquals("position field initialized correctly ", pos2,
148:                        border2.getTitlePosition());
149:                assertEquals("justification field initialized correctly ",
150:                        just2, border2.getTitleJustification());
151:            }
152:
153:            /*
154:             * Class under test for void TitledBorder(Border, String, int, int)
155:             */
156:            public void testTitledBorderBorderStringintint() {
157:                String string1 = "string1";
158:                String string2 = null;
159:                Border border3 = new EmptyBorder(1, 1, 1, 1);
160:                Border border4 = null;
161:                int just1 = 1;
162:                int just2 = 2;
163:                int pos1 = 1;
164:                int pos2 = 2;
165:                TitledBorder border1 = new TitledBorder(border3, string1,
166:                        just1, pos1);
167:                TitledBorder border2 = new TitledBorder(border4, string2,
168:                        just2, pos2);
169:                assertEquals("title field initialized correctly ", string1,
170:                        border1.getTitle());
171:                assertEquals("border field initialized correctly ", border3,
172:                        border1.getBorder());
173:                assertEquals("color field initialized correctly ", UIManager
174:                        .getDefaults().getColor("TitledBorder.titleColor"),
175:                        border1.getTitleColor());
176:                assertEquals("font field initialized correctly ", UIManager
177:                        .getDefaults().getFont("TitledBorder.font"), border1
178:                        .getTitleFont());
179:                assertEquals("position field initialized correctly ", pos1,
180:                        border1.getTitlePosition());
181:                assertEquals("justification field initialized correctly ",
182:                        just1, border1.getTitleJustification());
183:                assertEquals("title field initialized correctly ", string2,
184:                        border2.getTitle());
185:                assertEquals("border field initialized correctly ", UIManager
186:                        .getDefaults().getBorder("TitledBorder.border"),
187:                        border2.getBorder());
188:                assertEquals("color field initialized correctly ", UIManager
189:                        .getDefaults().getColor("TitledBorder.titleColor"),
190:                        border2.getTitleColor());
191:                assertEquals("font field initialized correctly ", UIManager
192:                        .getDefaults().getFont("TitledBorder.font"), border2
193:                        .getTitleFont());
194:                assertEquals("position field initialized correctly ", pos2,
195:                        border2.getTitlePosition());
196:                assertEquals("justification field initialized correctly ",
197:                        just2, border2.getTitleJustification());
198:            }
199:
200:            /*
201:             * Class under test for void TitledBorder(Border, String)
202:             */
203:            public void testTitledBorderBorderString() {
204:                String string1 = "string1";
205:                String string2 = null;
206:                Border border3 = new EmptyBorder(1, 1, 1, 1);
207:                Border border4 = null;
208:                TitledBorder border1 = new TitledBorder(border3, string1);
209:                TitledBorder border2 = new TitledBorder(border4, string2);
210:                assertEquals("title field initialized correctly ", string1,
211:                        border1.getTitle());
212:                assertEquals("border field initialized correctly ", border3,
213:                        border1.getBorder());
214:                assertEquals("color field initialized correctly ", UIManager
215:                        .getDefaults().getColor("TitledBorder.titleColor"),
216:                        border1.getTitleColor());
217:                assertEquals("font field initialized correctly ", UIManager
218:                        .getDefaults().getFont("TitledBorder.font"), border1
219:                        .getTitleFont());
220:                assertEquals("position field initialized correctly ",
221:                        TitledBorder.TOP, border1.getTitlePosition());
222:                assertEquals("justification field initialized correctly ",
223:                        TitledBorder.LEADING, border1.getTitleJustification());
224:                assertEquals("title field initialized correctly ", string2,
225:                        border2.getTitle());
226:                assertEquals("border field initialized correctly ", UIManager
227:                        .getDefaults().getBorder("TitledBorder.border"),
228:                        border2.getBorder());
229:                assertEquals("color field initialized correctly ", UIManager
230:                        .getDefaults().getColor("TitledBorder.titleColor"),
231:                        border2.getTitleColor());
232:                assertEquals("font field initialized correctly ", UIManager
233:                        .getDefaults().getFont("TitledBorder.font"), border2
234:                        .getTitleFont());
235:                assertEquals("position field initialized correctly ",
236:                        TitledBorder.TOP, border2.getTitlePosition());
237:                assertEquals("justification field initialized correctly ",
238:                        TitledBorder.LEADING, border2.getTitleJustification());
239:            }
240:
241:            /*
242:             * Class under test for void TitledBorder(Border)
243:             */
244:            public void testTitledBorderBorder() {
245:                Border border3 = new EmptyBorder(1, 1, 1, 1);
246:                Border border4 = null;
247:                TitledBorder border1 = new TitledBorder(border3);
248:                TitledBorder border2 = new TitledBorder(border4);
249:                assertEquals("title field initialized correctly ", "", border1
250:                        .getTitle());
251:                assertEquals("border field initialized correctly ", border3,
252:                        border1.getBorder());
253:                assertEquals("color field initialized correctly ", UIManager
254:                        .getDefaults().getColor("TitledBorder.titleColor"),
255:                        border1.getTitleColor());
256:                assertEquals("font field initialized correctly ", UIManager
257:                        .getDefaults().getFont("TitledBorder.font"), border1
258:                        .getTitleFont());
259:                assertEquals("position field initialized correctly ",
260:                        TitledBorder.TOP, border1.getTitlePosition());
261:                assertEquals("justification field initialized correctly ",
262:                        TitledBorder.LEADING, border1.getTitleJustification());
263:                assertEquals("title field initialized correctly ", "", border2
264:                        .getTitle());
265:                assertEquals("border field initialized correctly ", UIManager
266:                        .getDefaults().getBorder("TitledBorder.border"),
267:                        border2.getBorder());
268:                assertEquals("color field initialized correctly ", UIManager
269:                        .getDefaults().getColor("TitledBorder.titleColor"),
270:                        border2.getTitleColor());
271:                assertEquals("font field initialized correctly ", UIManager
272:                        .getDefaults().getFont("TitledBorder.font"), border2
273:                        .getTitleFont());
274:                assertEquals("position field initialized correctly ",
275:                        TitledBorder.TOP, border2.getTitlePosition());
276:                assertEquals("justification field initialized correctly ",
277:                        TitledBorder.LEADING, border2.getTitleJustification());
278:            }
279:
280:            /*
281:             * Class under test for void TitledBorder(String)
282:             */
283:            public void testTitledBorderString() {
284:                String string1 = "string1";
285:                String string2 = null;
286:                TitledBorder border1 = new TitledBorder(string1);
287:                TitledBorder border2 = new TitledBorder(string2);
288:                assertEquals("title field initialized correctly ", string1,
289:                        border1.getTitle());
290:                assertEquals("border field initialized correctly ", UIManager
291:                        .getDefaults().getBorder("TitledBorder.border"),
292:                        border1.getBorder());
293:                assertEquals("color field initialized correctly ", UIManager
294:                        .getDefaults().getColor("TitledBorder.titleColor"),
295:                        border1.getTitleColor());
296:                assertEquals("font field initialized correctly ", UIManager
297:                        .getDefaults().getFont("TitledBorder.font"), border1
298:                        .getTitleFont());
299:                assertEquals("position field initialized correctly ",
300:                        TitledBorder.TOP, border1.getTitlePosition());
301:                assertEquals("justification field initialized correctly ",
302:                        TitledBorder.LEADING, border1.getTitleJustification());
303:                assertEquals("title field initialized correctly ", string2,
304:                        border2.getTitle());
305:                assertEquals("border field initialized correctly ", UIManager
306:                        .getDefaults().getBorder("TitledBorder.border"),
307:                        border2.getBorder());
308:                assertEquals("color field initialized correctly ", UIManager
309:                        .getDefaults().getColor("TitledBorder.titleColor"),
310:                        border2.getTitleColor());
311:                assertEquals("font field initialized correctly ", UIManager
312:                        .getDefaults().getFont("TitledBorder.font"), border2
313:                        .getTitleFont());
314:                assertEquals("position field initialized correctly ",
315:                        TitledBorder.TOP, border2.getTitlePosition());
316:                assertEquals("justification field initialized correctly ",
317:                        TitledBorder.LEADING, border2.getTitleJustification());
318:            }
319:
320:            /*
321:             * Class under test for Insets getBorderInsets(Component, Insets)
322:             */
323:            public void testGetBorderInsetsComponentInsets() {
324:                Insets insets = new Insets(0, 0, 0, 0);
325:                Font font1 = new Font(null, Font.BOLD, 10);
326:                Font font2 = new Font(null, Font.ITALIC, 20);
327:                Border border1 = new EmptyBorder(10, 10, 10, 10);
328:                Border border2 = new EmptyBorder(20, 20, 20, 20);
329:                TitledBorder titledBorder = new TitledBorder("");
330:                assertEquals("insets sizes coincide ", new Insets(5, 5, 5, 5),
331:                        titledBorder.getBorderInsets(panel, insets));
332:                titledBorder.setTitle("_");
333:                assertEquals("insets sizes coincide ", new Insets(41, 5, 5, 5),
334:                        titledBorder.getBorderInsets(panel));
335:                titledBorder.setTitle("_____");
336:                assertEquals("insets sizes coincide ", new Insets(41, 5, 5, 5),
337:                        titledBorder.getBorderInsets(panel));
338:                titledBorder.setBorder(border1);
339:                assertEquals("insets sizes coincide ", new Insets(50, 14, 14,
340:                        14), titledBorder.getBorderInsets(panel));
341:                titledBorder.setBorder(border2);
342:                assertEquals("insets sizes coincide ", new Insets(60, 24, 24,
343:                        24), titledBorder.getBorderInsets(panel));
344:                titledBorder.setTitleFont(font1);
345:                assertEquals("insets sizes coincide ", new Insets(54, 24, 24,
346:                        24), titledBorder.getBorderInsets(panel));
347:                titledBorder.setTitleFont(font2);
348:                assertEquals("insets sizes coincide ", new Insets(84, 24, 24,
349:                        24), titledBorder.getBorderInsets(panel));
350:            }
351:
352:            /*
353:             * Class under test for Insets getBorderInsets(Component)
354:             */
355:            public void testGetBorderInsetsComponent() {
356:                Font font1 = new Font(null, Font.BOLD, 10);
357:                Font font2 = new Font(null, Font.ITALIC, 20);
358:                Border border1 = new EmptyBorder(10, 10, 10, 10);
359:                Border border2 = new EmptyBorder(20, 20, 20, 20);
360:                TitledBorder titledBorder = new TitledBorder("");
361:                assertEquals("insets sizes coincide ", new Insets(5, 5, 5, 5),
362:                        titledBorder.getBorderInsets(panel));
363:                titledBorder.setTitle("_");
364:                assertEquals("insets sizes coincide ", new Insets(41, 5, 5, 5),
365:                        titledBorder.getBorderInsets(panel));
366:                titledBorder.setTitle("_____");
367:                assertEquals("insets sizes coincide ", new Insets(41, 5, 5, 5),
368:                        titledBorder.getBorderInsets(panel));
369:                titledBorder.setBorder(border1);
370:                assertEquals("insets sizes coincide ", new Insets(50, 14, 14,
371:                        14), titledBorder.getBorderInsets(panel));
372:                titledBorder.setBorder(border2);
373:                assertEquals("insets sizes coincide ", new Insets(60, 24, 24,
374:                        24), titledBorder.getBorderInsets(panel));
375:                titledBorder.setTitleFont(font1);
376:                assertEquals("insets sizes coincide ", new Insets(54, 24, 24,
377:                        24), titledBorder.getBorderInsets(panel));
378:                titledBorder.setTitleFont(font2);
379:                assertEquals("insets sizes coincide ", new Insets(84, 24, 24,
380:                        24), titledBorder.getBorderInsets(panel));
381:                titledBorder.setTitlePosition(TitledBorder.ABOVE_TOP);
382:                assertEquals("insets sizes coincide ", new Insets(86, 24, 24,
383:                        24), titledBorder.getBorderInsets(panel));
384:                titledBorder.setTitlePosition(TitledBorder.BELOW_TOP);
385:                assertEquals("insets sizes coincide ", new Insets(86, 24, 24,
386:                        24), titledBorder.getBorderInsets(panel));
387:                titledBorder.setTitlePosition(TitledBorder.TOP);
388:                assertEquals("insets sizes coincide ", new Insets(84, 24, 24,
389:                        24), titledBorder.getBorderInsets(panel));
390:                titledBorder.setTitlePosition(TitledBorder.ABOVE_BOTTOM);
391:                assertEquals("insets sizes coincide ", new Insets(24, 24, 86,
392:                        24), titledBorder.getBorderInsets(panel));
393:                titledBorder.setTitlePosition(TitledBorder.BELOW_BOTTOM);
394:                assertEquals("insets sizes coincide ", new Insets(24, 24, 86,
395:                        24), titledBorder.getBorderInsets(panel));
396:                titledBorder.setTitlePosition(TitledBorder.BOTTOM);
397:                assertEquals("insets sizes coincide ", new Insets(24, 24, 84,
398:                        24), titledBorder.getBorderInsets(panel));
399:            }
400:
401:            public void testPaintBorder() {
402:                //        int numJust = 6;
403:                //        int numPos = 7;
404:                //        String title = "Title";
405:                //        JPanel mainPanel = new JPanel();
406:                //
407:                //        JFrame frame = new JFrame();
408:                //        mainPanel.setLayout(new GridLayout(numJust, numPos));
409:                //        for (int iPanel = 0; iPanel < numJust*numPos; iPanel++) {
410:                //            Border border = new TitledBorder(new LineBorder(Color.RED, 10), title, iPanel/numPos, iPanel%numPos);
411:                //            JPanel panel = new JPanel();
412:                //            panel.setBorder(border);
413:                //            panel.setPreferredSize(new Dimension(150, 150));
414:                //            mainPanel.add(panel);
415:                //        }
416:                //        frame.getContentPane().add(mainPanel);
417:                //        frame.pack();
418:                //        frame.show();
419:                //        while(!frame.isActive());
420:                //        while(frame.isActive());
421:            }
422:
423:            public void testIsBorderOpaque() {
424:                Border border1 = new TitledBorder("Text");
425:                Border border2 = new TitledBorder(new LineBorder(Color.WHITE));
426:                Border border3 = new TitledBorder(new LineBorder(Color.WHITE),
427:                        "Text");
428:                assertFalse("TitledBorder is not opaque ", border1
429:                        .isBorderOpaque());
430:                assertFalse("TitledBorder is not opaque ", border2
431:                        .isBorderOpaque());
432:                assertFalse("TitledBorder is not opaque ", border3
433:                        .isBorderOpaque());
434:            }
435:
436:            public void testGetFont() {
437:                class PublicTitledBorder extends TitledBorder {
438:                    private static final long serialVersionUID = 1L;
439:
440:                    PublicTitledBorder(final String title) {
441:                        super (title);
442:                    }
443:
444:                    @Override
445:                    public Font getFont(final Component c) {
446:                        return super .getFont(c);
447:                    }
448:                }
449:                ;
450:                PublicTitledBorder titledBorder = new PublicTitledBorder(
451:                        "hello, border!!");
452:                Font newFont1 = new Font(null, Font.BOLD, 10);
453:                Font newFont2 = new Font(null, Font.ITALIC, 20);
454:                Font newFont3 = new Font(null, Font.TRUETYPE_FONT, 30);
455:                Font newFont4 = null;
456:                titledBorder.setTitleFont(newFont1);
457:                assertEquals("fonts coincide ", newFont1, titledBorder
458:                        .getFont(null));
459:                titledBorder.setTitleFont(newFont2);
460:                assertEquals("fonts coincide ", newFont2, titledBorder
461:                        .getFont(null));
462:                titledBorder.setTitleFont(newFont3);
463:                assertEquals("fonts coincide ", newFont3, titledBorder
464:                        .getFont(null));
465:                titledBorder.setTitleFont(newFont4);
466:                assertFalse("font cannot be null ",
467:                        titledBorder.getFont(null) == null);
468:                assertEquals("font cannot be null ",
469:                        "class javax.swing.plaf.FontUIResource", titledBorder
470:                                .getFont(null).getClass().toString());
471:            }
472:
473:            public void testGetMinimumSize() {
474:                Font font1 = new Font(null, Font.BOLD, 10);
475:                Font font2 = new Font(null, Font.ITALIC, 20);
476:                Border border1 = new EmptyBorder(10, 10, 10, 10);
477:                Border border2 = new EmptyBorder(20, 20, 20, 20);
478:                TitledBorder titledBorder = new TitledBorder("");
479:                assertEquals("minimum sizes coincide ", new Dimension(10, 10),
480:                        titledBorder.getMinimumSize(panel));
481:                titledBorder.setTitle("_");
482:                assertEquals("minimum sizes coincide ", new Dimension(22, 46),
483:                        titledBorder.getMinimumSize(panel));
484:                titledBorder.setTitle("_____");
485:                assertEquals("minimum sizes coincide ", new Dimension(70, 46),
486:                        titledBorder.getMinimumSize(panel));
487:                titledBorder.setBorder(border1);
488:                assertEquals("minimum sizes coincide ", new Dimension(88, 64),
489:                        titledBorder.getMinimumSize(panel));
490:                titledBorder.setBorder(border2);
491:                assertEquals("minimum sizes coincide ", new Dimension(108, 84),
492:                        titledBorder.getMinimumSize(panel));
493:                titledBorder.setTitleFont(font1);
494:                assertEquals("minimum sizes coincide ", new Dimension(98, 78),
495:                        titledBorder.getMinimumSize(panel));
496:                titledBorder.setTitleFont(font2);
497:                assertEquals("minimum sizes coincide ",
498:                        new Dimension(148, 108), titledBorder
499:                                .getMinimumSize(panel));
500:            }
501:
502:            /**
503:             * This method is being tested in testGetBorder()
504:             */
505:            public void testSetBorder() {
506:            }
507:
508:            public void testGetBorder() {
509:                TitledBorder titledBorder = new TitledBorder("hello, border!!");
510:                Border border1 = new EmptyBorder(1, 1, 1, 1);
511:                Border border2 = new EmptyBorder(2, 2, 2, 2);
512:                Border border3 = new EmptyBorder(3, 3, 3, 3);
513:                titledBorder.setBorder(border1);
514:                assertEquals("borders coincide ", border1, titledBorder
515:                        .getBorder());
516:                titledBorder.setBorder(border2);
517:                assertEquals("borders coincide ", border2, titledBorder
518:                        .getBorder());
519:                titledBorder.setBorder(border3);
520:                assertEquals("borders coincide ", border3, titledBorder
521:                        .getBorder());
522:                titledBorder.setBorder(null);
523:                assertFalse("border cannot be null ",
524:                        titledBorder.getBorder() == null);
525:                assertEquals(
526:                        "border cannot be null ",
527:                        "class javax.swing.plaf.BorderUIResource$LineBorderUIResource",
528:                        titledBorder.getBorder().getClass().toString());
529:            }
530:
531:            /**
532:             * This method is being tested in testGetTitle()
533:             */
534:            public void testSetTitle() {
535:            }
536:
537:            public void testGetTitle() {
538:                TitledBorder titledBorder = new TitledBorder("hello, border!!");
539:                String string1 = "string1";
540:                String string2 = "string2";
541:                String string3 = "string3";
542:                String string4 = null;
543:                titledBorder.setTitle(string1);
544:                assertEquals("titles coincide ", string1, titledBorder
545:                        .getTitle());
546:                titledBorder.setTitle(string2);
547:                assertEquals("titles coincide ", string2, titledBorder
548:                        .getTitle());
549:                titledBorder.setTitle(string3);
550:                assertEquals("titles coincide ", string3, titledBorder
551:                        .getTitle());
552:                titledBorder.setTitle(string4);
553:                assertEquals("titles coincide ", string4, titledBorder
554:                        .getTitle());
555:            }
556:
557:            /**
558:             * This method is being tested in testGetTitleFont()
559:             */
560:            public void testSetTitleFont() {
561:            }
562:
563:            public void testGetTitleFont() {
564:                TitledBorder titledBorder = new TitledBorder("hello, border!!");
565:                Font newFont1 = new Font(null, Font.BOLD, 10);
566:                Font newFont2 = new Font(null, Font.ITALIC, 20);
567:                Font newFont3 = new Font(null, Font.TRUETYPE_FONT, 30);
568:                Font newFont4 = null;
569:                titledBorder.setTitleFont(newFont1);
570:                assertEquals("fonts coincide ", newFont1, titledBorder
571:                        .getTitleFont());
572:                titledBorder.setTitleFont(newFont2);
573:                assertEquals("fonts coincide ", newFont2, titledBorder
574:                        .getTitleFont());
575:                titledBorder.setTitleFont(newFont3);
576:                assertEquals("fonts coincide ", newFont3, titledBorder
577:                        .getTitleFont());
578:                titledBorder.setTitleFont(newFont4);
579:                assertFalse("font cannot be null ",
580:                        titledBorder.getTitleFont() == null);
581:                assertEquals("font cannot be null ",
582:                        "class javax.swing.plaf.FontUIResource", titledBorder
583:                                .getTitleFont().getClass().toString());
584:            }
585:
586:            /**
587:             * This method is being tested in testGetTitleColor()
588:             */
589:            public void testSetTitleColor() {
590:            }
591:
592:            public void testGetTitleColor() {
593:                TitledBorder titledBorder = new TitledBorder("hello, border!!");
594:                Color color1 = Color.RED;
595:                Color color2 = Color.YELLOW;
596:                Color color3 = Color.GREEN;
597:                Color color4 = null;
598:                titledBorder.setTitleColor(color1);
599:                assertEquals("colors coincide ", color1, titledBorder
600:                        .getTitleColor());
601:                titledBorder.setTitleColor(color2);
602:                assertEquals("colors coincide ", color2, titledBorder
603:                        .getTitleColor());
604:                titledBorder.setTitleColor(color3);
605:                assertEquals("colors coincide ", color3, titledBorder
606:                        .getTitleColor());
607:                titledBorder.setTitleColor(color4);
608:                assertFalse("color cannot be null ", titledBorder
609:                        .getTitleColor() == null);
610:                assertEquals("color cannot be null",
611:                        "class javax.swing.plaf.ColorUIResource", titledBorder
612:                                .getTitleColor().getClass().toString());
613:            }
614:
615:            /**
616:             * This method is being tested in testGetTitlePosition()
617:             */
618:            public void testSetTitlePosition() {
619:            }
620:
621:            public void testGetTitlePosition() {
622:                TitledBorder titledBorder = new TitledBorder("hello, border!!");
623:                int pos1 = 0;
624:                int pos2 = 3;
625:                int pos3 = 6;
626:                int pos4 = 7;
627:                int pos5 = -1;
628:                titledBorder.setTitlePosition(pos1);
629:                assertEquals("title positions coincide ", pos1, titledBorder
630:                        .getTitlePosition());
631:                titledBorder.setTitlePosition(pos2);
632:                assertEquals("title positions coincide ", pos2, titledBorder
633:                        .getTitlePosition());
634:                titledBorder.setTitlePosition(pos3);
635:                assertEquals("title positions coincide ", pos3, titledBorder
636:                        .getTitlePosition());
637:                String exText = null;
638:                try {
639:                    titledBorder.setTitlePosition(pos4);
640:                } catch (IllegalArgumentException e) {
641:                    exText = e.getMessage();
642:                }
643:                assertEquals(pos4 + " is not a valid title position.", exText);
644:                exText = null;
645:                try {
646:                    titledBorder.setTitlePosition(pos5);
647:                } catch (IllegalArgumentException e) {
648:                    exText = e.getMessage();
649:                }
650:                assertEquals(pos5 + " is not a valid title position.", exText);
651:            }
652:
653:            /**
654:             * This method is being tested in testGetTitleJustification()
655:             */
656:            public void testSetTitleJustification() {
657:            }
658:
659:            public void testGetTitleJustification() {
660:                TitledBorder titledBorder = new TitledBorder("hello, border!!");
661:                int just1 = 0;
662:                int just2 = 3;
663:                int just3 = 5;
664:                int just4 = -1;
665:                int just5 = 6;
666:                titledBorder.setTitleJustification(just1);
667:                assertEquals("title justifications coincide ", just1,
668:                        titledBorder.getTitleJustification());
669:                titledBorder.setTitleJustification(just2);
670:                assertEquals("title justifications coincide ", just2,
671:                        titledBorder.getTitleJustification());
672:                titledBorder.setTitleJustification(just3);
673:                assertEquals("title justifications coincide ", just3,
674:                        titledBorder.getTitleJustification());
675:                String exText = null;
676:                try {
677:                    titledBorder.setTitleJustification(just4);
678:                } catch (IllegalArgumentException e) {
679:                    exText = e.getMessage();
680:                }
681:                assertEquals(just4 + " is not a valid title justification.",
682:                        exText);
683:                exText = null;
684:                try {
685:                    titledBorder.setTitleJustification(just5);
686:                } catch (IllegalArgumentException e) {
687:                    exText = e.getMessage();
688:                }
689:                assertEquals(just5 + " is not a valid title justification.",
690:                        exText);
691:            }
692:
693:            public void testReadWriteObject() throws Exception {
694:                Border border3 = new LineBorder(Color.red, 33, false);
695:                String title4 = "new LineBorder(Color.yellow, 47, true);";
696:                TitledBorder border1 = new TitledBorder(border3);
697:                TitledBorder border2 = new TitledBorder(title4);
698:                TitledBorder resurrectedBorder = (TitledBorder) serializeObject(border1);
699:                assertNotNull(resurrectedBorder);
700:                assertEquals("Deserialized values coincides", resurrectedBorder
701:                        .getTitle(), border1.getTitle());
702:                assertEquals("Deserialized values coincides", resurrectedBorder
703:                        .getTitleColor(), border1.getTitleColor());
704:                assertEquals("Deserialized values coincides", resurrectedBorder
705:                        .getBorder().getClass(), border1.getBorder().getClass());
706:                resurrectedBorder = (TitledBorder) serializeObject(border2);
707:                assertNotNull(resurrectedBorder);
708:                assertEquals("Deserialized values coincides", resurrectedBorder
709:                        .getTitle(), border2.getTitle());
710:                assertEquals("Deserialized values coincides", resurrectedBorder
711:                        .getTitleColor(), border2.getTitleColor());
712:                assertEquals("Deserialized values coincides", resurrectedBorder
713:                        .getBorder().getClass(), border2.getBorder().getClass());
714:            }
715:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.