Source Code Cross Referenced for MockedMethodGeneratorJava15.java in  » Testing » MockCreator » net » sf » mockcreator » codegeneration » 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 » MockCreator » net.sf.mockcreator.codegeneration 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sf.mockcreator.codegeneration;
002:
003:        import java.lang.reflect.Method;
004:        import java.lang.reflect.Modifier;
005:        import java.lang.reflect.Type;
006:
007:        import net.sf.mockcreator.utils.SourceUtils;
008:        import net.sf.mockcreator.utils.TemplateUtils;
009:
010:        public class MockedMethodGeneratorJava15 implements 
011:                IMockedMethodGenerator {
012:            private Method method;
013:            String returnableClassName;
014:
015:            FormatterJava15 mf = new FormatterJava15();
016:            TypeUtilsJava15 tu = new TypeUtilsJava15();
017:
018:            public String getMockedMethodBody() {
019:                boolean isVoid = method.getReturnType().equals(void.class);
020:
021:                return TemplateUtils
022:                        .format(
023:                                "methodBody.template",
024:                                new Object[] {
025:                                        mf.getReturnType(),
026:                                        method.getName(),
027:                                        mf.getParameters(),
028:                                        mf.getExceptions(),
029:                                        SourceUtils
030:                                                .getPackParametersSrc(method),
031:                                        SourceUtils
032:                                                .getClassObjectMethodSignatureSrc(method),
033:                                        getExceptionHandling(),
034:                                        isVoid ? "" : getReturnClause(method
035:                                                .getGenericReturnType()),
036:                                        Modifier
037:                                                .isStatic(method.getModifiers()) ? "static"
038:                                                : "",
039:                                        isVoid ? "" : "java.lang.Object ret = ",
040:                                        new TypeUtilsJava15()
041:                                                .getCanonicalMethodParameters(method) });
042:            }
043:
044:            public String getMockedMethodDeclaration() {
045:                return TemplateUtils
046:                        .format(
047:                                "methodDeclaration.template",
048:                                new Object[] {
049:                                        mf.getReturnType(), // typeUtils.getCanonicalTypeSpelling(method.getGenericReturnType()),
050:                                        method.getName(),
051:                                        mf.getParameters(), // typeUtils.getParametersSpecification(method,method.getGenericParameterTypes()),
052:                                        mf.getExceptions(), // typeUtils.getThrowsSpecification(method.getGenericExceptionTypes()),
053:                                        Modifier
054:                                                .isStatic(method.getModifiers()) ? "static"
055:                                                : "" });
056:            }
057:
058:            private String getReturnClause(Type returnType) {
059:                if (returnType instanceof  Class
060:                        && ((Class) returnType).isPrimitive()) {
061:                    String casted = SourceUtils.unwrap((Class) returnType,
062:                            "ret");
063:                    return TemplateUtils.format(
064:                            "methodReturnPrimitive.template",
065:                            new Object[] { casted });
066:                } else {
067:                    String canonical = mf.getReturnType(); // typeUtils.getCanonicalTypeSpelling(returnType);    		
068:                    return TemplateUtils.format("methodReturnObject.template",
069:                            new Object[] { canonical });
070:                }
071:            }
072:
073:            public String getExceptionHandling() {
074:                String exTemplate = TemplateUtils
075:                        .getTemplate("methodExceptionHandler.template");
076:                String thTemplate = TemplateUtils
077:                        .getTemplate("methodThrowableHandler.template");
078:
079:                StringBuffer exceptions = new StringBuffer();
080:                Class[] exs = method.getExceptionTypes();
081:                SourceUtils.getAllExceptionHandlers(exceptions, exs,
082:                        exTemplate, thTemplate);
083:                return exceptions.toString();
084:            }
085:
086:            public void setMethod(Method method) {
087:                this .method = method;
088:                this .mf.setMethod(method);
089:            }
090:
091:            public String getReturnables() {
092:                StringBuffer methods = new StringBuffer();
093:
094:                String thTemplate = TemplateUtils
095:                        .getTemplate("returnableThrowable.template");
096:                Class[] exs = method.getExceptionTypes();
097:                SourceUtils.getAllExceptionHandlers(methods, exs, thTemplate,
098:                        thTemplate);
099:
100:                String genericType = new TypeUtilsJava15()
101:                        .getCanonicalMethodParameters(method);
102:
103:                Type ret = method.getGenericReturnType();
104:                if (ret instanceof  Class) {
105:                    if (addReturnsMethods(methods, (Class) ret, char.class,
106:                            Character.class))
107:                        ;
108:                    else if (addReturnsMethods(methods, (Class) ret,
109:                            byte.class, Byte.class))
110:                        ;
111:                    else if (addReturnsMethods(methods, (Class) ret,
112:                            short.class, Short.class))
113:                        ;
114:                    else if (addReturnsMethods(methods, (Class) ret, int.class,
115:                            Integer.class))
116:                        ;
117:                    else if (addReturnsMethods(methods, (Class) ret,
118:                            long.class, Long.class))
119:                        ;
120:                    else if (addReturnsMethods(methods, (Class) ret,
121:                            float.class, Float.class))
122:                        ;
123:                    else if (addReturnsMethods(methods, (Class) ret,
124:                            double.class, Double.class))
125:                        ;
126:                    else if (addReturnsMethods(methods, (Class) ret,
127:                            boolean.class, Boolean.class))
128:                        ;
129:                    else if (!void.class.equals(ret)) {
130:                        methods.append(TemplateUtils.format(
131:                                "returnableMethod.template", new Object[] {
132:                                        tu.getCanonicalTypeSpelling(ret),
133:                                        genericType }));
134:                    }
135:                } else {
136:                    methods.append(TemplateUtils.format(
137:                            "returnableMethod.template", new Object[] {
138:                                    tu.getCanonicalTypeSpelling(ret),
139:                                    genericType }));
140:                }
141:
142:                return methods.toString();
143:            }
144:
145:            private boolean addReturnsMethods(StringBuffer clz, Class ret,
146:                    Class one, Class two) {
147:                if (ret.equals(one) || ret.equals(two)) {
148:                    clz
149:                            .append(TemplateUtils
150:                                    .format(
151:                                            "returnablePrimitiveMethods.template",
152:                                            new Object[] {
153:                                                    SourceUtils
154:                                                            .getCanonicalTypeSpelling(one),
155:                                                    SourceUtils
156:                                                            .getCanonicalTypeSpelling(two) }));
157:                    return true;
158:                }
159:                return false;
160:            }
161:
162:            public String getParametersSpecification() {
163:                return mf.getParameters();
164:            }
165:
166:            public String getAcceptableParametersSpecification() {
167:                return mf.getObjectParameters();
168:            }
169:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.