All Downloads are FREE. Search and download functionalities are using the official Maven repository.

mockit.internal.expectations.mocking.TypeRedefinitions Maven / Gradle / Ivy

Go to download

JMockit is a Java toolkit for automated developer testing. It contains APIs for the creation of the objects to be tested, for mocking dependencies, and for faking external APIs; JUnit (4 & 5) and TestNG test runners are supported. It also contains an advanced code coverage tool.

There is a newer version: 1.49
Show newest version
/*
 * Copyright (c) 2006 Rogério Liesenfeld
 * This file is subject to the terms of the MIT license (see LICENSE.txt).
 */
package mockit.internal.expectations.mocking;

import java.lang.reflect.*;
import java.util.*;
import javax.annotation.*;

import mockit.internal.state.*;

public class TypeRedefinitions
{
   @Nonnull private final List> targetClasses;
   @Nullable protected CaptureOfNewInstances captureOfNewInstances;

   protected TypeRedefinitions() { targetClasses = new ArrayList>(2); }

   protected final void addTargetClass(@Nonnull MockedType mockedType)
   {
      Class targetClass = mockedType.getClassType();

      if (targetClass != TypeVariable.class) {
         targetClasses.add(targetClass);
         addDuplicateTargetClassRepresentingMultipleCapturedSetsOfClasses(mockedType, targetClass);
      }
   }

   private void addDuplicateTargetClassRepresentingMultipleCapturedSetsOfClasses(
      @Nonnull MockedType mockedType, @Nonnull Class targetClass)
   {
      int maxInstancesToCapture = mockedType.getMaxInstancesToCapture();

      if (maxInstancesToCapture > 0 && maxInstancesToCapture < Integer.MAX_VALUE) {
         targetClasses.add(targetClass);
      }
   }

   @Nonnull public final List> getTargetClasses() { return targetClasses; }
   @Nullable public final CaptureOfNewInstances getCaptureOfNewInstances() { return captureOfNewInstances; }

   protected static void registerMock(@Nonnull MockedType mockedType, @Nonnull Object mock)
   {
      TestRun.getExecutingTest().registerMock(mockedType, mock);
   }

   public void cleanUp()
   {
      if (captureOfNewInstances != null) {
         captureOfNewInstances.cleanUp();
         captureOfNewInstances = null;
      }
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy