Java 类org.mockito.invocation.MockHandler 实例源码

项目:powermock    文件:PowerMockitoStubberImpl.java   
@SuppressWarnings("unchecked")
private void addAnswersForStubbing(MockitoMethodInvocationControl invocationControl) {
    final MockHandler mockHandler = invocationControl.getInvocationHandler().getHandler();
    final List list = Whitebox.getInternalState(this, List.class);
    try {
        Whitebox.invokeMethod(mockHandler, "setAnswersForStubbing", list);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
项目:powermock    文件:PowerMockMaker.java   
public MockHandler getHandler(Object mock) {
    // Return a fake mock handler for static method mocks
    if(mock instanceof Class) {
        return new PowerMockInternalMockHandler((Class<?>) mock);
    } else {
        return cglibMockMaker.getHandler(mock);
    }
}
项目:powermock    文件:MockitoMethodInvocationControl.java   
private MockHandler replaceMatchersBinderIfNeeded(MockHandler mockHandler) {
    if(!Whitebox.getFieldsOfType(mockHandler, MatchersBinder.class).isEmpty()) {
        Whitebox.setInternalState(mockHandler, new PowerMockMatchersBinder());
    } else if(!Whitebox.getFieldsOfType(mockHandler, InternalMockHandler.class).isEmpty()) {
        final MockHandler internalMockHandler = Whitebox.getInternalState(mockHandler, MockHandler.class);
        return replaceMatchersBinderIfNeeded(internalMockHandler);
    }
    return mockHandler;
}
项目:mockito-cglib    文件:CglibMockMaker.java   
private InternalMockHandler cast(MockHandler handler) {
    if (!(handler instanceof InternalMockHandler)) {
        throw new MockitoException("At the moment you cannot provide own implementations of MockHandler." +
                "\nPlease see the javadocs for the MockMaker interface.");
    }
    return (InternalMockHandler) handler;
}
项目:mockito-cglib    文件:CglibMockMaker.java   
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();
}
项目:astor    文件:CglibMockMaker.java   
private InternalMockHandler cast(MockHandler handler) {
    if (!(handler instanceof InternalMockHandler)) {
        throw new MockitoException("At the moment you cannot provide own implementations of MockHandler." +
                "\nPlease see the javadocs for the MockMaker interface.");
    }
    return (InternalMockHandler) handler;
}
项目:astor    文件:CglibMockMaker.java   
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();
}
项目:astor    文件:MockUtil.java   
public <T> T createMock(MockCreationSettings<T> settings) {
    MockHandler mockHandler = new MockHandlerFactory().create(settings);

    T mock = mockMaker.createMock(settings, mockHandler);

    Object spiedInstance = settings.getSpiedInstance();
    if (spiedInstance != null) {
        new LenientCopyTool().copyToMock(spiedInstance, mock);
    }

    return mock;
}
项目:astor    文件:MockUtil.java   
public <T> void resetMock(T mock) {
    InternalMockHandler oldHandler = (InternalMockHandler) getMockHandler(mock);
    MockCreationSettings settings = oldHandler.getMockSettings();
    MockHandler newHandler = new MockHandlerFactory().create(settings);

    mockMaker.resetMock(mock, newHandler, settings);
}
项目:astor    文件:MockUtil.java   
public <T> InternalMockHandler<T> getMockHandler(T mock) {
    if (mock == null) {
        throw new NotAMockException("Argument should be a mock, but is null!");
    }

    if (isMockitoMock(mock)) {
        MockHandler handler = mockMaker.getHandler(mock);
        return (InternalMockHandler) handler;
    } else {
        throw new NotAMockException("Argument should be a mock, but is: " + mock.getClass());
    }
}
项目:dexmaker    文件:InlineDexmakerMockMaker.java   
@Override
public void resetMock(Object mock, MockHandler newHandler, MockCreationSettings settings) {
    InvocationHandlerAdapter adapter = getInvocationHandlerAdapter(mock);
    if (adapter != null) {
        adapter.setHandler(newHandler);
    }
}
项目:powermock    文件:PowerMockMaker.java   
public <T> T createMock(MockCreationSettings<T> settings, MockHandler handler) {
    return cglibMockMaker.createMock(settings, handler);
}
项目:powermock    文件:PowerMockMaker.java   
public void resetMock(Object mock, MockHandler newHandler, MockCreationSettings settings) {
    cglibMockMaker.resetMock(mock, newHandler, settings);
}
项目:mockito-cglib    文件:MethodInterceptorFilter.java   
public MockHandler getHandler() {
    return handler;
}
项目:mockito-cglib    文件:CglibMockMaker.java   
public <T> T createMock(MockCreationSettings<T> settings, MockHandler handler) {
    InternalMockHandler mockitoHandler = cast(handler);
    new AcrossJVMSerializationFeature().enableSerializationAcrossJVM(settings);
    return new ClassImposterizer(new InstantiatorProvider().getInstantiator(settings)).imposterise(
            new MethodInterceptorFilter(mockitoHandler, settings), settings.getTypeToMock(), settings.getExtraInterfaces());
}
项目:mockito-cglib    文件:CglibMockMaker.java   
public void resetMock(Object mock, MockHandler newHandler, MockCreationSettings settings) {
    ((Factory) mock).setCallback(0, new MethodInterceptorFilter(cast(newHandler), settings));
}
项目:j2objc    文件:InvocationHandlerAdapter.java   
public InvocationHandlerAdapter(MockHandler handler) {
  this.handler = handler;
}
项目:j2objc    文件:InvocationHandlerAdapter.java   
public MockHandler getHandler() {
  return handler;
}
项目:j2objc    文件:InvocationHandlerAdapter.java   
public void setHandler(MockHandler handler) {
  this.handler = handler;
}
项目:j2objc    文件:IosMockMaker.java   
@Override
public MockHandler getHandler(Object mock) {
  InvocationHandlerAdapter adapter = getInvocationHandlerAdapter(mock);
  return adapter != null ? adapter.getHandler() : null;
}
项目:j2objc    文件:IosMockMaker.java   
@Override
@SuppressWarnings("rawtypes")
public void resetMock(Object mock, MockHandler newHandler, MockCreationSettings settings) {
  InvocationHandlerAdapter adapter = getInvocationHandlerAdapter(mock);
  adapter.setHandler(newHandler);
}
项目:astor    文件:MethodInterceptorFilter.java   
public MockHandler getHandler() {
    return handler;
}
项目:astor    文件:CglibMockMaker.java   
public <T> T createMock(MockCreationSettings<T> settings, MockHandler handler) {
    InternalMockHandler mockitoHandler = cast(handler);
    new AcrossJVMSerializationFeature().enableSerializationAcrossJVM(settings);
    return ClassImposterizer.INSTANCE.imposterise(
            new MethodInterceptorFilter(mockitoHandler, settings), settings.getTypeToMock(), settings.getExtraInterfaces());
}
项目:astor    文件:CglibMockMaker.java   
public void resetMock(Object mock, MockHandler newHandler, MockCreationSettings settings) {
    ((Factory) mock).setCallback(0, new MethodInterceptorFilter(cast(newHandler), settings));
}
项目:dexmaker    文件:InvocationHandlerAdapter.java   
public InvocationHandlerAdapter(MockHandler handler) {
    this.handler = handler;
}
项目:dexmaker    文件:InvocationHandlerAdapter.java   
public MockHandler getHandler() {
    return handler;
}
项目:dexmaker    文件:InvocationHandlerAdapter.java   
public void setHandler(MockHandler handler) {
    this.handler = handler;
}
项目:dexmaker    文件:DexmakerMockMaker.java   
@Override
public void resetMock(Object mock, MockHandler newHandler, MockCreationSettings settings) {
    InvocationHandlerAdapter adapter = getInvocationHandlerAdapter(mock);
    adapter.setHandler(newHandler);
}
项目:dexmaker    文件:DexmakerMockMaker.java   
@Override
public MockHandler getHandler(Object mock) {
    InvocationHandlerAdapter adapter = getInvocationHandlerAdapter(mock);
    return adapter != null ? adapter.getHandler() : null;
}
项目:dexmaker    文件:InvocationHandlerAdapter.java   
InvocationHandlerAdapter(MockHandler handler) {
    this.handler = handler;
}
项目:dexmaker    文件:InvocationHandlerAdapter.java   
/**
 * Set a new handler for this adapter.
 */
