Improve test checking the inner class support
- constructor can access outer class managed fields
- static class can access outer class fields
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@689412 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/component/InnerClasses.java b/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/component/InnerClasses.java
index 1c8efc5..4bee70e 100644
--- a/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/component/InnerClasses.java
+++ b/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/component/InnerClasses.java
@@ -22,6 +22,8 @@
private String nonObject = "not-managed";
private int nonInt = 5;
+
+ private static int staticint = 6;
public boolean check() {
return true;
@@ -33,6 +35,8 @@
props.put("packageInner", new PackageNested().doSomething());
props.put("protectedInner", new ProtectedNested().doSomething());
props.put("privateInner", new PrivateNested().doSomething());
+ props.put("constructorInner", new ConstructorNested().doSomething());
+ props.put("staticInner", new StaticNested().doSomething());
Job anonymous = new Job() {
public Map doSomething() {
@@ -52,6 +56,7 @@
};
props.put("anonymous", anonymous.doSomething());
+ props.put("public", new PublicNested());
return props;
@@ -125,6 +130,36 @@
}
}
+ protected static class StaticNested implements Job {
+ private Map map = new HashMap();
+
+ public Map doSomething() {
+ map.put("static", new Boolean(true));
+ map.put("staticint", new Integer(staticint));
+ return map;
+ }
+ }
+
+ protected class ConstructorNested implements Job {
+ Map map = new HashMap();
+ public ConstructorNested() {
+ map.put("publicObject", publicObject);
+ map.put("publicInt", new Integer(publicInt));
+ map.put("packageObject", packageObject);
+ map.put("packageInt", new Integer(packageInt));
+ map.put("protectedObject", protectedObject);
+ map.put("protectedInt", new Integer(protectedInt));
+ map.put("privateObject", privateObject);
+ map.put("privateInt", new Integer(privateInt));
+ map.put("nonObject", nonObject);
+ map.put("nonInt", new Integer(nonInt));
+ }
+
+ public Map doSomething() {
+ return map;
+ }
+ }
+
}
diff --git a/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/NestedClassesTests.java b/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/NestedClassesTests.java
index 40d5fe1..cd60777 100644
--- a/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/NestedClassesTests.java
+++ b/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/NestedClassesTests.java
@@ -6,6 +6,8 @@
import org.apache.felix.ipojo.ComponentInstance;
import org.apache.felix.ipojo.Factory;
import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.component.InnerClasses;
+import org.apache.felix.ipojo.test.scenarios.component.InnerClasses.PublicNested;
import org.apache.felix.ipojo.test.scenarios.manipulation.service.CheckService;
import org.apache.felix.ipojo.test.scenarios.util.Utils;
import org.osgi.framework.ServiceReference;
@@ -113,6 +115,32 @@
}
+ public void testConstructorInnerClass() {
+ Map data = (Map) service.getProps().get("constructorInner");
+ assertNotNull("Check data existency", data);
+
+ assertEquals("Check public object", "publicObject", data.get("publicObject"));
+ assertEquals("Check public int", new Integer(0), data.get("publicInt"));
+ assertEquals("Check protected object", "protectedObject", data.get("protectedObject"));
+ assertEquals("Check protected int", new Integer(2), data.get("protectedInt"));
+ assertEquals("Check package object", "packageObject", data.get("packageObject"));
+ assertEquals("Check package int", new Integer(1), data.get("packageInt"));
+ assertEquals("Check private object", "privateObject", data.get("privateObject"));
+ assertEquals("Check private int", new Integer(3), data.get("privateInt"));
+ assertEquals("Check non-managed object", "not-managed", data.get("nonObject"));
+ assertEquals("Check non-managed int", new Integer(5), data.get("nonInt"));
+
+ }
+
+ public void testStaticInnerClass() {
+ Map data = (Map) service.getProps().get("staticInner");
+ assertNotNull("Check data existency", data);
+
+ assertEquals("Check static", new Boolean(true), data.get("static"));
+ assertEquals("Check static int", new Integer(6), data.get("staticint"));
+
+ }
+
public void testAnonymousInnerClass() {
Map data = (Map) service.getProps().get("anonymous");
assertNotNull("Check data existency", data);
@@ -130,6 +158,26 @@
}
+ public void testInnerAccess() {
+ Map map = (Map) service.getProps();
+ assertNotNull("Check map existency", map);
+
+ InnerClasses.PublicNested p = (PublicNested) map.get("public");
+ Map data = p.doSomething();
+
+ assertEquals("Check public object", "publicObject", data.get("publicObject"));
+ assertEquals("Check public int", new Integer(0), data.get("publicInt"));
+ assertEquals("Check protected object", "protectedObject", data.get("protectedObject"));
+ assertEquals("Check protected int", new Integer(2), data.get("protectedInt"));
+ assertEquals("Check package object", "packageObject", data.get("packageObject"));
+ assertEquals("Check package int", new Integer(1), data.get("packageInt"));
+ assertEquals("Check private object", "privateObject", data.get("privateObject"));
+ assertEquals("Check private int", new Integer(3), data.get("privateInt"));
+ assertEquals("Check non-managed object", "not-managed", data.get("nonObject"));
+ assertEquals("Check non-managed int", new Integer(5), data.get("nonInt"));
+
+ }
+
}