1 15 package org.apache.hivemind.methodmatch; 16 17 import org.apache.hivemind.ApplicationRuntimeException; 18 import org.apache.hivemind.Location; 19 import org.apache.hivemind.Resource; 20 import org.apache.hivemind.impl.LocationImpl; 21 import org.apache.hivemind.service.MethodSignature; 22 23 28 public class TestMethodMatcher extends AbstractMethodTestCase 29 { 30 private MethodMatcher _m = new MethodMatcher(); 31 32 public void testEmpty() 33 { 34 MethodSignature sig = getMethodSignature(this, "equals"); 35 36 assertEquals(null, _m.get(sig)); 37 } 38 39 public void testNoMatch() 40 { 41 _m.put("equals(java.lang.Object)", "match"); 42 43 assertEquals(null, _m.get(getMethodSignature(this, "hashCode"))); 44 } 45 46 47 public void testNoMatchReturnsDefault() 48 { 49 MethodMatcher m = new MethodMatcher("FRED"); 50 51 assertEquals("FRED", m.get(getMethodSignature(this, "hashCode"))); 52 53 m.put("zoop", "BARNEY"); 54 55 assertEquals("FRED", m.get(getMethodSignature(this, "hashCode"))); 56 } 57 58 public void testMatch() 59 { 60 _m.put("equals(java.lang.Object)", "match"); 61 62 assertEquals("match", _m.get(getMethodSignature(this, "equals"))); 63 } 64 65 public void testMatchPriority() 66 { 67 _m.put("*", "star"); 68 _m.put("equals(java.lang.Object)", "exact"); 69 70 assertEquals("star", _m.get(getMethodSignature(this, "equals"))); 71 } 72 73 public void testParseException() 74 { 75 _m.put("*(", "invalid"); 76 77 try 78 { 79 _m.get(getMethodSignature(this, "hashCode")); 80 unreachable(); 81 } 82 catch (ApplicationRuntimeException ex) 83 { 84 assertEquals("Method pattern '*(' contains an invalid parameters pattern.", ex 85 .getMessage()); 86 } 87 } 88 89 public void testParseExceptionWithLocation() throws Exception 90 { 91 Resource r = getResource("MethodSubject.class"); 92 Location l = new LocationImpl(r, 3); 93 94 MethodSubject s = new MethodSubject(); 95 s.setLocation(l); 96 97 _m.put("*(", s); 98 99 try 100 { 101 _m.get(getMethodSignature(this, "hashCode")); 102 unreachable(); 103 } 104 catch (ApplicationRuntimeException ex) 105 { 106 String message = ex.getMessage(); 107 108 boolean matchesPattern = matches( 109 message, 110 "Exception at .*?, line 3: Method pattern '\\*\\(' contains an invalid parameters pattern\\."); 111 112 assertEquals(true, matchesPattern); 113 } 114 } 115 } | Popular Tags |