1 3 package org.jmock.examples.website; 4 5 import java.beans.BeanInfo ; 6 import java.beans.IntrospectionException ; 7 import java.beans.Introspector ; 8 import java.beans.PropertyDescriptor ; 9 import junit.framework.AssertionFailedError; 10 import org.jmock.core.Invocation; 11 import org.jmock.core.matcher.StatelessInvocationMatcher; 12 13 14 public class BeanPropertyGetterMatcher extends StatelessInvocationMatcher 15 { 16 17 public boolean matches( Invocation invocation ) { 18 Class beanClass = invocation.invokedMethod.getDeclaringClass(); 19 20 try { 21 BeanInfo beanInfo = Introspector.getBeanInfo(beanClass); 22 PropertyDescriptor [] properties = beanInfo.getPropertyDescriptors(); 23 24 for (int i = 0; i < properties.length; i++) { 25 if (invocation.invokedMethod.equals(properties[i].getReadMethod())) return true; 26 } 27 return false; 28 } 29 catch (IntrospectionException ex) { 30 throw new AssertionFailedError("could not introspect bean class" + beanClass + ": " + ex.getMessage()); 31 } 32 } 33 34 public StringBuffer describeTo( StringBuffer buffer ) { 35 return buffer.append("any bean property getter"); 36 } 37 } 38 | Popular Tags |