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.Type;
11  
12  import mockit.internal.expectations.MockingFilters;
13  
14  class TypeRedefinition extends BaseTypeRedefinition {
15      TypeRedefinition(@NonNull MockedType typeMetadata) {
16          super(typeMetadata);
17      }
18  
19      @Nullable
20      final InstanceFactory redefineType() {
21          // noinspection ConstantConditions
22          Class<?> classToMock = typeMetadata.getClassType();
23  
24          if (MockingFilters.isSubclassOfUnmockable(classToMock)) {
25              String mockSource = typeMetadata.field == null ? "mock parameter" : "mock field";
26              throw new IllegalArgumentException(
27                      classToMock + " is not mockable (" + mockSource + " \"" + typeMetadata.getName() + "\")");
28          }
29  
30          Type declaredType = typeMetadata.getDeclaredType();
31          return redefineType(declaredType);
32      }
33  }