Source Code Cross Referenced for TestFactoryTest.java in  » Testing » JUnitPerf » com » clarkware » junitperf » 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 » JUnitPerf » com.clarkware.junitperf 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.clarkware.junitperf;
002:
003:        import junit.framework.*;
004:
005:        /**
006:         * The <code>TestFactoryTest</code> is a <code>TestCase</code>
007:         * for the <code>TestFactory</code> and <code>TestMethodFactory</code>
008:         * classes.
009:         *
010:         * @author <a href="mailto:mike@clarkware.com">Mike Clark</a>
011:         * @author <a href="http://www.clarkware.com">Clarkware Consulting, Inc.</a>
012:         *
013:         * @see junit.framework.TestCase
014:         */
015:
016:        public class TestFactoryTest extends TestCase {
017:
018:            private TestSuite _allMethodsTestSuite;
019:            private TestSuite _oneMethodTestSuite;
020:
021:            private Class _testClass;
022:
023:            public TestFactoryTest(String name) {
024:                super (name);
025:
026:                _testClass = com.clarkware.junitperf.MockTestFactoryTest.class;
027:
028:                _allMethodsTestSuite = new TestSuite(_testClass);
029:
030:                _oneMethodTestSuite = new TestSuite();
031:                _oneMethodTestSuite.addTest(new MockTestFactoryTest(
032:                        "testSuccess"));
033:            }
034:
035:            public void testAllTestMethods() {
036:
037:                TestFactory testFactory = new TestFactory(_testClass);
038:
039:                assertEquals(2, testFactory.countTestCases());
040:
041:                assertEqualsTestSuite(_allMethodsTestSuite, testFactory
042:                        .getTest());
043:
044:                TestResult result = new TestResult();
045:                testFactory.run(result);
046:
047:                assertEquals(2, result.runCount());
048:                assertEquals(0, result.errorCount());
049:                assertEquals(1, result.failureCount());
050:            }
051:
052:            public void testAllTestMethodsSameSuiteForSameThread() {
053:
054:                TestFactory testFactory = new TestFactory(_testClass);
055:
056:                Test test1 = testFactory.getTest();
057:                Test test2 = testFactory.getTest();
058:
059:                assertSame(test1, test2);
060:
061:                assertEqualsTestSuite(_allMethodsTestSuite, test1);
062:                assertEqualsTestSuite(_allMethodsTestSuite, test2);
063:            }
064:
065:            public void testAllTestMethodsDifferentSuiteForDifferentThread() {
066:
067:                TestFactory testFactory = new TestFactory(_testClass);
068:
069:                MockRunnable runner1 = new MockRunnable(testFactory);
070:                MockRunnable runner2 = new MockRunnable(testFactory);
071:
072:                Thread thread1 = new Thread(runner1);
073:                Thread thread2 = new Thread(runner2);
074:
075:                thread1.start();
076:                thread2.start();
077:
078:                sleep();
079:
080:                Test test1 = runner1.getTest();
081:                Test test2 = runner2.getTest();
082:
083:                assertTrue(!(test1 == test2));
084:
085:                assertEqualsTestSuite(_allMethodsTestSuite, test1);
086:                assertEqualsTestSuite(_allMethodsTestSuite, test2);
087:            }
088:
089:            public void testOneTestMethodSuccess() {
090:
091:                TestMethodFactory testFactory = new TestMethodFactory(
092:                        _testClass, "testSuccess");
093:
094:                assertEquals(1, testFactory.countTestCases());
095:
096:                assertEqualsTestSuite(_oneMethodTestSuite, testFactory
097:                        .getTest());
098:
099:                TestResult result = new TestResult();
100:                testFactory.run(result);
101:
102:                assertEquals(1, result.runCount());
103:                assertEquals(0, result.errorCount());
104:                assertEquals(0, result.failureCount());
105:            }
106:
107:            public void testOneTestMethodFailure() {
108:
109:                TestMethodFactory testFactory = new TestMethodFactory(
110:                        _testClass, "testFailure");
111:
112:                assertEquals(1, testFactory.countTestCases());
113:
114:                assertEqualsTestSuite(_oneMethodTestSuite, testFactory
115:                        .getTest());
116:
117:                TestResult result = new TestResult();
118:                testFactory.run(result);
119:
120:                assertEquals(1, result.runCount());
121:                assertEquals(0, result.errorCount());
122:                assertEquals(1, result.failureCount());
123:            }
124:
125:            public void testOneTestMethodNoSuchMethod() {
126:
127:                TestMethodFactory testFactory = new TestMethodFactory(
128:                        _testClass, "testFoo");
129:
130:                TestResult result = new TestResult();
131:                testFactory.run(result);
132:
133:                assertEquals(1, result.runCount());
134:                assertEquals(0, result.errorCount());
135:                assertEquals(1, result.failureCount());
136:            }
137:
138:            public void testOneTestMethodSameSuiteForSameThread() {
139:
140:                TestFactory testFactory = new TestMethodFactory(_testClass,
141:                        "testSuccess");
142:
143:                Test test1 = testFactory.getTest();
144:                Test test2 = testFactory.getTest();
145:
146:                assertSame(test1, test2);
147:
148:                assertEqualsTestSuite(_oneMethodTestSuite, test1);
149:                assertEqualsTestSuite(_oneMethodTestSuite, test2);
150:            }
151:
152:            public void testOneTestMethodDifferentSuiteForDifferentThread() {
153:
154:                TestFactory testFactory = new TestMethodFactory(_testClass,
155:                        "testSuccess");
156:
157:                MockRunnable runner1 = new MockRunnable(testFactory);
158:                MockRunnable runner2 = new MockRunnable(testFactory);
159:
160:                Thread thread1 = new Thread(runner1);
161:                Thread thread2 = new Thread(runner2);
162:
163:                thread1.start();
164:                thread2.start();
165:
166:                sleep();
167:
168:                Test test1 = runner1.getTest();
169:                Test test2 = runner2.getTest();
170:
171:                assertTrue(!(test1 == test2));
172:
173:                assertEqualsTestSuite(_oneMethodTestSuite, test1);
174:                assertEqualsTestSuite(_oneMethodTestSuite, test2);
175:            }
176:
177:            public void testClassNotATestCase() {
178:
179:                try {
180:
181:                    TestFactory testFactory = new TestFactory(
182:                            java.lang.String.class);
183:                    fail("Class not assignable to TestCase!");
184:
185:                    testFactory = new TestMethodFactory(java.lang.String.class,
186:                            "");
187:                    fail("Class not assignable to TestCase!");
188:
189:                } catch (IllegalArgumentException success) {
190:                }
191:            }
192:
193:            protected void sleep() {
194:                try {
195:                    Thread.sleep(250);
196:                } catch (InterruptedException ignored) {
197:                }
198:            }
199:
200:            protected void assertEqualsTestSuite(Test t1, Test t2) {
201:
202:                assertTrue(t1 instanceof  TestSuite);
203:                assertTrue(t2 instanceof  TestSuite);
204:
205:                TestSuite suite1 = (TestSuite) t1;
206:                TestSuite suite2 = (TestSuite) t2;
207:
208:                assertEquals(suite1.countTestCases(), suite2.countTestCases());
209:                assertEquals(suite1.getName(), suite2.getName());
210:            }
211:
212:            private static class MockRunnable implements  Runnable {
213:
214:                private TestFactory _factory;
215:                private Test _test;
216:
217:                public MockRunnable(TestFactory factory) {
218:                    _factory = factory;
219:                }
220:
221:                public void run() {
222:                    _test = _factory.getTest();
223:                }
224:
225:                public Test getTest() {
226:                    return _test;
227:                }
228:            }
229:
230:            public static Test suite() {
231:                return new TestSuite(TestFactoryTest.class);
232:            }
233:
234:            public static void main(String args[]) {
235:                junit.textui.TestRunner.run(suite());
236:            }
237:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.