This testcase shows that we aren't wrapping user-thrown exceptions consistently
git-svn-id: https://google-guice.googlecode.com/svn/trunk@466 d779f126-a31b-0410-b53b-1d3aecad763e
diff --git a/src/com/google/inject/internal/ConstructionProxy.java b/src/com/google/inject/internal/ConstructionProxy.java
deleted file mode 100644
index 437bd2b..0000000
--- a/src/com/google/inject/internal/ConstructionProxy.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/**
- * Copyright (C) 2006 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.internal;
-
-import com.google.inject.Parameter;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Member;
-import java.util.List;
-
-/**
- * Proxies calls to a {@link java.lang.reflect.Constructor} for a class
- * {@code T}.
- *
- * @author crazybob@google.com (Bob Lee)
- */
-public interface ConstructionProxy<T> {
-
- /**
- * Constructs an instance of {@code T} for the given arguments.
- */
- T newInstance(Object... arguments) throws InvocationTargetException;
-
- List<Parameter<?>> getParameters();
-
- /**
- * Returns the injected method or constructor. If the injected member is
- * synthetic (such as generated code for method interception), the natural
- * constructor is returned.
- */
- Member getMember();
-}
diff --git a/src/com/google/inject/internal/ConstructionProxyFactory.java b/src/com/google/inject/internal/ConstructionProxyFactory.java
deleted file mode 100644
index 8eb83db..0000000
--- a/src/com/google/inject/internal/ConstructionProxyFactory.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/**
- * Copyright (C) 2006 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.internal;
-
-import com.google.inject.internal.ConstructionProxy;
-
-import java.lang.reflect.Constructor;
-
-/**
- * Creates {@link ConstructionProxy} instances.
- *
- * @author crazybob@google.com (Bob Lee)
- */
-public interface ConstructionProxyFactory {
-
- /**
- * Gets a construction proxy for the given constructor.
- */
- <T> ConstructionProxy<T> get(Constructor<T> constructor);
-}
diff --git a/test/com/google/inject/ProvisionExceptionTest.java b/test/com/google/inject/ProvisionExceptionTest.java
index 1afe796..f54b27c 100644
--- a/test/com/google/inject/ProvisionExceptionTest.java
+++ b/test/com/google/inject/ProvisionExceptionTest.java
@@ -23,6 +23,9 @@
*/
public class ProvisionExceptionTest extends TestCase {
+ private static final ProvisionException provisionException
+ = new ProvisionException(new RuntimeException(), "User Exception");
+
public void testExceptionsCollapsed() {
try {
Guice.createInjector().getInstance(A.class);
@@ -76,6 +79,36 @@
}
}
+ /**
+ * This test demonstrates that if the user throws a ProvisionException,
+ * sometimes we wrap it and sometimes we don't. We should be consistent.
+ */
+ public void testUserCodeProvisionExceptionsAreWrapped() {
+ try {
+ Guice.createInjector().getInstance(F.class);
+ fail();
+ } catch (ProvisionException e) {
+ assertNotSame(e, provisionException);
+ assertContains(e.getMessage(), "while locating "
+ + "com.google.inject.ProvisionExceptionTest$F");
+ assertEquals("User Exception", e.getCause().getMessage());
+ }
+
+ try {
+ Guice.createInjector(new AbstractModule() {
+ protected void configure() {
+ bind(F.class).toProvider(FProvider.class);
+ }
+ }).getInstance(F.class);
+ fail();
+ } catch (ProvisionException e) {
+ assertNotSame(e, provisionException);
+ assertContains(e.getMessage(), "while locating "
+ + "com.google.inject.ProvisionExceptionTest$F");
+ assertEquals("User Exception", e.getCause().getMessage());
+ }
+ }
+
static class A {
@Inject
A(B b) { }
@@ -107,4 +140,16 @@
assertTrue(String.format("Expected \"%s\" to contain substring \"%s\"",
text, substring), text.contains(substring));
}
+
+ static class F {
+ @Inject public F() {
+ throw provisionException;
+ }
+ }
+
+ static class FProvider implements Provider<F> {
+ public F get() {
+ return new F();
+ }
+ }
}