01: package org.drools.util.asm;
02:
03: import java.io.InputStream;
04:
05: import junit.framework.TestCase;
06:
07: import org.drools.asm.ClassReader;
08:
09: public class MethodComparerTest extends TestCase {
10:
11: public void testMethodCompare() throws Exception {
12: final MethodComparator comp = new MethodComparator();
13: boolean result = comp.equivalent("evaluate", new ClassReader(
14: getClassData(MethodCompareA.class)), "evaluate",
15: new ClassReader(getClassData(MethodCompareB.class)));
16: assertEquals(true, result);
17:
18: result = comp.equivalent("evaluate", new ClassReader(
19: getClassData(MethodCompareA.class)), "evaluate2",
20: new ClassReader(getClassData(MethodCompareA.class)));
21: assertEquals(false, result);
22:
23: result = comp.equivalent("evaluate", new ClassReader(
24: getClassData(MethodCompareB.class)), "evaluate2",
25: new ClassReader(getClassData(MethodCompareA.class)));
26: assertEquals(false, result);
27:
28: result = comp.equivalent("evaluate", new ClassReader(
29: getClassData(MethodCompareB.class)), "evaluate",
30: new ClassReader(getClassData(MethodCompareA.class)));
31: assertEquals(true, result);
32:
33: result = comp.equivalent("evaluate", new ClassReader(
34: getClassData(MethodCompareA.class)), "evaluate",
35: new ClassReader(getClassData(MethodCompareA.class)));
36: assertEquals(true, result);
37:
38: result = comp.equivalent("evaluate", new ClassReader(
39: getClassData(MethodCompareA.class)), "askew",
40: new ClassReader(getClassData(MethodCompareA.class)));
41: assertEquals(false, result);
42:
43: }
44:
45: private InputStream getClassData(final Class clazz) {
46: final String name = getResourcePath(clazz);
47: return clazz.getResourceAsStream(name);
48: }
49:
50: private String getResourcePath(final Class clazz) {
51: return "/" + clazz.getName().replaceAll("\\.", "/") + ".class";
52: }
53:
54: }
|