1 15 package org.apache.hivemind.methodmatch; 16 17 import java.util.ArrayList ; 18 import java.util.List ; 19 20 import org.apache.hivemind.service.MethodSignature; 21 22 28 public class TestMethodFilters extends AbstractMethodTestCase 29 { 30 public void testExactNameFilter() throws Exception 31 { 32 MethodFilter f = new ExactNameFilter("hashCode"); 33 34 assertEquals(true, f.matchMethod(getMethodSignature(this, "hashCode"))); 35 assertEquals(false, f.matchMethod(getMethodSignature(this, "toString"))); 36 } 37 38 public void testNamePrefixFilter() throws Exception 39 { 40 MethodFilter f = new NamePrefixFilter("hash"); 41 42 assertEquals(true, f.matchMethod(getMethodSignature(this, "hashCode"))); 43 assertEquals(false, f.matchMethod(getMethodSignature(this, "toString"))); 44 } 45 46 public void testNameSuffixFilter() throws Exception 47 { 48 MethodFilter f = new NameSuffixFilter("Code"); 49 50 assertEquals(true, f.matchMethod(getMethodSignature(this, "hashCode"))); 51 assertEquals(false, f.matchMethod(getMethodSignature(this, "toString"))); 52 } 53 54 public void testInfixNameFilter() throws Exception 55 { 56 MethodFilter f1 = new InfixNameFilter("od"); 57 58 assertEquals(true, f1.matchMethod(getMethodSignature(this, "hashCode"))); 59 assertEquals(false, f1.matchMethod(getMethodSignature(this, "toString"))); 60 61 MethodFilter f2 = new InfixNameFilter("hashCode"); 62 assertEquals(true, f2.matchMethod(getMethodSignature(this, "hashCode"))); 63 assertEquals(false, f2.matchMethod(getMethodSignature(this, "toString"))); 64 } 65 66 public void testParameterCountFilter() throws Exception 67 { 68 MethodFilter f = new ParameterCountFilter(0); 69 70 assertEquals(true, f.matchMethod(getMethodSignature(this, "hashCode"))); 71 assertEquals(true, f.matchMethod(getMethodSignature(this, "toString"))); 72 assertEquals(false, f.matchMethod(getMethodSignature(this, "equals"))); 73 74 f = new ParameterCountFilter(1); 75 76 assertEquals(false, f.matchMethod(getMethodSignature(this, "hashCode"))); 77 assertEquals(false, f.matchMethod(getMethodSignature(this, "toString"))); 78 assertEquals(true, f.matchMethod(getMethodSignature(this, "equals"))); 79 } 80 81 public void testParameterFilterIntArg() 82 { 83 MethodFilter f = new ParameterFilter(0, "int"); 84 85 assertEquals(true, f.matchMethod(getMethodSignature(MethodSubject.class, "intArg"))); 86 assertEquals(false, f.matchMethod(getMethodSignature(MethodSubject.class, "integerArg"))); 87 } 88 89 public void testParameterFilterIntegerArg() 90 { 91 MethodFilter f = new ParameterFilter(0, "java.lang.Integer"); 92 93 assertEquals(false, f.matchMethod(getMethodSignature(MethodSubject.class, "intArg"))); 94 assertEquals(true, f.matchMethod(getMethodSignature(MethodSubject.class, "integerArg"))); 95 } 96 97 public void testParameterFilterArrayArg() 98 { 99 MethodFilter f = new ParameterFilter(0, "java.lang.Integer[]"); 100 101 assertEquals(false, f.matchMethod(getMethodSignature(MethodSubject.class, "intArg"))); 102 assertEquals(false, f.matchMethod(getMethodSignature(MethodSubject.class, "integerArg"))); 103 assertEquals(true, f.matchMethod(getMethodSignature(MethodSubject.class, "arrayArg"))); 104 assertEquals(false, f.matchMethod(getMethodSignature(MethodSubject.class, "scalarArrayArg"))); 105 } 106 107 public void testParameterFilterScalarArrayArg() 108 { 109 MethodFilter f = new ParameterFilter(0, "int[]"); 110 111 assertEquals(false, f.matchMethod(getMethodSignature(MethodSubject.class, "intArg"))); 112 assertEquals(false, f.matchMethod(getMethodSignature(MethodSubject.class, "integerArg"))); 113 assertEquals(false, f.matchMethod(getMethodSignature(MethodSubject.class, "arrayArg"))); 114 assertEquals(true, f.matchMethod(getMethodSignature(MethodSubject.class, "scalarArrayArg"))); 115 } 116 117 public void testCompositeFilter() 118 { 119 List l = new ArrayList (); 120 l.add(new ExactNameFilter("intArg")); 121 122 CompositeFilter f = new CompositeFilter(l); 123 MethodSignature sig = getMethodSignature(MethodSubject.class, "intArg"); 124 125 assertEquals(true, f.matchMethod(sig)); 126 127 l.add(new ParameterCountFilter(0)); 128 129 assertEquals(false, f.matchMethod(sig)); 130 } 131 132 public void testMatchAllFilter() 133 { 134 MethodFilter f = new MatchAllFilter(); 135 136 assertEquals(true, f.matchMethod(null)); 137 } 138 139 } 140 | Popular Tags |