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


001:        package org.hanseltest;
002:
003:        import junit.framework.TestCase;
004:        import junit.framework.TestResult;
005:
006:        import org.hansel.CoverageDecorator;
007:        import org.hansel.Util;
008:
009:        /**
010:         * Test the coverage test of if statements. 
011:         * 
012:         * @author Niklas Mehner
013:         */
014:        public class TestIf extends TestCase {
015:            /** Class the tests cover. */
016:            private static final Class[] COVERED = { CoverIf.class };
017:
018:            /**
019:             * Create a new test.
020:             * @param name Name of the test.
021:             */
022:            public TestIf(String name) {
023:                super (name);
024:            }
025:
026:            /**
027:             * No code is covered.
028:             */
029:            public void testNoCoverage() {
030:                CoverageDecorator cd = new CoverageDecorator(NoCoverage.class,
031:                        COVERED);
032:
033:                TestResult result = new TestResult();
034:
035:                cd.run(result);
036:
037:                // 5 Failures: 4 Methods and 1 Constructor
038:                assertEquals(5, result.failureCount());
039:
040:                // No errors
041:                assertEquals(0, result.errorCount());
042:            }
043:
044:            /**
045:             * Only a part of the class is covered.
046:             * See inner class PartCoverage1 for more detail.
047:             */
048:            public void testPartCoverage1() {
049:                CoverageDecorator cd = new CoverageDecorator(
050:                        PartCoverage1.class, COVERED);
051:
052:                TestResult result = new TestResult();
053:
054:                cd.run(result);
055:
056:                // Three failures: The first three methods are not fully covered.
057:                assertEquals(3, result.failureCount());
058:
059:                // No errors
060:                assertEquals(0, result.errorCount());
061:            }
062:
063:            /**
064:             * Only a part of the class is covered.
065:             * See inner class PartCoverage2 for more detail.
066:             */
067:            public void testPartCoverage2() {
068:                CoverageDecorator cd = new CoverageDecorator(
069:                        PartCoverage2.class, COVERED);
070:
071:                TestResult result = new TestResult();
072:
073:                cd.run(result);
074:
075:                org.hansel.Util.dumpResult(result);
076:                // Three failures: The first "if" is not fully covered.
077:                // The second if is not fully covered. The third if is not covered at
078:                // all but that failure message is suppressed, because it is caused by 
079:                // the first failure.
080:                // Also the ifPointer method is not covered at all.
081:                assertEquals(3, result.failureCount());
082:
083:                // No errors
084:                assertEquals(0, result.errorCount());
085:            }
086:
087:            /**
088:             * Test full coverage of the class.
089:             */
090:            public void testFullCoverage() {
091:                CoverageDecorator cd = new CoverageDecorator(
092:                        FullCoverage.class, COVERED);
093:
094:                TestResult result = new TestResult();
095:
096:                cd.run(result);
097:
098:                Util.dumpResult(result);
099:                // No failures
100:                assertEquals(0, result.failureCount());
101:
102:                // No errors
103:                assertEquals(0, result.errorCount());
104:            }
105:
106:            /**
107:             * TestCase does covers no code at all.
108:             */
109:            public static class NoCoverage extends TestCase {
110:                /**
111:                 * Creates a new test.
112:                 * @param name Name of the test.
113:                 */
114:                public NoCoverage(String name) {
115:                    super (name);
116:                }
117:
118:                /** Empty method. */
119:                public void testNothing() {
120:                }
121:            }
122:
123:            /** 
124:             * This testcase only calls the methods with condition=false..
125:             */
126:            public static class PartCoverage1 extends TestCase {
127:                /**
128:                 * Creates a new test.
129:                 * @param name Name of the test.
130:                 */
131:                public PartCoverage1(String name) {
132:                    super (name);
133:                }
134:
135:                /** Covers parts of the code. */
136:                public void testAll() {
137:                    System.out.println("Probetable class: "
138:                            + org.hansel.ProbeTable.class);
139:                    CoverIf ci = new CoverIf();
140:
141:                    assertEquals(0, ci.simpleIf(false));
142:                    assertEquals(4, ci.ifElse(false));
143:
144:                    assertEquals(1, ci.nestedIf(true, true));
145:                    assertEquals(2, ci.nestedIf(true, false));
146:                    assertEquals(3, ci.nestedIf(false, true));
147:                    assertEquals(4, ci.nestedIf(false, false));
148:                }
149:
150:            }
151:
152:            /** 
153:             * This testcase only calls the nestedIf methods with parameters 
154:             * (true, true). The other methods are fully covered.
155:             */
156:            public static class PartCoverage2 extends TestCase {
157:                /**
158:                 * Creates a new test.
159:                 * @param name Name of the test.
160:                 */
161:                public PartCoverage2(String name) {
162:                    super (name);
163:                }
164:
165:                /** Covers parts of the code. */
166:                public void testAll() {
167:                    CoverIf ci = new CoverIf();
168:
169:                    // Cover the first two messages
170:                    assertEquals(0, ci.simpleIf(false));
171:                    assertEquals(1, ci.simpleIf(true));
172:                    assertEquals(4, ci.ifElse(false));
173:                    assertEquals(3, ci.ifElse(true));
174:
175:                    // Only make one call to the third method.
176:                    assertEquals(1, ci.nestedIf(true, true));
177:                }
178:
179:            }
180:
181:            /**
182:             * Test for full coverage.
183:             */
184:            public static class FullCoverage extends TestCase {
185:                /**
186:                 * Creates a new test.
187:                 * @param name Name of the test.
188:                 */
189:                public FullCoverage(String name) {
190:                    super (name);
191:                }
192:
193:                /** Covers all the code. */
194:                public void testAll() {
195:                    CoverIf ci = new CoverIf();
196:
197:                    assertEquals(0, ci.simpleIf(false));
198:                    assertEquals(1, ci.simpleIf(true));
199:
200:                    assertEquals(4, ci.ifElse(false));
201:                    assertEquals(3, ci.ifElse(true));
202:
203:                    assertEquals(1, ci.nestedIf(true, true));
204:                    assertEquals(2, ci.nestedIf(true, false));
205:                    assertEquals(3, ci.nestedIf(false, true));
206:                    assertEquals(4, ci.nestedIf(false, false));
207:
208:                    assertEquals(0, ci.ifPointer(null, null));
209:                    assertEquals(1, ci.ifPointer(new Object(), null));
210:                }
211:            }
212:
213:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.