Source Code Cross Referenced for CoverageRunner.java in  » Test-Coverage » Hansel » org » hansel » 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 » Test Coverage » Hansel » org.hansel 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.hansel;
002:
003:        import java.lang.annotation.ElementType;
004:        import java.lang.annotation.Retention;
005:        import java.lang.annotation.RetentionPolicy;
006:        import java.lang.annotation.Target;
007:        import java.util.HashSet;
008:
009:        import org.junit.internal.runners.InitializationError;
010:        import org.junit.runner.Description;
011:        import org.junit.runner.notification.Failure;
012:        import org.junit.runner.notification.RunNotifier;
013:        import org.junit.runners.Suite;
014:
015:        public class CoverageRunner extends Suite {
016:            private ProbeTable probeTable;
017:            private Class[] coveredClasses;
018:            private Description desc;
019:            private Description coverageDesc;
020:            private boolean initialized;
021:
022:            /**
023:             * The <code>CoverClasses</code> annotation specifies the classes to be covered
024:             * when the test suite is run.
025:             */
026:            @Retention(RetentionPolicy.RUNTIME)
027:            @Target(ElementType.TYPE)
028:            public @interface CoverClasses {
029:                public Class[] value();
030:            }
031:
032:            /**
033:             * Internal use only.
034:             */
035:            public CoverageRunner(Class<?> klass) throws InitializationError {
036:                super (klass);
037:                this .probeTable = new ProbeTable(null);
038:                this .coveredClasses = getCoveredClasses(klass);
039:                this .initialized = false;
040:            }
041:
042:            private static Class[] getCoveredClasses(Class<?> klass)
043:                    throws InitializationError {
044:                CoverClasses annotation = klass
045:                        .getAnnotation(CoverClasses.class);
046:                if (annotation == null)
047:                    throw new InitializationError(String.format(
048:                            "class '%s' must have a CoverClasses annotation",
049:                            klass.getName()));
050:
051:                return annotation.value();
052:            }
053:
054:            private HashSet<String> toStringSet(Class[] classes) {
055:                HashSet<String> coveredClasses = new HashSet<String>();
056:                for (Class clazz : classes) {
057:                    coveredClasses.add(clazz.getName());
058:                }
059:                return coveredClasses;
060:
061:            }
062:
063:            @Override
064:            public void run(RunNotifier notifier) {
065:                init();
066:
067:                CheckFailureRunListener listener = new CheckFailureRunListener();
068:                notifier.addListener(listener);
069:                super .run(notifier);
070:
071:                shutdown(notifier, listener.hasFailures());
072:            }
073:
074:            protected void init() {
075:                if (initialized) {
076:                    return;
077:                }
078:
079:                try {
080:                    ProbeTable.setProbeTable(probeTable);
081:                    Startup.init(toStringSet(coveredClasses));
082:                    initialized = true;
083:                } catch (Exception e) {
084:                    throw new IllegalStateException(e);
085:                }
086:            }
087:
088:            protected void shutdown(RunNotifier result, boolean hasErrors) {
089:                try {
090:                    loadClasses();
091:                    Startup.tearDown();
092:
093:                    result.fireTestStarted(getCoverageDescription());
094:                    probeTable.run(result, getCoverageDescription(), hasErrors);
095:                } catch (Exception e) {
096:                    result.fireTestFailure(new Failure(
097:                            getCoverageDescription(), e));
098:                } finally {
099:                    result.fireTestFinished(getCoverageDescription());
100:                }
101:            }
102:
103:            private void loadClasses() {
104:                // Make sure all classes are linked, so all probes get created.
105:                for (Class clazz : coveredClasses) {
106:                    clazz.getDeclaredFields();
107:                }
108:            }
109:
110:            public Description getCoverageDescription() {
111:                if (coverageDesc == null) {
112:                    coverageDesc = Description
113:                            .createSuiteDescription("Coverage");
114:                }
115:
116:                return coverageDesc;
117:            }
118:
119:            @Override
120:            public Description getDescription() {
121:                init();
122:
123:                if (this .desc == null) {
124:                    desc = super .getDescription();
125:
126:                    desc.addChild(getCoverageDescription());
127:
128:                    try {
129:                        probeTable
130:                                .addProbeDescriptions(getCoverageDescription());
131:                    } catch (ClassNotFoundException e) {
132:                        throw new IllegalStateException(e);
133:                    }
134:                }
135:
136:                return desc;
137:            }
138:
139:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.