@Override public MockSettings verificationStartedListeners(VerificationStartedListener... listeners) { addListeners(listeners, this.verificationStartedListeners, "verificationStartedListeners"); return this; }
@Override public <T> MockCreationSettings<T> build(Class<T> typeToMock) { return validatedSettings(typeToMock, (CreationSettings<T>) this); }
@Override public MockSettings serializable() { return serializable(SerializableMode.BASIC); }
Object returnValueFor(Class<?> clazz) { if (!mockitoCore.isTypeMockable(clazz)) { return null; } return mockitoCore.mock(clazz, new MockSettingsImpl().defaultAnswer(this)); } }
public <T> T createMock(MockCreationSettings<T> settings, MockHandler handler) { InternalMockHandler mockitoHandler = cast(handler); return ClassImposterizer.INSTANCE.imposterise( new MethodInterceptorFilter(mockitoHandler, settings), settings.getTypeToMock(), settings.getExtraInterfaces()); }
@Override public MockSettings verboseLogging() { if (!invocationListenersContainsType(VerboseMockInvocationLogger.class)) { invocationListeners(new VerboseMockInvocationLogger()); } return this; }
public MockitoMethodProxy createMockitoMethodProxy(MethodProxy methodProxy) { if (mockSettings.isSerializable()) return new SerializableMockitoMethodProxy(methodProxy); return new DelegatingMockitoMethodProxy(methodProxy); }
private static MockitoMethod createMockitoMethod(Method method, MockCreationSettings settings) { if (settings.isSerializable()) { return new SerializableMethod(method); } else { return new DelegatingMethod(method); } } }
public void resetMock(Object mock, MockHandler newHandler, MockCreationSettings settings) { ((Factory) mock).setCallback(0, new MethodInterceptorFilter(cast(newHandler), settings)); }
public MockHandler getHandler(Object mock) { if (!(mock instanceof Factory)) { return null; } Factory factory = (Factory) mock; Callback callback = factory.getCallback(0); if (!(callback instanceof MethodInterceptorFilter)) { return null; } return ((MethodInterceptorFilter) callback).getHandler(); } }
public Object invoke(Object target, Object[] arguments) throws Throwable { return methodProxy.invokeSuper(target, arguments); }
/** * Scans the classpath to find a mock maker plugin if one is available, * allowing mockito to run on alternative platforms like Android. */ static MockMaker findPlatformMockMaker() { return findPluginImplementation(MockMaker.class, new CglibMockMaker()); }
public Object invokeSuper(Object target, Object[] arguments) throws Throwable { return getMethodProxy().invokeSuper(target, arguments); } }
public DelegatingMethod(Method method) { assert method != null : "Method cannot be null"; this.method = method; this.parameterTypes = SuspendMethod.trimSuspendParameterTypes(method.getParameterTypes()); }
public static Class<?>[] trimSuspendParameterTypes(Class<?>[] parameterTypes) { int n = parameterTypes.length; if (n > 0 && isContinuationType(parameterTypes[n - 1])) return Arrays.copyOf(parameterTypes, n - 1); return parameterTypes; }
public MockSettings verboseLogging() { if (!invocationListenersContainsType(VerboseMockInvocationLogger.class)) { invocationListeners(new VerboseMockInvocationLogger()); } return this; }
public static boolean isToStringMethod(Method method) { MockitoMethod m = new DelegatingMethod(method); return m.getReturnType() == String.class && m.getParameterTypes().length == 0 && "toString".equals(m.getName()); }
public MockCreationSettings<T> confirm(Class<T> typeToMock) { return validatedSettings(typeToMock, this); }
@Override public MockSettings invocationListeners(InvocationListener... listeners) { if (listeners == null || listeners.length == 0) { throw invocationListenersRequiresAtLeastOneListener(); } addListeners(listeners, invocationListeners, "invocationListeners"); return this; }
public SerializableMethod(Method method) { this.method = method; declaringClass = method.getDeclaringClass(); methodName = method.getName(); parameterTypes = SuspendMethod.trimSuspendParameterTypes(method.getParameterTypes()); returnType = method.getReturnType(); exceptionTypes = method.getExceptionTypes(); isVarArgs = method.isVarArgs(); isAbstract = (method.getModifiers() & Modifier.ABSTRACT) != 0; }