1 package com.google.code.beanmatchers; 2 3 import static com.google.code.beanmatchers.BeanOperations.noArgsConstructor; 4 5 import org.hamcrest.Description; 6 import org.hamcrest.TypeSafeDiagnosingMatcher; 7 8 public class HasValidBeanConstructorMatcher extends TypeSafeDiagnosingMatcher<Class> { 9 10 @Override 11 protected boolean matchesSafely(Class item, Description mismatchDescription) { 12 try { 13 noArgsConstructor(item); 14 return true; 15 } catch (BeanMatchersException exception) { 16 mismatchDescription 17 .appendText("bean of type ") 18 .appendValue(item.getName()) 19 .appendText(" does not have a no-args constructor"); 20 return false; 21 } 22 } 23 24 public void describeTo(Description description) { 25 description.appendText("bean class with a valid no-args constructor"); 26 } 27 }