Source Code Cross Referenced for TestClassFactory.java in  » Test-Coverage » Quilt » org » quilt » cl » 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 » Quilt » org.quilt.cl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* TestClassFactory.java */
002:
003:        package org.quilt.cl;
004:
005:        import java.io.ByteArrayOutputStream;
006:        import java.io.DataInputStream;
007:        import java.io.File;
008:        import java.io.IOException;
009:        import java.io.InputStream;
010:        import java.net.URL;
011:        import java.net.URLClassLoader;
012:
013:        import junit.framework.TestCase;
014:
015:        /**
016:         * 
017:         * @author <a href="ddp@apache.org">David Dixon-Peugh</a>
018:         * @author <a href="jddixon@users.sourceforge.net">Jim Dixon</a> - mods Jul 2003
019:
020:         */
021:        public class TestClassFactory extends TestCase {
022:            private ClassLoader loader = new CFClassLoader();
023:            private String name = null;
024:            private RunTest tinter = null;
025:
026:            public class CFClassLoader extends URLClassLoader {
027:                public CFClassLoader() {
028:                    super (new URL[0], TestClassFactory.class.getClassLoader());
029:                }
030:
031:                public Class findClass(String className)
032:                        throws ClassNotFoundException {
033:                    String classFile = className.replace('.',
034:                            File.separatorChar)
035:                            + ".class";
036:                    InputStream bytecodeIS = getResourceAsStream(classFile);
037:
038:                    byte bytecode[] = new byte[4096];
039:                    int len = 0;
040:                    try {
041:                        len = bytecodeIS.read(bytecode);
042:                    } catch (IOException e) {
043:                        e.printStackTrace();
044:                        throw new ClassNotFoundException(e.getMessage());
045:                    }
046:
047:                    Class RC = defineClass(className, bytecode, 0, len);
048:                    return RC;
049:                }
050:
051:                /**
052:                 * This is where we generate bytecode for the 
053:                 * Instrumenting Class Loader to instrument.
054:                 *
055:                 * The resourceName looks like "test/data/TestMyStuff.class"
056:                 * it needs to be converted to "test.data.TestMyStuff"
057:                 */
058:                public InputStream getResourceAsStream(String resName) {
059:                    return ClassFactory.getInstance().getResourceAsStream(
060:                            resName);
061:                }
062:            }
063:
064:            /**
065:             * Constructor for TestClassFactory.
066:             * @param arg0
067:             */
068:            public TestClassFactory(String arg0) {
069:                super (arg0);
070:                this .name = arg0;
071:            }
072:
073:            public void setUp() {
074:                try {
075:                    Class clazz = loader.loadClass("test.data." + name);
076:                    tinter = (RunTest) clazz.newInstance();
077:                } catch (Exception e) {
078:                    e.printStackTrace();
079:                }
080:            }
081:
082:            public void testDefault() {
083:                assertEquals(2, tinter.runTest(5));
084:            }
085:
086:            public void testIfThen() {
087:                assertEquals(3, tinter.runTest(5));
088:                assertEquals(5, tinter.runTest(-1));
089:            }
090:
091:            public void testSelect() {
092:                assertEquals(2, tinter.runTest(0));
093:                assertEquals(1, tinter.runTest(1));
094:                assertEquals(3, tinter.runTest(2));
095:                assertEquals(5, tinter.runTest(3));
096:                assertEquals(2, tinter.runTest(4));
097:            }
098:
099:            public void testWhile() {
100:                assertEquals(0, tinter.runTest(0));
101:                assertEquals(-1, tinter.runTest(-1));
102:                assertEquals(0, tinter.runTest(1));
103:                assertEquals(0, tinter.runTest(5));
104:            }
105:
106:            public void testNPENoCatch() {
107:                try {
108:                    tinter.runTest(0);
109:                    fail("Expecting Null Pointer Exception.");
110:                } catch (NullPointerException npe) {
111:                }
112:            }
113:
114:            public void testNPEWithCatch() {
115:                int retValue = 0;
116:                try {
117:                    retValue = tinter.runTest(0);
118:                } catch (NullPointerException npe) {
119:                    fail("Unexpected null pointer exception");
120:                }
121:                assertEquals("NPEWithCatch did not handle the exception", 3,
122:                        retValue);
123:            }
124:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.