Source Code Cross Referenced for TreeContentTest.java in  » Testing » UISpec4J » org » uispec4j » 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 » Testing » UISpec4J » org.uispec4j 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.uispec4j;
002:
003:        import junit.framework.AssertionFailedError;
004:        import org.uispec4j.utils.AssertionFailureNotDetectedError;
005:        import org.uispec4j.utils.DummyTreeCellRenderer;
006:        import org.uispec4j.utils.Functor;
007:
008:        import javax.swing.tree.DefaultMutableTreeNode;
009:        import java.awt.Color;
010:
011:        public class TreeContentTest extends TreeTestCase {
012:            public void testContentCheck() throws Exception {
013:                assertTrue(tree.contentEquals("root\n" + "  child1\n"
014:                        + "    child1_1\n" + "  child2"));
015:            }
016:
017:            public void testContentCheckWithEmptyExpectedStringError() {
018:                checkContainmentError("  ",
019:                        "Expected tree description should not be empty");
020:            }
021:
022:            public void testContentCheckWithErrors() throws Exception {
023:                checkContainmentError("root\n" + "  child1\n" + "    error\n"
024:                        + "  child2");
025:            }
026:
027:            public void testExpectedContentStringIsTrimmedInContainmentCheck()
028:                    throws Exception {
029:                assertTrue(tree.contentEquals("   root\n" + "  child1\n"
030:                        + "    child1_1\n" + "  child2\n"));
031:                assertTrue(tree.contentEquals("   root\n" + "  child1\n"
032:                        + "    child1_1\n" + "  child2\n \t "));
033:            }
034:
035:            public void testContentCheckWithPropertiesSpecification()
036:                    throws Exception {
037:                child1_1.setBold(true);
038:                child1_1.setColor(Color.RED);
039:                child2.setColor(Color.BLUE);
040:                assertTrue(tree.contentEquals("root\n" + "  child1\n"
041:                        + "    child1_1 #(bold,color=red)\n"
042:                        + "  child2 #(color=blue)"));
043:            }
044:
045:            public void testContentCheckWithMissingBoldnessError()
046:                    throws Exception {
047:                child1.setBold(true);
048:                checkContainmentError("root\n" + "  child1\n"
049:                        + "    child1_1\n" + "  child2");
050:            }
051:
052:            public void testContentCheckWithBoldnessError() throws Exception {
053:                child1.setBold(false);
054:                checkContainmentError("root\n" + "  child1 #(bold)\n"
055:                        + "    child1_1\n" + "  child2");
056:            }
057:
058:            public void testContentCheckAcceptsBothNumericAndHumanReadableValues()
059:                    throws Exception {
060:                child2.setColor(Color.BLUE);
061:                tree.contentEquals("root\n" + "  child1\n" + "    child1_1\n"
062:                        + "  child2 #(color=blue)");
063:                assertTrue(tree.contentEquals("root\n" + "  child1\n"
064:                        + "    child1_1\n" + "  child2 #(color=0000ff)"));
065:            }
066:
067:            public void testContentCheckWithMissingColorError()
068:                    throws Exception {
069:                child1.setColor(Color.BLUE);
070:                checkContainmentError("root\n" + "  child1\n"
071:                        + "    child1_1\n" + "  child2");
072:            }
073:
074:            public void testCheckContentsWithColorNameError() throws Exception {
075:                child1_1.setColor(Color.BLUE);
076:                checkAssertionFailedError(new Functor() {
077:                    public void run() throws Exception {
078:                        assertTrue(tree.contentEquals("root\n" + "  child1\n"
079:                                + "    child1_1 #(color=ERROR)\n" + "  child2"));
080:                    }
081:                }, "'ERROR' does not seem to be a color");
082:            }
083:
084:            public void testAssertContains() throws Exception {
085:                assertTrue(tree.contains("child1/child1_1"));
086:                try {
087:                    assertTrue(tree.contains("child1/unknown"));
088:                    throw new AssertionFailureNotDetectedError();
089:                } catch (AssertionFailedError e) {
090:                    assertEquals("Could not find element 'child1/unknown'", e
091:                            .getMessage());
092:                }
093:            }
094:
095:            public void testAssertContainsReallyChecksTheWholePath()
096:                    throws Exception {
097:                child1Node.add(new DefaultMutableTreeNode(
098:                        new DummyTreeCellRenderer.UserObject("child1_2")));
099:                assertTrue(tree.contains("child1/child1_2"));
100:            }
101:
102:            public void testSeparatorCustomisation() throws Exception {
103:                DefaultMutableTreeNode child3 = new DefaultMutableTreeNode(
104:                        new DummyTreeCellRenderer.UserObject("child/3"));
105:                rootNode.add(child3);
106:                child3.add(new DefaultMutableTreeNode(
107:                        new DummyTreeCellRenderer.UserObject("child/3 3")));
108:                tree.setSeparator(" | ");
109:                checkPath("child/3 | child/3 3");
110:                tree.setSeparator(" ## ");
111:                checkPath("child/3 ## child/3 3");
112:                tree.setSeparator("-");
113:                checkPath("child/3-child/3 3");
114:            }
115:
116:            private void checkPath(String path) {
117:                tree.contains(path);
118:                tree.select(path);
119:                assertTrue(tree.selectionEquals(path));
120:                tree.clearSelection();
121:                tree.click(path);
122:                assertTrue(tree.selectionEquals(path));
123:            }
124:
125:            public void testSeparatorCanBeSpecifiedAtTreeCreationTime()
126:                    throws Exception {
127:                String previousSeparator = Tree.defaultSeparator;
128:                System.getProperties().remove(Tree.SEPARATOR_PROPERTY);
129:                Tree.setDefaultSeparator("-*-");
130:
131:                Tree tree = new Tree(jTree);
132:                assertTrue(tree.contains("child1-*-child1_1"));
133:                System.setProperty(Tree.SEPARATOR_PROPERTY, "#");
134:                assertTrue(tree.contains("child1-*-child1_1"));
135:                tree = new Tree(jTree);
136:                assertTrue(tree.contains("child1#child1_1"));
137:
138:                System.getProperties().remove(Tree.SEPARATOR_PROPERTY);
139:                Tree.setDefaultSeparator(previousSeparator);
140:            }
141:
142:            public void testSeparatorCannotBeEmpty() throws Exception {
143:                try {
144:                    tree.setSeparator("");
145:                    throw new AssertionFailureNotDetectedError();
146:                } catch (IllegalArgumentException e) {
147:                    assertEquals("Separator must not be empty", e.getMessage());
148:                }
149:                try {
150:                    Tree.setDefaultSeparator("");
151:                    throw new AssertionFailureNotDetectedError();
152:                } catch (IllegalArgumentException e) {
153:                    assertEquals("Separator must not be empty", e.getMessage());
154:                }
155:
156:                System.setProperty(Tree.SEPARATOR_PROPERTY, "");
157:                Tree tree = new Tree(jTree);
158:                assertEquals("/", tree.getSeparator());
159:                System.getProperties().remove(Tree.SEPARATOR_PROPERTY);
160:            }
161:
162:            public void testSeparatorCannotBeNull() throws Exception {
163:                try {
164:                    tree.setSeparator(null);
165:                    throw new AssertionFailureNotDetectedError();
166:                } catch (IllegalArgumentException e) {
167:                    assertEquals("Separator must not be null", e.getMessage());
168:                }
169:                try {
170:                    Tree.setDefaultSeparator(null);
171:                    throw new AssertionFailureNotDetectedError();
172:                } catch (IllegalArgumentException e) {
173:                    assertEquals("Separator must not be null", e.getMessage());
174:                }
175:            }
176:
177:            public void testPathDefinitionsGivePriorityToExactNames()
178:                    throws Exception {
179:                rootNode.add(new DefaultMutableTreeNode(
180:                        new DummyTreeCellRenderer.UserObject("child1bis")));
181:                checkPath("child1/child1_1");
182:            }
183:
184:            public void testUsingASpecificConverter() throws Exception {
185:                tree.setCellValueConverter(new DummyTreeCellValueConverter());
186:                assertTrue(tree.contentEquals("_obj:root_\n"
187:                        + "  _obj:child1_\n" + "    _obj:child1_1_\n"
188:                        + "  _obj:child2_"));
189:                assertTrue(tree.contains("_obj:child1_/_obj:child1_1_"));
190:            }
191:
192:            public void testUsingASpecificConverterForColor() throws Exception {
193:                DummyTreeCellValueConverter converter = new DummyTreeCellValueConverter();
194:                converter.setRedFontPattern("child1");
195:                tree.setCellValueConverter(converter);
196:                assertTrue(tree.contentEquals("_obj:root_\n"
197:                        + "  _obj:child1_ #(color=FF0000)\n"
198:                        + "    _obj:child1_1_ #(color=FF0000)\n"
199:                        + "  _obj:child2_"));
200:            }
201:
202:            public void testUsingASpecificConverterForTextStyle()
203:                    throws Exception {
204:                DummyTreeCellValueConverter converter = new DummyTreeCellValueConverter();
205:                converter.setBoldPattern("child");
206:                tree.setCellValueConverter(converter);
207:                assertTrue(tree.contentEquals("_obj:root_\n"
208:                        + "  _obj:child1_ #(bold)\n"
209:                        + "    _obj:child1_1_ #(bold)\n"
210:                        + "  _obj:child2_ #(bold)"));
211:            }
212:
213:            public void testGetChildCount() throws Exception {
214:                assertEquals(2, tree.getChildCount(""));
215:                assertEquals(1, tree.getChildCount("child1"));
216:            }
217:
218:            public void testCheckForegroundColor() throws Exception {
219:                assertTrue(tree.foregroundEquals("", "black"));
220:                child1.setColor(new Color(250, 10, 10));
221:                assertTrue(tree.foregroundEquals("child1", "red"));
222:                try {
223:                    assertTrue(tree.foregroundEquals("child1", "green"));
224:                    throw new AssertionFailureNotDetectedError();
225:                } catch (AssertionFailedError e) {
226:                    assertEquals("expected:<GREEN> but was:<FA0A0A>", e
227:                            .getMessage());
228:                }
229:            }
230:
231:            public void testToString() throws Exception {
232:                assertEquals("root\n" + "  child1\n" + "    child1_1\n"
233:                        + "  child2\n", tree.toString());
234:            }
235:
236:            private void checkContainmentError(String expectedTree) {
237:                checkContainmentError(expectedTree, null);
238:            }
239:
240:            private void checkContainmentError(String expectedTree,
241:                    String message) {
242:                try {
243:                    assertTrue(tree.contentEquals(expectedTree));
244:                    throw new AssertionFailureNotDetectedError();
245:                } catch (AssertionFailedError e) {
246:                    if (message != null) {
247:                        assertEquals(message, e.getMessage());
248:                    }
249:                }
250:            }
251:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.