Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (c) 2007 Mockito contributors
   * This program is made available under the terms of the MIT License.
   */
  package org.mockito.internal;
  
  import java.util.List;
  
Invocation handler set on mock objects.

Parameters:
<T> type of mock object to handle
 
 public class MockHandler<T> implements IMockHandler {
 
     private static final long serialVersionUID = -2917871070982574165L;
 
 
     private final MockName mockName;
     private final MockSettingsImpl mockSettings;
 
     public MockHandler(MockName mockNameMockingProgress mockingProgressMatchersBinder matchersBinder,
                     MockSettingsImpl mockSettings) {
         this. = mockName;
         this. = mockingProgress;
         this. = matchersBinder;
         this. = mockSettings;
         this. = new MockitoStubber(mockingProgress);
         this. = new RegisteredInvocations();
     }
 
     public MockHandler(MockHandler<T> oldMockHandler) {
         this(oldMockHandler.mockNameoldMockHandler.mockingProgressoldMockHandler.matchersBinder,
                         oldMockHandler.mockSettings);
     }
 
     // for tests
     MockHandler() {
         this(new MockName("mockie for tests"MockHandler.class), new ThreadSafeMockingProgress(),
                         new MatchersBinder(), new MockSettingsImpl());
     }
 
     public Object handle(Invocation invocationthrows Throwable {
         if (.hasAnswersForStubbing()) {
             // stubbing voids with stubVoid() or doAnswer() style
             InvocationMatcher invocationMatcher = .bindMatchers(
                             .getArgumentMatcherStorage(), invocation);
             .setMethodForStubbing(invocationMatcher);
             return null;
         }
         VerificationMode verificationMode = .pullVerificationMode();
 
                         invocation);
 
         .validateState();
 
         if (verificationMode != null) {
             VerificationDataImpl data = new VerificationDataImpl(.getAll(), invocationMatcher);
             verificationMode.verify(data);
             return null;
         }
 
         .add(invocationMatcher.getInvocation());
         .setInvocationForPotentialStubbing(invocationMatcher);
         OngoingStubbingImpl<T> ongoingStubbing = new OngoingStubbingImpl<T>();
         .reportOngoingStubbing(ongoingStubbing);
 
         StubbedInvocationMatcher stubbedInvocation = .findAnswerFor(invocation);
         if (!invocation.isVoid() && stubbedInvocation == null) {
             // it is a return-value interaction but not stubbed. This *might* be
             // a problem
             .getDebuggingInfo().addPotentiallyUnstubbed(invocationMatcher);
         }
 
         if (stubbedInvocation != null) {
             .getDebuggingInfo().reportUsedStub(invocationMatcher);
             stubbedInvocation.captureArgumentsFrom(invocation);
             return stubbedInvocation.answer(invocation);
         } else {
             Object ret = .getDefaultAnswer().answer(invocation);
 
             // redo setting invocation for potential stubbing in case of partial
            // mocks / spies.
            // Without it, the real method inside 'when' might have delegated
            // to other self method and overwrite the intended stubbed method
            // with a different one.
            .setInvocationForPotentialStubbing(invocationMatcher);
            return ret;
        }
    }
    public void verifyNoMoreInteractions() {
        VerificationModeFactory.noMoreInteractions().verify(data);
    }
    public VoidMethodStubbable<T> voidMethodStubbable(T mock) {
        return new VoidMethodStubbableImpl<T>(mock);
    }
        return .getAll();
    }
    public MockName getMockName() {
        return ;
    }
    @SuppressWarnings("unchecked")
    public void setAnswersForStubbing(List<Answeranswers) {
        .setAnswersForStubbing(answers);
    }
New to GrepCode? Check out our FAQ X