Revert: unintended commit on the manipulator test suite.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1454302 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulation/ManipulatedClassLoader.java b/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulation/ManipulatedClassLoader.java
index 995f07e..0d3af17 100644
--- a/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulation/ManipulatedClassLoader.java
+++ b/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulation/ManipulatedClassLoader.java
@@ -18,9 +18,6 @@
*/
package org.apache.felix.ipojo.manipulation;
-import java.util.HashMap;
-import java.util.Map;
-
/**
* A classloader used to load manipulated classes.
*/
@@ -29,33 +26,19 @@
private String name;
private byte[] clazz;
- private Map<String, byte[]> inners = new HashMap<String, byte[]>();
-
public ManipulatedClassLoader(String name, byte[] clazz) {
this.name = name;
this.clazz = clazz;
}
- public void addInnerClasses(Map<String, byte[]> inn) {
- inners = inn;
- }
-
public Class findClass(String name) throws ClassNotFoundException {
if (name.equals(this.name)) {
return defineClass(name, clazz, 0, clazz.length);
}
- if (inners.containsKey(name)) {
- return defineClass(name, inners.get(name), 0, inners.get(name).length);
-
- }
return super.findClass(name);
}
public Class loadClass(String arg0) throws ClassNotFoundException {
- if (inners.containsKey(arg0)) {
- return defineClass(arg0, inners.get(arg0), 0, inners.get(arg0).length);
-
- }
return super.loadClass(arg0);
}
}
diff --git a/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulation/switches/TestSwitches.java b/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulation/switches/TestSwitches.java
deleted file mode 100644
index f98264b..0000000
--- a/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulation/switches/TestSwitches.java
+++ /dev/null
@@ -1,99 +0,0 @@
-package org.apache.felix.ipojo.manipulation.switches;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.felix.ipojo.manipulation.ManipulatedClassLoader;
-import org.apache.felix.ipojo.manipulation.Manipulator;
-import org.junit.Assert;
-import org.junit.Test;
-import org.objectweb.asm.ClassReader;
-import org.objectweb.asm.util.CheckClassAdapter;
-import test.switches.Color;
-
-import java.io.*;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Checks the manipulation of switch constructs
- */
-public class TestSwitches {
-
-
- @Test
- public void testSwitchOnInteger() throws IOException, ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
- Manipulator manipulator = new Manipulator();
- byte[] clazz = manipulator.manipulate(getBytesFromFile(new File
- ("target/test-classes/test/switches/Switches.class")));
- ManipulatedClassLoader classloader = new ManipulatedClassLoader("test.switches.Switches", clazz);
-
- ClassReader reader = new ClassReader(clazz);
- CheckClassAdapter.verify(reader, false, new PrintWriter(new File("/tmp/class_dump")));
-
- Class cl = classloader.findClass("test.switches.Switches");
- Object o = cl.newInstance();
-
- Method method = cl.getMethod("switchOnInteger", new Class[] { Integer.TYPE});
- int zero = (Integer) method.invoke(o, 0);
- int one = (Integer) method.invoke(o, 1);
- int two = (Integer) method.invoke(o, 2);
- int three = (Integer) method.invoke(o, 4);
-
- Assert.assertEquals(zero, 0);
- Assert.assertEquals(one, 1);
- Assert.assertEquals(two, 2);
- Assert.assertEquals(three, 3);
- }
-
- @Test
- public void testSwitchOnEnum() throws IOException, ClassNotFoundException, IllegalAccessException,
- InstantiationException, NoSuchMethodException, InvocationTargetException {
- Manipulator manipulator = new Manipulator();
- byte[] clazz = manipulator.manipulate(getBytesFromFile(new File
- ("target/test-classes/test/switches/Switches.class")));
- ManipulatedClassLoader classloader = new ManipulatedClassLoader("test.switches.Switches", clazz);
- Map<String, byte[]> inners = new HashMap<String, byte[]>();
-
- inners.put("test.switches.Switches$1", getBytesFromFile(new File
- ("target/test-classes/test/switches/Switches$1.class")));
- classloader.addInnerClasses(inners);
-
- FileUtils.writeByteArrayToFile(new File("target/Switches.class"), clazz);
-
- Class cl = classloader.findClass("test.switches.Switches");
- Object o = cl.newInstance();
-
- Method method = cl.getMethod("switchOnEnum", new Class[] { Color.class});
- int one = (Integer) method.invoke(o, Color.RED);
- int two = (Integer) method.invoke(o, Color.GREEN);
- int three = (Integer) method.invoke(o, Color.BLUE);
-
- Assert.assertEquals(one, 1);
- Assert.assertEquals(two, 2);
- Assert.assertEquals(three, 3);
- }
-
- public static byte[] getBytesFromFile(File file) throws IOException {
- InputStream is = new FileInputStream(file);
- long length = file.length();
- byte[] bytes = new byte[(int)length];
-
- // Read in the bytes
- int offset = 0;
- int numRead = 0;
- while (offset < bytes.length
- && (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
- offset += numRead;
- }
-
- // Ensure all the bytes have been read in
- if (offset < bytes.length) {
- throw new IOException("Could not completely read file "+file.getName());
- }
-
- // Close the input stream and return bytes
- is.close();
- return bytes;
- }
-}
diff --git a/ipojo/manipulator/manipulator/src/test/java/test/switches/Color.java b/ipojo/manipulator/manipulator/src/test/java/test/switches/Color.java
deleted file mode 100644
index 462e742..0000000
--- a/ipojo/manipulator/manipulator/src/test/java/test/switches/Color.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package test.switches;
-
-/**
- * An enum.
- */
-public enum Color {
- RED, GREEN, BLUE
-}
diff --git a/ipojo/manipulator/manipulator/src/test/java/test/switches/Switches.java b/ipojo/manipulator/manipulator/src/test/java/test/switches/Switches.java
deleted file mode 100644
index a4ef6cf..0000000
--- a/ipojo/manipulator/manipulator/src/test/java/test/switches/Switches.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package test.switches;
-
-/**
- * A component using switch on integers and enum.
- */
-public class Switches {
-
-
- public int switchOnInteger(int i) {
- switch (i) {
- case 0 : return 0;
- case 1 : return 1;
- case 2 : return 2;
- default: return 3;
- }
- }
-
- public int switchOnEnum(Color c) {
- switch (c) {
- case RED: return 1;
- case GREEN: return 2;
- default: return 3;
- }
- }
-}