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


001:        package org.junit.runner;
002:
003:        import java.lang.annotation.Annotation;
004:        import java.util.ArrayList;
005:        import java.util.Arrays;
006:        import java.util.Collection;
007:
008:        /**
009:         * <p>A <code>Description</code> describes a test which is to be run or has been run. <code>Descriptions</code> 
010:         * can be atomic (a single test) or compound (containing children tests). <code>Descriptions</code> are used
011:         * to provide feedback about the tests that are about to run (for example, the tree view
012:         * visible in many IDEs) or tests that have been run (for example, the failures view).</p>
013:         * 
014:         * <p><code>Descriptions</code> are implemented as a single class rather than a Composite because
015:         * they are entirely informational. They contain no logic aside from counting their tests.</p>
016:         * 
017:         * <p>In the past, we used the raw {@link junit.framework.TestCase}s and {@link junit.framework.TestSuite}s
018:         * to display the tree of tests. This was no longer viable in JUnit 4 because atomic tests no longer have 
019:         * a superclass below {@link Object}. We needed a way to pass a class and name together. Description 
020:         * emerged from this.</p>
021:         * 
022:         * @see org.junit.runner.Request
023:         * @see org.junit.runner.Runner
024:         */
025:        public class Description {
026:
027:            /**
028:             * Create a <code>Description</code> named <code>name</code>.
029:             * Generally, you will add children to this <code>Description</code>.
030:             * @param name the name of the <code>Description</code> 
031:             * @param annotations 
032:             * @return a <code>Description</code> named <code>name</code>
033:             */
034:            public static Description createSuiteDescription(String name,
035:                    Annotation... annotations) {
036:                return new Description(name, annotations);
037:            }
038:
039:            /**
040:             * Create a <code>Description</code> of a single test named <code>name</code> in the class <code>clazz</code>.
041:             * Generally, this will be a leaf <code>Description</code>.
042:             * @param clazz the class of the test
043:             * @param name the name of the test (a method name for test annotated with {@link org.junit.Test})
044:             * @param annotations meta-data about the test, for downstream interpreters
045:             * @return a <code>Description</code> named <code>name</code>
046:             */
047:            public static Description createTestDescription(Class<?> clazz,
048:                    String name, Annotation... annotations) {
049:                return new Description(String.format("%s(%s)", name, clazz
050:                        .getName()), annotations);
051:            }
052:
053:            /**
054:             * Create a <code>Description</code> of a single test named <code>name</code> in the class <code>clazz</code>.
055:             * Generally, this will be a leaf <code>Description</code>.  
056:             * (This remains for binary compatibility with clients of JUnit 4.3)
057:             * @param clazz the class of the test
058:             * @param name the name of the test (a method name for test annotated with {@link org.junit.Test})
059:             * @return a <code>Description</code> named <code>name</code>
060:             */
061:            public static Description createTestDescription(Class<?> clazz,
062:                    String name) {
063:                return createTestDescription(clazz, name, new Annotation[0]);
064:            }
065:
066:            /**
067:             * Create a <code>Description</code> named after <code>testClass</code>
068:             * @param testClass A {@link Class} containing tests 
069:             * @return a <code>Description</code> of <code>testClass</code>
070:             */
071:            public static Description createSuiteDescription(Class<?> testClass) {
072:                return new Description(testClass.getName(), testClass
073:                        .getAnnotations());
074:            }
075:
076:            public static final Description EMPTY = new Description("No Tests");
077:            public static final Description TEST_MECHANISM = new Description(
078:                    "Test mechanism");
079:
080:            private final ArrayList<Description> fChildren = new ArrayList<Description>();
081:            private final String fDisplayName;
082:
083:            private final Annotation[] fAnnotations;
084:
085:            private Description(final String displayName,
086:                    Annotation... annotations) {
087:                fDisplayName = displayName;
088:                fAnnotations = annotations;
089:            }
090:
091:            /**
092:             * @return a user-understandable label
093:             */
094:            public String getDisplayName() {
095:                return fDisplayName;
096:            }
097:
098:            /**
099:             * Add <code>Description</code> as a child of the receiver.
100:             * @param description the soon-to-be child.
101:             */
102:            public void addChild(Description description) {
103:                getChildren().add(description);
104:            }
105:
106:            /**
107:             * @return the receiver's children, if any
108:             */
109:            public ArrayList<Description> getChildren() {
110:                return fChildren;
111:            }
112:
113:            /**
114:             * @return <code>true</code> if the receiver is a suite
115:             */
116:            public boolean isSuite() {
117:                return !isTest();
118:            }
119:
120:            /**
121:             * @return <code>true</code> if the receiver is an atomic test
122:             */
123:            public boolean isTest() {
124:                return getChildren().isEmpty();
125:            }
126:
127:            /**
128:             * @return the total number of atomic tests in the receiver
129:             */
130:            public int testCount() {
131:                if (isTest())
132:                    return 1;
133:                int result = 0;
134:                for (Description child : getChildren())
135:                    result += child.testCount();
136:                return result;
137:            }
138:
139:            @Override
140:            public int hashCode() {
141:                return getDisplayName().hashCode();
142:            }
143:
144:            @Override
145:            public boolean equals(Object obj) {
146:                if (!(obj instanceof  Description))
147:                    return false;
148:                Description d = (Description) obj;
149:                return getDisplayName().equals(d.getDisplayName())
150:                        && getChildren().equals(d.getChildren());
151:            }
152:
153:            @Override
154:            public String toString() {
155:                return getDisplayName();
156:            }
157:
158:            public boolean isEmpty() {
159:                return equals(EMPTY);
160:            }
161:
162:            public Description childlessCopy() {
163:                return new Description(fDisplayName, fAnnotations);
164:            }
165:
166:            public <T extends Annotation> T getAnnotation(
167:                    Class<T> annotationType) {
168:                for (Annotation each : fAnnotations)
169:                    if (each.annotationType().equals(annotationType))
170:                        return annotationType.cast(each);
171:                return null;
172:            }
173:
174:            public Collection<Annotation> getAnnotations() {
175:                return Arrays.asList(fAnnotations);
176:            }
177:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.