View Javadoc
1   /*
2    * Copyright (c) 2006 JMockit developers
3    * This file is subject to the terms of the MIT license (see LICENSE.txt).
4    */
5   package mockit.internal.expectations.mocking;
6   
7   import edu.umd.cs.findbugs.annotations.NonNull;
8   import edu.umd.cs.findbugs.annotations.Nullable;
9   
10  import java.lang.reflect.TypeVariable;
11  import java.util.ArrayList;
12  import java.util.List;
13  
14  import mockit.internal.state.TestRun;
15  
16  public class TypeRedefinitions {
17      @NonNull
18      private final List<Class<?>> targetClasses;
19      @Nullable
20      protected CaptureOfNewInstances captureOfNewInstances;
21  
22      TypeRedefinitions() {
23          targetClasses = new ArrayList<>(2);
24      }
25  
26      final void addTargetClass(@NonNull MockedType mockedType) {
27          Class<?> targetClass = mockedType.getClassType();
28  
29          if (targetClass != TypeVariable.class) {
30              targetClasses.add(targetClass);
31          }
32      }
33  
34      @NonNull
35      public final List<Class<?>> getTargetClasses() {
36          return targetClasses;
37      }
38  
39      @Nullable
40      public final CaptureOfNewInstances getCaptureOfNewInstances() {
41          return captureOfNewInstances;
42      }
43  
44      static void registerMock(@NonNull MockedType mockedType, @NonNull Object mock) {
45          TestRun.getExecutingTest().registerMock(mockedType, mock);
46      }
47  
48      public void cleanUp() {
49          if (captureOfNewInstances != null) {
50              captureOfNewInstances.cleanUp();
51              captureOfNewInstances = null;
52          }
53      }
54  }