Source Code Cross Referenced for TestabilityResult.java in  » IDE-Netbeans » junit » org » netbeans » modules » junit » 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 » IDE Netbeans » junit » org.netbeans.modules.junit 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:
042:        package org.netbeans.modules.junit;
043:
044:        import java.util.MissingResourceException;
045:        import java.util.ResourceBundle;
046:        import org.openide.ErrorManager;
047:        import org.openide.util.NbBundle;
048:
049:        /**
050:         * Helper class representing reasons for skipping a class in the test 
051:         * generation process. The class enumerates known reasons, why a class may 
052:         * not be considered testable, allows to combine the reasons and provide 
053:         * human-readable representation  of them.
054:         */
055:        final class TestabilityResult {
056:            // bitfield of reasons for skipping a class
057:            private long reason;
058:
059:            // reason constants
060:            public static final TestabilityResult OK = new TestabilityResult(0);
061:            public static final TestabilityResult PACKAGE_PRIVATE_CLASS = new TestabilityResult(
062:                    1);
063:            public static final TestabilityResult NO_TESTEABLE_METHODS = new TestabilityResult(
064:                    2);
065:            public static final TestabilityResult TEST_CLASS = new TestabilityResult(
066:                    4);
067:            public static final TestabilityResult ABSTRACT_CLASS = new TestabilityResult(
068:                    8);
069:            public static final TestabilityResult NONSTATIC_INNER_CLASS = new TestabilityResult(
070:                    16);
071:            public static final TestabilityResult EXCEPTION_CLASS = new TestabilityResult(
072:                    32);
073:            public static final TestabilityResult PRIVATE_CLASS = new TestabilityResult(
074:                    64);
075:
076:            // bundle keys for reason descriptions
077:            private static final String[] reasonBundleKeys = {
078:                    "TestabilityResult_PkgPrivate",
079:                    "TestabilityResult_NoTestableMethods",
080:                    "TestabilityResult_TestClass",
081:                    "TestabilityResult_AbstractClass",
082:                    "TestabilityResult_NonstaticInnerClass",
083:                    "TestabilityResult_ExceptionClass",
084:                    "TestabilityResult_Private" };
085:
086:            private TestabilityResult(long reason) {
087:                this .reason = reason;
088:            }
089:
090:            /**
091:             * Combine two result reasons into a new one.
092:             *
093:             * The combination is the union
094:             * of the failure reasons represented by the two results. Thus,
095:             * if both are success (no failure), the combination is a success. If 
096:             * some of them is failed, the result is failed.
097:             *
098:             * @param lhs the first TestabilityResult
099:             * @param rhs the second TestabilityResult
100:             * @return a new TestabilityResult representing the combination of the two 
101:             *         results
102:             **/
103:            public static TestabilityResult combine(TestabilityResult lhs,
104:                    TestabilityResult rhs) {
105:                return new TestabilityResult(lhs.reason | rhs.reason);
106:            }
107:
108:            /**
109:             * Returns true if the result is for a testable class.
110:             * @return true or false
111:             */
112:            public boolean isTestable() {
113:                return reason == 0;
114:            }
115:
116:            /**
117:             * Returns true if the result is for a non-testable class.
118:             * @return true if the result is for a non-testable class.
119:             */
120:            public boolean isFailed() {
121:                return reason != 0;
122:            }
123:
124:            /**
125:             * Returns a human-readable representation of the reason. If the reason 
126:             * is a combination of multiple reasons, they are separated with ",".
127:             * @return String
128:             */
129:            public String getReason() {
130:                return getReason(", ", ", "); //NOI18N
131:            }
132:
133:            /**
134:             * Returns {@link #getReason()}.
135:             * @return String
136:             */
137:            public String toString() {
138:                return getReason(", ", ", "); //NOI18N
139:            }
140:
141:            /** 
142:             * Returns a human-readable representation of the reason. If the reason 
143:             * is a combination of multiple reasons, they are separated with 
144:             * {@code separ} except for the last reason, which is separated 
145:             * with {@code terminalSepar}
146:             * <p>
147:             * For example: getReason(", ", " or ") might return 
148:             * "abstract, package private or without testable methods".
149:             *
150:             * @return String
151:             */
152:            public String getReason(String separ, String terminalSepar) {
153:                try {
154:                    ResourceBundle bundle = NbBundle
155:                            .getBundle(TestCreator.class);
156:                    if (reason == 0) {
157:                        return bundle.getString("TestabilityResult_OK"); //NOI18N
158:                    } else {
159:                        String str = ""; //NOI18N
160:                        boolean lastPrep = true;
161:                        for (long i = 0, r = reason; r > 0; r >>= 1, i++) {
162:                            if ((r & 1) != 0) {
163:                                if (str.length() > 0) {
164:                                    if (lastPrep) {
165:                                        str = terminalSepar + str;
166:                                        lastPrep = false;
167:                                    } else {
168:                                        str = separ + str;
169:                                    }
170:                                }
171:                                str = bundle
172:                                        .getString(reasonBundleKeys[(int) i])
173:                                        + str;
174:                            }
175:                        }
176:                        return str;
177:                    }
178:                } catch (MissingResourceException ex) {
179:                    ErrorManager.getDefault().notify(ex);
180:                    return "";
181:                }
182:            }
183:
184:            /**
185:             * Class for holding name of a skipped java class
186:             * together with the reason why it was skipped.
187:             */
188:            static final class SkippedClass {
189:                final String clsName;
190:                final TestabilityResult reason;
191:
192:                SkippedClass(String clsName, TestabilityResult reason) {
193:                    this.clsName = clsName;
194:                    this.reason = reason;
195:                }
196:            }
197:
198:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.