Added a test checking the field duplication.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1402157 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulation/ManipulatorTest.java b/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulation/ManipulatorTest.java
index 4aaa928..a6d333c 100644
--- a/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulation/ManipulatorTest.java
+++ b/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulation/ManipulatorTest.java
@@ -109,6 +109,46 @@
}
+ public void testManipulatingTheNonSunPOJO() throws Exception {
+ Manipulator manipulator = new Manipulator();
+ byte[] clazz = manipulator.manipulate(getBytesFromFile(new File("target/test-classes/test/NonSunClass.class")));
+ ManipulatedClassLoader classloader = new ManipulatedClassLoader("test.NonSunClass", clazz);
+ Class cl = classloader.findClass("test.NonSunClass");
+ Assert.assertNotNull(cl);
+ Assert.assertNotNull(manipulator.getManipulationMetadata());
+
+ System.out.println(manipulator.getManipulationMetadata());
+
+ // The manipulation add stuff to the class.
+ Assert.assertTrue(clazz.length > getBytesFromFile(new File("target/test-classes/test/NonSunClass.class")).length);
+
+
+ boolean found = false;
+ Constructor cst = null;
+ Constructor[] csts = cl.getDeclaredConstructors();
+ for (int i = 0; i < csts.length; i++) {
+ System.out.println(Arrays.asList(csts[i].getParameterTypes()));
+ if (csts[i].getParameterTypes().length == 1 &&
+ csts[i].getParameterTypes()[0].equals(InstanceManager.class)) {
+ found = true;
+ cst = csts[i];
+ }
+ }
+ Assert.assertTrue(found);
+
+ // Check the POJO interface
+ Assert.assertTrue(Arrays.asList(cl.getInterfaces()).contains(Pojo.class));
+
+ cst.setAccessible(true);
+ Object pojo = cst.newInstance(new Object[] {new InstanceManager()});
+ Assert.assertNotNull(pojo);
+ Assert.assertTrue(pojo instanceof Pojo);
+
+ Method method = cl.getMethod("getS1", new Class[0]);
+ Assert.assertTrue(((Boolean) method.invoke(pojo, new Object[0])).booleanValue());
+
+ }
+
public void testManipulatingChild() throws Exception {
Manipulator manipulator = new Manipulator();
byte[] clazz = manipulator.manipulate(getBytesFromFile(new File("target/test-classes/test/Child.class")));
diff --git a/ipojo/manipulator/manipulator/src/test/java/test/NonSunClass.java b/ipojo/manipulator/manipulator/src/test/java/test/NonSunClass.java
new file mode 100644
index 0000000..1d84182
--- /dev/null
+++ b/ipojo/manipulator/manipulator/src/test/java/test/NonSunClass.java
@@ -0,0 +1,19 @@
+package test;
+
+/**
+ * Class that does not respect Sun conventions.
+ */
+public class NonSunClass {
+
+ /**
+ * Does not match the Sun convention.
+ */
+ private boolean S1 = true;
+
+ public boolean getS1() {
+ return S1;
+ }
+
+
+
+}