Ejemplo n.º 1
0
  @Nullable
  private Expectation findPreviousNotStrictExpectation(@Nonnull ExpectedInvocation newInvocation) {
    int n = notStrictExpectations.size();

    if (n == 0) {
      return null;
    }

    Object mock = newInvocation.instance;
    String mockClassDesc = newInvocation.getClassDesc();
    String mockNameAndDesc = newInvocation.getMethodNameAndDescription();
    boolean constructorInvocation = newInvocation.isConstructor();

    for (int i = 0; i < n; i++) {
      Expectation previousExpectation = notStrictExpectations.get(i);

      if (isMatchingInvocation(
              mock, mockClassDesc, mockNameAndDesc, constructorInvocation, previousExpectation)
          && isWithMatchingArguments(newInvocation, previousExpectation.invocation)) {
        return previousExpectation;
      }
    }

    return null;
  }
Ejemplo n.º 2
0
 private boolean isMatchingInvocation(
     @Nullable Object mock,
     @Nonnull String mockClassDesc,
     @Nonnull String mockNameAndDesc,
     boolean constructorInvocation,
     @Nonnull Expectation expectation) {
   ExpectedInvocation invocation = expectation.invocation;
   return invocation.isMatch(mockClassDesc, mockNameAndDesc)
       && isSameMockedClass(mock, invocation.instance)
       && (constructorInvocation || mock == null || isMatchingInstance(mock, expectation));
 }
Ejemplo n.º 3
0
  private void removeMatchingExpectationsCreatedBefore(@Nonnull ExpectedInvocation invocation) {
    Expectation previousExpectation = findPreviousNotStrictExpectation(invocation);

    if (previousExpectation != null) {
      notStrictExpectations.remove(previousExpectation);
      invocation.copyDefaultReturnValue(previousExpectation.invocation);
    }
  }
Ejemplo n.º 4
0
 private void forceMatchingOnMockInstanceIfRequired(@Nonnull ExpectedInvocation invocation) {
   if (isToBeMatchedOnInstance(invocation.instance, invocation.getMethodNameAndDescription())) {
     invocation.matchInstance = true;
   }
 }