1 package org.sapia.soto.reflect; 2 3 import junit.framework.TestCase; 4 5 import java.util.List ; 6 7 8 12 public class MatcherTest extends TestCase { 13 16 public MatcherTest(String name) { 17 super(name); 18 } 19 20 public void testNoMethodName() throws Exception { 21 Matcher m = new Matcher(); 22 m.setDeclaredMethods(true); 23 m.setSig("java.lang.String"); 24 25 List methods = m.scanMethods(Dog.class); 26 super.assertEquals(2, methods.size()); 27 } 28 29 public void testWithMethodName() throws Exception { 30 Matcher m = new Matcher(); 31 m.setDeclaredMethods(true); 32 m.setName("setName"); 33 m.setSig("java.lang.String"); 34 35 List methods = m.scanMethods(Dog.class); 36 super.assertEquals(1, methods.size()); 37 m = new Matcher(); 38 m.setDeclaredMethods(true); 39 m.setName("getName"); 40 m.setSig(""); 41 methods = m.scanMethods(Dog.class); 42 super.assertEquals(1, methods.size()); 43 } 44 45 public void testNoSig() throws Exception { 46 Matcher m = new Matcher(); 47 m.setDeclaredMethods(true); 48 m.setName("*Name"); 49 50 List methods = m.scanMethods(Dog.class); 51 super.assertEquals(2, methods.size()); 52 } 53 54 public void testNoSigNoMethod() throws Exception { 55 Matcher m = new Matcher(); 56 m.setDeclaredMethods(true); 57 58 List methods = m.scanMethods(Dog.class); 59 super.assertEquals(9, methods.size()); 60 } 61 62 public void testPublicMethods() throws Exception { 63 Matcher m = new Matcher(); 64 m.setDeclaredMethods(true); 65 m.setName("setAttribute*"); 66 m.setVisibility("public"); 67 68 List methods = m.scanMethods(Dog.class); 69 super.assertEquals(1, methods.size()); 70 } 71 72 public void testProtectedMethods() throws Exception { 73 Matcher m = new Matcher(); 74 m.setDeclaredMethods(true); 75 m.setName("setAttribute*"); 76 m.setVisibility("protected"); 77 78 List methods = m.scanMethods(Dog.class); 79 super.assertEquals(1, methods.size()); 80 } 81 82 public void testPrivateMethods() throws Exception { 83 Matcher m = new Matcher(); 84 m.setDeclaredMethods(true); 85 m.setName("setAttribute*"); 86 m.setVisibility("private"); 87 88 List methods = m.scanMethods(Dog.class); 89 super.assertEquals(1, methods.size()); 90 } 91 92 public void testPublicProtectedMethods() throws Exception { 93 Matcher m = new Matcher(); 94 m.setDeclaredMethods(true); 95 m.setName("setAttribute*"); 96 m.setVisibility("public, protected"); 97 98 List methods = m.scanMethods(Dog.class); 99 super.assertEquals(2, methods.size()); 100 } 101 102 public void testIncludeNoExclude() throws Exception { 103 Matcher m = new Matcher(); 104 m.setName("*"); 105 m.setVisibility("public, protected"); 106 m.setIncludes("**.*Dog"); 107 108 List methods = m.scanMethods(Dog.class); 109 super.assertEquals(7, methods.size()); 110 } 111 112 public void testIncludeExclude() throws Exception { 113 Matcher m = new Matcher(); 114 m.setName("*"); 115 m.setVisibility("public, protected"); 116 m.setIncludes("**.*Dog, java.lang.Object"); 117 m.setExcludes("**.Object"); 118 119 List methods = m.scanMethods(Dog.class); 120 super.assertEquals(7, methods.size()); 121 } 122 123 public void testExcludeNoInclude() throws Exception { 124 Matcher m = new Matcher(); 125 m.setName("*"); 126 m.setVisibility("public, protected"); 127 m.setExcludes("**.Object"); 128 129 List methods = m.scanMethods(Dog.class); 130 super.assertEquals(8, methods.size()); 131 } 132 133 public static class Dog extends Animal { 134 public String getName() { 135 return null; 136 } 137 138 public void setName(String name) { 139 } 140 141 public int getAge() { 142 return 0; 143 } 144 145 public void setAge(int age) { 146 } 147 148 public String getColor() { 149 return null; 150 } 151 152 public void setColor(String color) { 153 } 154 155 protected void setAttributeProtected(int i) { 156 } 157 158 private void setAttributePrivate(int i) { 159 } 160 161 public void setAttributePublic(int i) { 162 } 163 } 164 165 public static class Animal { 166 public int compareTo(Object arg0) { 167 return 0; 168 } 169 } 170 } 171 | Popular Tags |