/** * Attempts to provide more descriptive toString() for given matcher. * Searches matcher class hierarchy for toString() method. If it is found it will be used. * If no toString() is defined for the matcher hierarchy, * uses decamelized class name instead of default Object.toString(). * This way we can promote meaningful names for custom matchers. * * @param matcher * @return */ static String toString(ArgumentMatcher<?> matcher) { Class<?> cls = matcher.getClass(); while(cls != Object.class) { Method[] methods = cls.getDeclaredMethods(); for (Method m : methods) { if(isToStringMethod(m)) { return matcher.toString(); } } cls = cls.getSuperclass(); } return decamelizeMatcher(matcher.getClass().getSimpleName()); }