1   /***************************************************************************************
2    * Copyright (c) Jonas Bonér, Alexandre Vasseur. All rights reserved.                 *
3    * http://aspectwerkz.codehaus.org                                                    *
4    * ---------------------------------------------------------------------------------- *
5    * The software in this package is published under the terms of the LGPL license      *
6    * a copy of which has been included with this distribution in the license.txt file.  *
7    **************************************************************************************/
8   package test;
9   
10  import junit.framework.TestCase;
11  import org.codehaus.aspectwerkz.MethodComparator;
12  
13  import java.lang.reflect.Array;
14  import java.lang.reflect.Method;
15  
16  /***
17   * @author <a href="mailto:jboner@codehaus.org">Jonas Bonér </a>
18   */
19  public class MethodComparatorTest extends TestCase {
20      public void testCompare() {
21          Method method1 = null;
22          Method method11 = null;
23          Method method2 = null;
24          Method method3 = null;
25          Method method4 = null;
26          Method method5 = null;
27          Method method6 = null;
28          try {
29              method1 = this.getClass().getMethod("__generated$_AW_$method1", new Class[] {});
30              method11 = this.getClass().getMethod("__generated$_AW_$method1$x", new Class[] {});
31              method2 = this.getClass().getMethod("__generated$_AW_$method1", new Class[] {
32                  int.class
33              });
34              method3 = this.getClass().getMethod("__generated$_AW_$method2", new Class[] {});
35              method4 = this.getClass().getMethod("__generated$_AW_$method2", new Class[] {
36                  int.class
37              });
38              method5 = this.getClass().getMethod("__generated$_AW_$method2", new Class[] {
39                  String.class
40              });
41              method6 = this.getClass().getMethod("__generated$_AW_$method2", new Class[] {
42                  Array.newInstance(String.class, 1).getClass()
43              });
44          } catch (Exception e) {
45              throw new RuntimeException("exception unexpected: " + e);
46          }
47          assertTrue(0 == MethodComparator.getInstance(MethodComparator.PREFIXED_METHOD).compare(
48              method1,
49              method1));
50          assertTrue(0 == MethodComparator.getInstance(MethodComparator.PREFIXED_METHOD).compare(
51              method2,
52              method2));
53          assertTrue(0 > MethodComparator.getInstance(MethodComparator.PREFIXED_METHOD).compare(
54              method1,
55              method2));
56          assertTrue(0 < MethodComparator.getInstance(MethodComparator.PREFIXED_METHOD).compare(
57              method2,
58              method1));
59          assertTrue(0 > MethodComparator.getInstance(MethodComparator.PREFIXED_METHOD).compare(
60              method1,
61              method11));
62          assertTrue(0 > MethodComparator.getInstance(MethodComparator.PREFIXED_METHOD).compare(
63              method3,
64              method4));
65          assertTrue(0 < MethodComparator.getInstance(MethodComparator.PREFIXED_METHOD).compare(
66              method4,
67              method3));
68          assertTrue(0 > MethodComparator.getInstance(MethodComparator.PREFIXED_METHOD).compare(
69              method1,
70              method4));
71          assertTrue(0 < MethodComparator.getInstance(MethodComparator.PREFIXED_METHOD).compare(
72              method4,
73              method1));
74          assertTrue(0 < MethodComparator.getInstance(MethodComparator.PREFIXED_METHOD).compare(
75              method3,
76              method2));
77          assertTrue(0 > MethodComparator.getInstance(MethodComparator.PREFIXED_METHOD).compare(
78              method2,
79              method3));
80          assertTrue(0 > MethodComparator.getInstance(MethodComparator.PREFIXED_METHOD).compare(
81              method4,
82              method5));
83  
84          // AW-104 test
85          assertTrue(0 > MethodComparator.getInstance(MethodComparator.PREFIXED_METHOD).compare(
86              method5,
87              method6));
88      }
89  
90      public static void main(String[] args) {
91          junit.textui.TestRunner.run(suite());
92      }
93  
94      public static junit.framework.Test suite() {
95          return new junit.framework.TestSuite(MethodComparatorTest.class);
96      }
97  
98      public void __generated$_AW_$method1() {
99      }
100 
101     public void __generated$_AW_$method1$x() {
102     }
103 
104     public void __generated$_AW_$method1(int i) {
105     }
106 
107     public void __generated$_AW_$method2() {
108     }
109 
110     public void __generated$_AW_$method2(int i) {
111     }
112 
113     public void __generated$_AW_$method2(String i) {
114     }
115 
116     public void __generated$_AW_$method2(String[] i) {
117     }
118 }