public boolean isOut(Invocation invocation) { return new ObjectMethodsGuru().isToString(invocation.getMethod()); } }
public boolean isOut(Invocation invocation) { return isToStringMethod(invocation.getMethod()); } }
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable { if (objectMethodsGuru.isEqualsMethod(method)) { return proxy == args[0]; } else if (objectMethodsGuru.isHashCodeMethod(method)) { return hashCodeForMock(proxy); } MockitoMethodProxy mockitoMethodProxy = createMockitoMethodProxy(methodProxy); cglibHacker.setMockitoNamingPolicy(mockitoMethodProxy); MockitoMethod mockitoMethod = createMockitoMethod(method); FilteredCGLIBProxyRealMethod realMethod = new FilteredCGLIBProxyRealMethod(mockitoMethodProxy); Invocation invocation = new InvocationImpl(proxy, mockitoMethod, args, SequenceNumber.next(), realMethod); return handler.handle(invocation); }
public Object answer(InvocationOnMock invocation) { if (methodsGuru.isToString(invocation.getMethod())) { Object mock = invocation.getMock(); MockName name = new MockUtil().getMockName(mock); if (name.isDefault()) { return "Mock for " + ClassNameFinder.classNameForMock(mock) + ", hashCode: " + mock.hashCode(); } else { return name.toString(); } } else if (methodsGuru.isCompareToMethod(invocation.getMethod())) { //see issue 184. //mocks by default should not return 0 for compareTo because they are not the same. Hence we return 1 (anything but 0 is good). //Only for compareTo() method by the Comparable interface return 1; } Class<?> returnType = invocation.getMethod().getReturnType(); return returnValueFor(returnType); }
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); }
public boolean isToString(Method method) { return isToString(new DelegatingMethod(method)); }
@Override public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable { if (objectMethodsGuru.isEqualsMethod(method)) { return proxy == args[0]; } else if (objectMethodsGuru.isHashCodeMethod(method)) { return hashCodeForMock(proxy); } else if (acrossJVMSerializationFeature.isWriteReplace(method)) { return acrossJVMSerializationFeature.writeReplace(proxy); } MockitoMethodProxy mockitoMethodProxy = createMockitoMethodProxy(methodProxy); new CGLIBHacker().setMockitoNamingPolicy(methodProxy); MockitoMethod mockitoMethod = createMockitoMethod(method); CleanTraceRealMethod realMethod = new CleanTraceRealMethod(mockitoMethodProxy); Invocation invocation = new InvocationImpl(proxy, mockitoMethod, args, SequenceNumber.next(), realMethod); return handler.handle(invocation); }
public Object answer(InvocationOnMock invocation) { if (methodsGuru.isToString(invocation.getMethod())) { Object mock = invocation.getMock(); MockName name = new MockUtil().getMockName(mock); if (name.isSurrogate()) { return "Mock for " + ClassNameFinder.classNameForMock(mock) + ", hashCode: " + mock.hashCode(); } else { return name.toString(); } } else if (methodsGuru.isCompareToMethod(invocation.getMethod())) { //see issue 184. //mocks by default should not return 0 for compareTo because they are not the same. Hence we return 1 (anything but 0 is good). //Only for compareTo() method by the Comparable interface return 1; } Class<?> returnType = invocation.getMethod().getReturnType(); return returnValueFor(returnType); }
public boolean isToString(Method method) { return isToString(new DelegatingMethod(method)); }
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (objectMethodsGuru.isEqualsMethod(method)) { return proxy == args[0]; } else if (objectMethodsGuru.isHashCodeMethod(method)) { return System.identityHashCode(proxy); } ProxiedMethod proxiedMethod = new ProxiedMethod(method); return handler.handle(new InvocationImpl(proxy, proxiedMethod, args, SequenceNumber.next(), proxiedMethod)); }
public Object answer(InvocationOnMock currentInvocation) throws Throwable { if (new ObjectMethodsGuru().isToString(currentInvocation.getMethod())) { return "SmartNull returned by this unstubbed method call on a mock:\n" + unstubbedInvocation.toString(); } new Reporter().smartNullPointerException(unstubbedInvocation.toString(), location); return null; } }
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); } }
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable { if (objectMethodsGuru.isEqualsMethod(method)) { return proxy == args[0]; } else if (objectMethodsGuru.isHashCodeMethod(method)) { return hashCodeForMock(proxy); } MockitoMethodProxy mockitoMethodProxy = createMockitoMethodProxy(methodProxy); cglibHacker.setMockitoNamingPolicy(mockitoMethodProxy); MockitoMethod mockitoMethod = createMockitoMethod(method); FilteredCGLIBProxyRealMethod realMethod = new FilteredCGLIBProxyRealMethod(mockitoMethodProxy); Invocation invocation = new Invocation(proxy, mockitoMethod, args, SequenceNumber.next(), realMethod); return handler.handle(invocation); }
void assertWantedIsVerifiable() { if (wanted == null) { return; } ObjectMethodsGuru o = new ObjectMethodsGuru(); if (o.isToString(wanted.getMethod())) { new Reporter().cannotVerifyToString(); } } }
/** * 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()); }
public boolean isToString() { return new ObjectMethodsGuru().isToString(getMethod()); }
private void assertWantedIsVerifiable() { if (wanted == null) { return; } if (isToStringMethod(wanted.getMethod())) { throw cannotVerifyToString(); } } }
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable { if (new ObjectMethodsGuru().isToString(method)) { return "SmartNull returned by this unstubbed method call on a mock:\n" + invocation.toString(); } new Reporter().smartNullPointerException(invocation.toString(), location); return null; } }
void assertWantedIsVerifiable() { if (wanted == null) { return; } ObjectMethodsGuru o = new ObjectMethodsGuru(); if (o.isToString(wanted.getMethod())) { new Reporter().cannotVerifyToString(); } } }