Source Code Cross Referenced for AntTest.java in  » Testing » webtest » com » canoo » webtest » self » 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 » webtest » com.canoo.webtest.self 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // Copyright © 2002-2005 Canoo Engineering AG, Switzerland.
002:        package com.canoo.webtest.self;
003:
004:        import junit.framework.Assert;
005:        import junit.framework.AssertionFailedError;
006:        import junit.framework.TestCase;
007:
008:        import java.lang.reflect.Method;
009:
010:        /**
011:         * Helper to test that the implementation of steps complies to the way
012:         * ANT instantiatiates its nested elements.
013:         * <p/>
014:         * There must be an addXXX method for each Element XXX with
015:         * exactly one parameter that can be instantiated via dynamic invocation.
016:         */
017:        public class AntTest extends TestCase {
018:            public AntTest(String string) {
019:                super (string);
020:            }
021:
022:            public static void nested(Class taskClass, String nested) {
023:                String methodName = "add" + nested;
024:                Method[] methods = taskClass.getDeclaredMethods();
025:                boolean foundMethod = false;
026:                for (int i = 0; i < methods.length; i++) {
027:                    Method method = methods[i];
028:                    if (method.getName().equals(methodName)) {
029:                        if (foundMethod) {
030:                            Assert.fail("more than one method"
031:                                    + at(taskClass, methodName));
032:                        }
033:                        foundMethod = true;
034:                        Class[] parms = method.getParameterTypes();
035:                        Assert.assertEquals("parameter count in"
036:                                + at(taskClass, methodName), 1, parms.length);
037:                        try {
038:                            parms[0].newInstance();
039:                        } catch (Exception e) {
040:                            Assert.fail("cannot instantiate parameter in"
041:                                    + at(taskClass, methodName, parms[0]
042:                                            .getName()));
043:                        }
044:                    }
045:                }
046:                Assert.assertTrue("no such method"
047:                        + at(taskClass, methodName, "?"), foundMethod);
048:            }
049:
050:            private static String at(Class taskClass,
051:                    String expectedMethodName, String param) {
052:                return " " + taskClass.getName() + "." + expectedMethodName
053:                        + "(" + param + ")";
054:            }
055:
056:            private static String at(Class taskClass, String expectedMethodName) {
057:                return at(taskClass, expectedMethodName, "?");
058:            }
059:
060:            public void testNoMethodFails() {
061:                String message = ThrowAssert.assertThrows(
062:                        AssertionFailedError.class, new TestBlock() {
063:                            public void call() throws Exception {
064:                                nested(Object.class, "NoSuchNestedElement");
065:                            }
066:                        });
067:                assertEquals(
068:                        "no such method java.lang.Object.addNoSuchNestedElement(?)",
069:                        message);
070:            }
071:
072:            public void addTwoMethods(Object o) {
073:            }
074:
075:            public void addTwoMethods(String x) {
076:            }
077:
078:            public void testMoreThanOneMethodFails() {
079:                String message = ThrowAssert.assertThrows(
080:                        AssertionFailedError.class, new TestBlock() {
081:                            public void call() throws Exception {
082:                                nested(AntTest.class, "TwoMethods");
083:                            }
084:                        });
085:                assertEquals(
086:                        "more than one method com.canoo.webtest.self.AntTest.addTwoMethods(?)",
087:                        message);
088:            }
089:
090:            public void addNoEmptyConstructor(AntTest x) {
091:            }
092:
093:            public void testNoEmptyCtorForParamFails() {
094:                String message = ThrowAssert.assertThrows(
095:                        AssertionFailedError.class, new TestBlock() {
096:                            public void call() throws Exception {
097:                                nested(AntTest.class, "NoEmptyConstructor");
098:                            }
099:                        });
100:                assertEquals(
101:                        "cannot instantiate parameter in com.canoo.webtest.self.AntTest.addNoEmptyConstructor(com.canoo.webtest.self.AntTest)",
102:                        message);
103:            }
104:
105:            public void addTooManyParams(String x, String y) {
106:            }
107:
108:            public void testTooManyParamsFails() {
109:                String message = ThrowAssert.assertThrows(
110:                        AssertionFailedError.class, new TestBlock() {
111:                            public void call() throws Exception {
112:                                nested(AntTest.class, "TooManyParams");
113:                            }
114:                        });
115:                assertEquals(
116:                        "parameter count in com.canoo.webtest.self.AntTest.addTooManyParams(?) expected:<1> but was:<2>",
117:                        message);
118:            }
119:
120:            public void testAddMethodDummyCanBeCalled() {
121:                addNoEmptyConstructor(null);
122:                addTooManyParams(null, null);
123:                addTwoMethods(new Object());
124:                addTwoMethods(new String());
125:            }
126:
127:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.