void setHandler(MockHandler handler) {
    this.handler = handler;
}
项目:dexmaker    文件:InlineDexmakerMockMaker.java   
@Override
public MockHandler getHandler(Object mock) {
    InvocationHandlerAdapter adapter = getInvocationHandlerAdapter(mock);
    return adapter != null ? adapter.getHandler() : null;
}
项目:astor    文件:MockMaker.java   
/**
 * If you want to provide your own implementation of {@code MockMaker} this method should:
 * <ul>
 *     <li>Create a proxy object that implements {@code settings.typeToMock} and potentially also {@code settings.extraInterfaces}.</li>
 *     <li>You may use the information from {@code settings} to create/configure your proxy object.</li>
 *     <li>Your proxy object should carry the {@code handler} with it. For example, if you generate byte code
 *     to create the proxy you could generate an extra field to keep the {@code handler} with the generated object.
 *     Your implementation of {@code MockMaker} is required to provide this instance of {@code handler} when
 *     {@link #getHandler(Object)} is called.
 *     </li>
 * </ul>
 *
 * @param settings - mock creation settings like type to mock, extra interfaces and so on.
 * @param handler See {@link org.mockito.invocation.MockHandler}.
 *                <b>Do not</b> provide your own implementation at this time. Make sure your implementation of
 *                {@link #getHandler(Object)} will return this instance.
 * @param <T> Type of the mock to return, actually the <code>settings.getTypeToMock</code>.
 * @return The mock instance.
 * @since 1.9.5
 */
<T> T createMock(
        MockCreationSettings<T> settings,
        MockHandler handler
);
项目:astor    文件:MockMaker.java   
/**
 * Returns the handler for the {@code mock}. <b>Do not</b> provide your own implementations at this time
 * because the work on the {@link MockHandler} api is not completed.
 * Use the instance provided to you by Mockito at {@link #createMock} or {@link #resetMock}.
 *
 * @param mock The mock instance.
 * @return may return null - it means that there is no handler attached to provided object.
 *   This means the passed object is not really a Mockito mock.
 * @since 1.9.5
 */
MockHandler getHandler(Object mock);
项目:astor    文件:MockMaker.java   
/**
 * Replaces the existing handler on {@code mock} with {@code newHandler}.
 *
 * <p>The invocation handler actually store invocations to achieve
 * stubbing and verification. In order to reset the mock, we pass
 * a new instance of the invocation handler.</p>
 *
 * <p>Your implementation should make sure the {@code newHandler} is correctly associated to passed {@code mock}</p>
 *
 * @param mock The mock instance whose invocation handler is to be replaced.
 * @param newHandler The new invocation handler instance.
 * @param settings The mock settings - should you need to access some of the mock creation details.
 * @since 1.9.5
 */
void resetMock(
        Object mock,
        MockHandler newHandler,
        MockCreationSettings settings
);
项目:dexmaker    文件:InvocationHandlerAdapter.java   
/**
 * Get the handler registered with this adapter.
 *
 * @return handler
 */
MockHandler getHandler() {
    return handler;
}