1 package com.google.code.beanmatchers; 2 3 import static com.google.code.beanmatchers.BeanOperations.instantiateBean; 4 5 import org.hamcrest.Description; 6 import org.hamcrest.Matcher; 7 import org.hamcrest.TypeSafeMatcher; 8 9 public class InstantiatingMatcherDecorator<T> extends TypeSafeMatcher<Class<T>> { 10 11 private final Matcher<T> delegateMatcher; 12 13 public InstantiatingMatcherDecorator(Matcher<T> matcher) { 14 this.delegateMatcher = matcher; 15 } 16 17 @Override 18 protected boolean matchesSafely(Class<T> beanType) { 19 T beanInstance = instantiateBean(beanType); 20 return delegateMatcher.matches(beanInstance); 21 } 22 23 @Override 24 protected void describeMismatchSafely(Class<T> beanType, Description mismatchDescription) { 25 T beanInstance = instantiateBean(beanType); 26 delegateMatcher.describeMismatch(beanInstance, mismatchDescription); 27 } 28 29 public void describeTo(Description description) { 30 delegateMatcher.describeTo(description); 31 } 32 }