Source Code Cross Referenced for GenericInvocationHandlerTest.java in  » Net » Terracotta » com » tc » common » proxy » 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 » Net » Terracotta » com.tc.common.proxy 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice.  All rights reserved.
003:         */
004:        package com.tc.common.proxy;
005:
006:        import java.lang.reflect.Proxy;
007:
008:        import junit.framework.TestCase;
009:
010:        /**
011:         * @author andrew Unit test for {@link GenericInvocationHandler}.
012:         */
013:        public class GenericInvocationHandlerTest extends TestCase {
014:
015:            private static interface Foo {
016:                public String a(String x);
017:
018:                public int b(int b);
019:
020:                public String b(String b);
021:
022:                public String c(String c);
023:            }
024:
025:            private static class OurHandler {
026:                private int aCallCount;
027:                private String lastACallArg;
028:                private int b1CallCount;
029:                private int lastB1CallArg;
030:                private int b2CallCount;
031:                private String lastB2CallArg;
032:
033:                public String a(String x) {
034:                    ++aCallCount;
035:                    lastACallArg = x;
036:                    return "a!";
037:                }
038:
039:                public int b(int b) {
040:                    ++b1CallCount;
041:                    lastB1CallArg = b;
042:                    return 42;
043:                }
044:
045:                public String b(String b) {
046:                    ++b2CallCount;
047:                    lastB2CallArg = b;
048:                    return "b2!";
049:                }
050:
051:                public void reset() {
052:                    aCallCount = 0;
053:                    lastACallArg = null;
054:                    b1CallCount = 0;
055:                    lastB1CallArg = 0;
056:                    b2CallCount = 0;
057:                    lastB2CallArg = null;
058:                }
059:
060:                public int getACallCount() {
061:                    return this .aCallCount;
062:                }
063:
064:                public int getB1CallCount() {
065:                    return this .b1CallCount;
066:                }
067:
068:                public int getB2CallCount() {
069:                    return this .b2CallCount;
070:                }
071:
072:                public String getLastACallArg() {
073:                    return this .lastACallArg;
074:                }
075:
076:                public int getLastB1CallArg() {
077:                    return this .lastB1CallArg;
078:                }
079:
080:                public String getLastB2CallArg() {
081:                    return this .lastB2CallArg;
082:                }
083:            }
084:
085:            private GenericInvocationHandler invocationHandler;
086:            private OurHandler handlerObject;
087:            private Foo theProxy;
088:
089:            protected void setUp() throws Exception {
090:                handlerObject = new OurHandler();
091:                invocationHandler = new GenericInvocationHandler(handlerObject);
092:                theProxy = (Foo) Proxy.newProxyInstance(
093:                        GenericInvocationHandlerTest.class.getClassLoader(),
094:                        new Class[] { Foo.class }, invocationHandler);
095:            }
096:
097:            public void testDelegatesMethodsToHandler() throws Exception {
098:                checkCallCounts(0, 0, 0);
099:
100:                assertEquals("a!", theProxy.a("g"));
101:                checkCallCounts(1, 0, 0);
102:                assertEquals("g", handlerObject.getLastACallArg());
103:                handlerObject.reset();
104:
105:                assertEquals(42, theProxy.b(16));
106:                checkCallCounts(0, 1, 0);
107:                assertEquals(16, handlerObject.getLastB1CallArg());
108:                handlerObject.reset();
109:
110:                assertEquals("b2!", theProxy.b("h"));
111:                checkCallCounts(0, 0, 1);
112:                assertEquals("h", handlerObject.getLastB2CallArg());
113:                handlerObject.reset();
114:            }
115:
116:            public void testThrowsExceptionOnMissingMethod() throws Exception {
117:                try {
118:                    theProxy.c("a");
119:                    fail("Should've gotten an exception");
120:                } catch (NoSuchMethodError err) {
121:                    // ok
122:                }
123:            }
124:
125:            private void checkCallCounts(int aCallCount, int bCallCount,
126:                    int cCallCount) {
127:                assertEquals(aCallCount, handlerObject.getACallCount());
128:                assertEquals(bCallCount, handlerObject.getB1CallCount());
129:                assertEquals(cCallCount, handlerObject.getB2CallCount());
130:            }
131:
132:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.