Author: limpbizkit
Date: Sun Dec 7 00:45:10 2008
New Revision: 721
Added:
trunk/test/com/google/inject/MethodInterceptionTest.java
Modified:
trunk/test/com/google/inject/AllTests.java
Log:
Testcases for proxy generation.
Modified: trunk/test/com/google/inject/AllTests.java
==============================================================================
--- trunk/test/com/google/inject/AllTests.java (original)
+++ trunk/test/com/google/inject/AllTests.java Sun Dec 7 00:45:10 2008
@@ -60,6 +60,7 @@
suite.addTestSuite(IntegrationTest.class);
suite.addTestSuite(KeyTest.class);
suite.addTestSuite(LoggerInjectionTest.class);
+ suite.addTestSuite(MethodInterceptionTest.class);
suite.addTestSuite(ModuleTest.class);
suite.addTestSuite(ModulesTest.class);
suite.addTestSuite(NullableInjectionPointTest.class);
Added: trunk/test/com/google/inject/MethodInterceptionTest.java
==============================================================================
--- (empty file)
+++ trunk/test/com/google/inject/MethodInterceptionTest.java Sun Dec 7
00:45:10 2008
@@ -0,0 +1,80 @@
+/**
+ * Copyright (C) 2008 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.inject;
+
+import com.google.inject.matcher.Matchers;
+import junit.framework.TestCase;
+import org.aopalliance.intercept.MethodInterceptor;
+import org.aopalliance.intercept.MethodInvocation;
+
+/**
+ * @author [EMAIL PROTECTED] (Jesse Wilson)
+ */
+public class MethodInterceptionTest extends TestCase {
+
+ private final MethodInterceptor returnNullInterceptor = new
MethodInterceptor() {
+ public Object invoke(MethodInvocation methodInvocation) throws
Throwable {
+ return null;
+ }
+ };
+
+ public void testSharedProxyClasses() {
+ Injector injector = Guice.createInjector(new AbstractModule() {
+ protected void configure() {
+ bindInterceptor(Matchers.any(),
Matchers.returns(Matchers.only(Foo.class)),
+ returnNullInterceptor);
+ }
+ });
+
+ Injector nullFoosInjector = injector.createChildInjector(new
AbstractModule() {
+ protected void configure() {
+ bind(Interceptable.class);
+ }
+ });
+
+ Interceptable nullFoos =
nullFoosInjector.getInstance(Interceptable.class);
+ assertNotNull(nullFoos.bar());
+ assertNull(nullFoos.foo());
+
+ Injector nullFoosAndBarsInjector = injector.createChildInjector(new
AbstractModule() {
+ protected void configure() {
+ bind(Interceptable.class);
+ bindInterceptor(Matchers.any(),
Matchers.returns(Matchers.only(Bar.class)),
+ returnNullInterceptor);
+ }
+ });
+
+ Interceptable bothNull =
nullFoosAndBarsInjector.getInstance(Interceptable.class);
+ assertNull(bothNull.bar());
+ assertNull(bothNull.foo());
+
+ assertSame("Child injectors should share proxy classes, otherwise
memory leaks!",
+ nullFoos.getClass(), bothNull.getClass());
+ }
+
+ static class Foo {}
+ static class Bar {}
+
+ public static class Interceptable {
+ public Foo foo() {
+ return new Foo() {};
+ }
+ public Bar bar() {
+ return new Bar() {};
+ }
+ }
+}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"google-guice-dev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/google-guice-dev?hl=en
-~----------~----~----~----~------~----~------~--~---