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