Tests for bug 281. We didn't have coverage for getThis().
git-svn-id: https://google-guice.googlecode.com/svn/trunk@746 d779f126-a31b-0410-b53b-1d3aecad763e
diff --git a/test/com/google/inject/MethodInterceptionTest.java b/test/com/google/inject/MethodInterceptionTest.java
index a876866..060e2af 100644
--- a/test/com/google/inject/MethodInterceptionTest.java
+++ b/test/com/google/inject/MethodInterceptionTest.java
@@ -17,6 +17,7 @@
package com.google.inject;
import com.google.inject.matcher.Matchers;
+import java.util.concurrent.atomic.AtomicReference;
import junit.framework.TestCase;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
@@ -65,6 +66,25 @@
assertSame("Child injectors should share proxy classes, otherwise memory leaks!",
nullFoos.getClass(), bothNull.getClass());
}
+
+ public void testGetThis() {
+ final AtomicReference<Object> lastTarget = new AtomicReference<Object>();
+
+ Injector injector = Guice.createInjector(new AbstractModule() {
+ protected void configure() {
+ bindInterceptor(Matchers.any(), Matchers.any(), new MethodInterceptor() {
+ public Object invoke(MethodInvocation methodInvocation) throws Throwable {
+ lastTarget.set(methodInvocation.getThis());
+ return methodInvocation.proceed();
+ }
+ });
+ }
+ });
+
+ Interceptable interceptable = injector.getInstance(Interceptable.class);
+ interceptable.foo();
+ assertSame(interceptable, lastTarget.get());
+ }
static class Foo {}
static class Bar {}