public boolean isOut(Invocation invocation) { return isToStringMethod(invocation.getMethod()); } }
public Object answer(InvocationOnMock currentInvocation) throws Throwable { if (isToStringMethod(currentInvocation.getMethod())) { return "SmartNull returned by this unstubbed method call on a mock:\n" + unstubbedInvocation.toString(); } throw smartNullPointerException(unstubbedInvocation.toString(), location); } }
/** * 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()); }
private void assertWantedIsVerifiable() { if (wanted == null) { return; } if (isToStringMethod(wanted.getMethod())) { throw cannotVerifyToString(); } } }
public Object answer(InvocationOnMock invocation) { if (isToStringMethod(invocation.getMethod())) { Object mock = invocation.getMock(); MockName name = MockUtil.getMockName(mock); if (name.isDefault()) { return "Mock for " + MockUtil.getMockSettings(mock).getTypeToMock().getSimpleName() + ", hashCode: " + mock.hashCode(); } else { return name.toString(); } } else if (isCompareToMethod(invocation.getMethod())) { //see issue 184. //mocks by default should return 0 if references are the same, otherwise some other value because they are not the same. Hence we return 1 (anything but 0 is good). //Only for compareTo() method by the Comparable interface return invocation.getMock() == invocation.getArgument(0) ? 0 : 1; } Class<?> returnType = invocation.getMethod().getReturnType(); return returnValueFor(returnType); }