felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clem...@apache.org
Subject svn commit: r1402157 - in /felix/trunk/ipojo/manipulator/manipulator/src/test/java: org/apache/felix/ipojo/manipulation/ManipulatorTest.java test/NonSunClass.java
Date Thu, 25 Oct 2012 14:08:25 GMT
Author: clement
Date: Thu Oct 25 14:08:25 2012
New Revision: 1402157

URL: http://svn.apache.org/viewvc?rev=1402157&view=rev
Log:
Added a test checking the field duplication.

Added:
    felix/trunk/ipojo/manipulator/manipulator/src/test/java/test/NonSunClass.java
Modified:
    felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulation/ManipulatorTest.java

Modified: felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulation/ManipulatorTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulation/ManipulatorTest.java?rev=1402157&r1=1402156&r2=1402157&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulation/ManipulatorTest.java
(original)
+++ felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulation/ManipulatorTest.java
Thu Oct 25 14:08:25 2012
@@ -109,6 +109,46 @@ public class ManipulatorTest extends Tes
 
     }
 
+    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")));

Added: felix/trunk/ipojo/manipulator/manipulator/src/test/java/test/NonSunClass.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/test/java/test/NonSunClass.java?rev=1402157&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/test/java/test/NonSunClass.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/test/java/test/NonSunClass.java Thu Oct
25 14:08:25 2012
@@ -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;
+    }
+
+
+
+}



Mime
View raw message