Exemplo n.º 1
0
  private boolean isMatchingInstance(
      @Nonnull Object invokedInstance, @Nonnull Expectation expectation) {
    ExpectedInvocation invocation = expectation.invocation;
    assert invocation.instance != null;

    if (isEquivalentInstance(invocation.instance, invokedInstance)) {
      return true;
    }

    if (TestRun.getExecutingTest().isInjectableMock(invokedInstance)) {
      return false;
    }

    if (dynamicMockInstancesToMatch != null) {
      if (containsReference(dynamicMockInstancesToMatch, invokedInstance)) {
        return false;
      }

      Class<?> invokedClass = invocation.instance.getClass();

      for (Object dynamicMock : dynamicMockInstancesToMatch) {
        if (dynamicMock.getClass() == invokedClass) {
          return false;
        }
      }
    }

    return !invocation.matchInstance && expectation.recordPhase != null;
  }
Exemplo n.º 2
0
 boolean isEquivalentInstance(
     @Nonnull Object invocationInstance, @Nonnull Object invokedInstance) {
   return invocationInstance == invokedInstance
       || invocationInstance == replacementMap.get(invokedInstance)
       || invocationInstance == instanceMap.get(invokedInstance)
       || invokedInstance == instanceMap.get(invocationInstance)
       || TestRun.getExecutingTest()
           .isInvokedInstanceEquivalentToCapturedInstance(invocationInstance, invokedInstance);
 }
Exemplo n.º 3
0
  private boolean isSameMockedClass(@Nullable Object mock1, @Nullable Object mock2) {
    if (mock1 == mock2) {
      return true;
    }

    if (mock1 != null && mock2 != null) {
      Class<?> mockedClass1 = mock1.getClass();
      Class<?> mockedClass2 = mock2.getClass();

      if (mockedClass1 == mockedClass2
          || TestRun.getExecutingTest()
              .isInvokedInstanceEquivalentToCapturedInstance(mock1, mock2)) {
        return true;
      }

      return TestRun.mockFixture().areCapturedClasses(mockedClass1, mockedClass2);
    }

    return false;
  }
Exemplo n.º 4
0
  boolean isToBeMatchedOnInstance(@Nullable Object mock, @Nonnull String mockNameAndDesc) {
    if (mock == null || mockNameAndDesc.charAt(0) == '<') {
      return false;
    }

    if (dynamicMockInstancesToMatch != null
        && containsReference(dynamicMockInstancesToMatch, mock)) {
      return true;
    }

    if (mockedTypesToMatchOnInstances != null) {
      Class<?> mockedClass = GeneratedClasses.getMockedClass(mock);

      if (containsReference(mockedTypesToMatchOnInstances, mockedClass)) {
        return true;
      }
    } else if (TestRun.getExecutingTest().isInjectableMock(mock)) {
      return true;
    }

    return false;
  }