Ejemplo n.º 1
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);
 }
Ejemplo n.º 2
0
  private void registerReplacementInstanceIfApplicable(
      @Nullable Object mock, @Nonnull ExpectedInvocation invocation) {
    Object replacementInstance = invocation.replacementInstance;

    if (replacementInstance != null && replacementInstance != invocation.instance) {
      replacementMap.put(mock, replacementInstance);
    }
  }
Ejemplo n.º 3
0
  boolean areInDifferentEquivalenceSets(@Nonnull Object mock1, @Nonnull Object mock2) {
    if (mock1 == mock2 || instanceMap.isEmpty()) {
      return false;
    }

    Object mock1Equivalent = instanceMap.get(mock1);
    Object mock2Equivalent = instanceMap.get(mock2);

    if (mock1Equivalent == mock2 || mock2Equivalent == mock1) {
      return false;
    }

    if (mock1Equivalent != null && mock2Equivalent != null) {
      return true;
    }

    return instanceMapHasMocksInSeparateEntries(mock1, mock2);
  }
Ejemplo n.º 4
0
 @Override
 void markAsCoveredIfNoUnreadValuesAreLeft() {
   for (Boolean withUnreadValue : testIdsToAssignments.values()) {
     if (withUnreadValue == null) {
       covered = true;
       break;
     }
   }
 }
Ejemplo n.º 5
0
  private boolean instanceMapHasMocksInSeparateEntries(
      @Nonnull Object mock1, @Nonnull Object mock2) {
    boolean found1 = false;
    boolean found2 = false;

    for (Entry<Object, Object> entry : instanceMap.entrySet()) {
      if (!found1 && isInMapEntry(entry, mock1)) {
        found1 = true;
      }

      if (!found2 && isInMapEntry(entry, mock2)) {
        found2 = true;
      }

      if (found1 && found2) {
        return true;
      }
    }

    return false;
  }
Ejemplo n.º 6
0
 @Nullable
 Object getReplacementInstanceForMethodInvocation(
     @Nonnull Object invokedInstance, @Nonnull String methodNameAndDesc) {
   return methodNameAndDesc.charAt(0) == '<' ? null : replacementMap.get(invokedInstance);
 }
Ejemplo n.º 7
0
 void registerRead() {
   int testId = TestRun.getTestId();
   testIdsToAssignments.put(testId, null);
   readCount++;
 }
Ejemplo n.º 8
0
 void registerAssignment() {
   int testId = TestRun.getTestId();
   testIdsToAssignments.put(testId, Boolean.TRUE);
   writeCount++;
 }