Add a test checking that we don't create proxies for abstract and concrete classes.

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1042164 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/core/src/test/java/org/apache/felix/ipojo/handlers/dependency/SmartProxyTest.java b/ipojo/core/src/test/java/org/apache/felix/ipojo/handlers/dependency/SmartProxyTest.java
index baf9725..9028b12 100644
--- a/ipojo/core/src/test/java/org/apache/felix/ipojo/handlers/dependency/SmartProxyTest.java
+++ b/ipojo/core/src/test/java/org/apache/felix/ipojo/handlers/dependency/SmartProxyTest.java
@@ -1,5 +1,6 @@
 package org.apache.felix.ipojo.handlers.dependency;
 
+import java.awt.Window;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
@@ -23,114 +24,21 @@
 
 public class SmartProxyTest extends TestCase {
 
-	private Dependency dependency;
-
-
 	public void setUp() {
 	}
 
 
 	/**
-	 * Tests if we can proxies classes from java.* package.
-	 * Indeed, a recent JVM bug fix introduces a bug:
-	 * <code>
-	 * [ERROR] test : Cannot create the proxy object
-	 * java.lang.SecurityException: Prohibited package name: java.awt
-	 * </code>
+	 * Check that we don't create smart proxies for concrete and abstract classes.
 	 */
-	public void testProxiesOfJavaClasses() {
-		Bundle bundle = new Bundle() {
-
-			public int getState() {
-				return 0;
-			}
-
-			public void start() throws BundleException {
-			}
-
-			public void stop() throws BundleException {
-			}
-
-			public void update() throws BundleException {
-			}
-
-			public void update(InputStream in) throws BundleException {
-			}
-
-			public void uninstall() throws BundleException {
-			}
-
-			public Dictionary getHeaders() {
-				return null;
-			}
-
-			public long getBundleId() {
-				return 0;
-			}
-
-			public String getLocation() {
-				return null;
-			}
-
-			public ServiceReference[] getRegisteredServices() {
-				return null;
-			}
-
-			public ServiceReference[] getServicesInUse() {
-				return null;
-			}
-
-			public boolean hasPermission(Object permission) {
-				return false;
-			}
-
-			public URL getResource(String name) {
-				return null;
-			}
-
-			public Dictionary getHeaders(String locale) {
-				return null;
-			}
-
-			public String getSymbolicName() {
-				return null;
-			}
-
-			public Class loadClass(String name) throws ClassNotFoundException {
-				return Dependency.class.getClassLoader().loadClass(name);
-			}
-
-			public Enumeration getResources(String name) throws IOException {
-				return null;
-			}
-
-			public Enumeration getEntryPaths(String path) {
-				return null;
-			}
-
-			public URL getEntry(String name) {
-				return null;
-			}
-
-			public long getLastModified() {
-				return 0;
-			}
-
-			public Enumeration findEntries(String path, String filePattern,
-					boolean recurse) {
-				return null;
-			}
-
-		};
-
+	public void testCannotProxyAbstractAndContreteClasses() {
+		Bundle bundle = new BundleImplementingLoading();
 
 		BundleContext context = (BundleContext) Mockito.mock(BundleContext.class);
 		Mockito.when(context.getProperty(DependencyHandler.PROXY_TYPE_PROPERTY)).thenReturn(null);
 		Mockito.when(context.getProperty(Logger.IPOJO_LOG_LEVEL_PROP)).thenReturn(null);
 		Mockito.when(context.getBundle()).thenReturn(bundle);
 
-		//getBundle().loadClass(name);
-
 		ComponentFactory factory = (ComponentFactory) Mockito.mock(ComponentFactory.class);
 		Mockito.when(factory.getBundleClassLoader()).thenReturn(Dependency.class.getClassLoader());
 
@@ -146,7 +54,55 @@
 		Mockito.when(handler.getLogger()).thenReturn(logger);
 
 		// Try with java.List
-		dependency = new Dependency(handler, "a_field", List.class, null, false, false, false,
+		Dependency dependency = new Dependency(handler, "a_field", Window.class, null, false, false, false,
+				true, "dep", context, Dependency.DYNAMIC_BINDING_POLICY, null, null);
+		dependency.start();
+
+		// No service
+		Assert.assertNull(dependency.onGet(new Object(), "a_field", null));
+
+		dependency.stop();
+
+		// Try with javax.swing.Action
+		dependency = new Dependency(handler, "a_field", Object.class, null, false, false, false,
+				true, "dep", context, Dependency.DYNAMIC_BINDING_POLICY, null, null);
+		dependency.start();
+		// OK
+		Assert.assertNull(dependency.onGet(new Object(), "a_field", null));
+	}
+
+	/**
+	 * Tests if we can proxies classes from java.* package.
+	 * Indeed, a recent JVM bug fix introduces a bug:
+	 * <code>
+	 * [ERROR] test : Cannot create the proxy object
+	 * java.lang.SecurityException: Prohibited package name: java.awt
+	 * </code>
+	 */
+	public void testProxiesOfJavaClasses() {
+		Bundle bundle = new BundleImplementingLoading();
+
+		BundleContext context = (BundleContext) Mockito.mock(BundleContext.class);
+		Mockito.when(context.getProperty(DependencyHandler.PROXY_TYPE_PROPERTY)).thenReturn(null);
+		Mockito.when(context.getProperty(Logger.IPOJO_LOG_LEVEL_PROP)).thenReturn(null);
+		Mockito.when(context.getBundle()).thenReturn(bundle);
+
+		ComponentFactory factory = (ComponentFactory) Mockito.mock(ComponentFactory.class);
+		Mockito.when(factory.getBundleClassLoader()).thenReturn(Dependency.class.getClassLoader());
+
+		InstanceManager im = (InstanceManager) Mockito.mock(InstanceManager.class);
+		Mockito.when(im.getContext()).thenReturn(context);
+		Mockito.when(im.getFactory()).thenReturn(factory);
+
+		DependencyHandler handler = (DependencyHandler) Mockito.mock(DependencyHandler.class);
+		Mockito.when(handler.getInstanceManager()).thenReturn(im);
+		Logger logger = new Logger(context, "test", Logger.INFO);
+
+
+		Mockito.when(handler.getLogger()).thenReturn(logger);
+
+		// Try with java.List
+		Dependency dependency = new Dependency(handler, "a_field", List.class, null, false, false, false,
 				true, "dep", context, Dependency.DYNAMIC_BINDING_POLICY, null, null);
 		dependency.start();
 
@@ -165,4 +121,86 @@
 		Assert.assertTrue(dependency.onGet(new Object(), "a_field", null) instanceof Action);
 	}
 
+	private class BundleImplementingLoading implements Bundle {
+		public int getState() {
+			return 0;
+		}
+
+		public void start() throws BundleException {
+		}
+
+		public void stop() throws BundleException {
+		}
+
+		public void update() throws BundleException {
+		}
+
+		public void update(InputStream in) throws BundleException {
+		}
+
+		public void uninstall() throws BundleException {
+		}
+
+		public Dictionary getHeaders() {
+			return null;
+		}
+
+		public long getBundleId() {
+			return 0;
+		}
+
+		public String getLocation() {
+			return null;
+		}
+
+		public ServiceReference[] getRegisteredServices() {
+			return null;
+		}
+
+		public ServiceReference[] getServicesInUse() {
+			return null;
+		}
+
+		public boolean hasPermission(Object permission) {
+			return false;
+		}
+
+		public URL getResource(String name) {
+			return null;
+		}
+
+		public Dictionary getHeaders(String locale) {
+			return null;
+		}
+
+		public String getSymbolicName() {
+			return null;
+		}
+
+		public Class loadClass(String name) throws ClassNotFoundException {
+			return Dependency.class.getClassLoader().loadClass(name);
+		}
+
+		public Enumeration getResources(String name) throws IOException {
+			return null;
+		}
+
+		public Enumeration getEntryPaths(String path) {
+			return null;
+		}
+
+		public URL getEntry(String name) {
+			return null;
+		}
+
+		public long getLastModified() {
+			return 0;
+		}
+
+		public Enumeration findEntries(String path, String filePattern,
+				boolean recurse) {
+			return null;
+		}
+	}
+
 }