[DOSGI-254] Make proxyfactory generic. Small fix in test
diff --git a/common/src/main/java/org/apache/cxf/dosgi/common/proxy/ProxyFactory.java b/common/src/main/java/org/apache/cxf/dosgi/common/proxy/ProxyFactory.java
index ec10f6e..03c2a14 100644
--- a/common/src/main/java/org/apache/cxf/dosgi/common/proxy/ProxyFactory.java
+++ b/common/src/main/java/org/apache/cxf/dosgi/common/proxy/ProxyFactory.java
@@ -23,10 +23,11 @@
public final class ProxyFactory {
private ProxyFactory() {
}
-
- public static Object create(Object serviceProxy, Class<?> iType) {
- return Proxy.newProxyInstance(iType.getClassLoader(), new Class[] {
- iType
- }, new ServiceInvocationHandler(serviceProxy, iType));
+
+ @SuppressWarnings("unchecked")
+ public static <T> T create(Object serviceProxy, Class<T> iType) {
+ Class<?>[] ifaces = new Class<?>[] {iType};
+ return (T)Proxy.newProxyInstance(iType.getClassLoader(), ifaces,
+ new ServiceInvocationHandler(serviceProxy, iType));
}
}
diff --git a/common/src/test/java/org/apache/cxf/dosgi/common/proxy/ServiceInvocationHandlerTest.java b/common/src/test/java/org/apache/cxf/dosgi/common/proxy/ServiceInvocationHandlerTest.java
index 30cf5a8..43a90a7 100644
--- a/common/src/test/java/org/apache/cxf/dosgi/common/proxy/ServiceInvocationHandlerTest.java
+++ b/common/src/test/java/org/apache/cxf/dosgi/common/proxy/ServiceInvocationHandlerTest.java
@@ -80,7 +80,7 @@
@Test(expected = IOException.class)
public void testException() throws IOException {
- MySubService proxy = (MySubService)ProxyFactory.create(new MyServiceImpl(), MySubService.class);
+ MySubService proxy = ProxyFactory.create(new MyServiceImpl(), MySubService.class);
proxy.throwException2();
}
@@ -90,7 +90,7 @@
*/
@Test(expected = ServiceException.class)
public void testInheritedException() throws IOException {
- MyBaseService proxy = (MyBaseService)ProxyFactory.create(new MyServiceImpl(), MySubService.class);
+ MySubService proxy = ProxyFactory.create(new MyServiceImpl(), MySubService.class);
proxy.throwException1();
}