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;
6   
7   import static java.lang.reflect.Modifier.isNative;
8   import static java.lang.reflect.Modifier.isStatic;
9   
10  import edu.umd.cs.findbugs.annotations.NonNull;
11  import edu.umd.cs.findbugs.annotations.Nullable;
12  
13  import mockit.internal.state.TestRun;
14  
15  public enum ExecutionMode {
16      Regular {
17          @Override
18          boolean isNativeMethodToBeIgnored(int access) {
19              return false;
20          }
21  
22          @Override
23          boolean isToExecuteRealImplementation(@Nullable Object instance) {
24              return instance != null && !TestRun.mockFixture().isInstanceOfMockedClass(instance);
25          }
26      },
27  
28      Partial {
29          @Override
30          boolean isToExecuteRealImplementation(@Nullable Object instance) {
31              return instance != null && !TestRun.mockFixture().isInstanceOfMockedClass(instance);
32          }
33  
34          @Override
35          boolean isWithRealImplementation(@Nullable Object instance) {
36              return instance == null || !TestRun.getExecutingTest().isInjectableMock(instance);
37          }
38  
39          @Override
40          boolean isToExecuteRealObjectOverride(@NonNull Object instance) {
41              return true;
42          }
43      },
44  
45      PerInstance {
46          @Override
47          boolean isStaticMethodToBeIgnored(int access) {
48              return isStatic(access);
49          }
50  
51          @Override
52          boolean isToExecuteRealImplementation(@Nullable Object instance) {
53              return instance == null || TestRun.getExecutingTest().isUnmockedInstance(instance);
54          }
55  
56          @Override
57          boolean isToExecuteRealObjectOverride(@NonNull Object instance) {
58              return TestRun.getExecutingTest().isUnmockedInstance(instance);
59          }
60      };
61  
62      public final boolean isMethodToBeIgnored(int access) {
63          return isStaticMethodToBeIgnored(access) || isNativeMethodToBeIgnored(access);
64      }
65  
66      boolean isStaticMethodToBeIgnored(int access) {
67          return false;
68      }
69  
70      boolean isNativeMethodToBeIgnored(int access) {
71          return isNative(access);
72      }
73  
74      boolean isToExecuteRealImplementation(@Nullable Object instance) {
75          return false;
76      }
77  
78      boolean isWithRealImplementation(@Nullable Object instance) {
79          return false;
80      }
81  
82      boolean isToExecuteRealObjectOverride(@NonNull Object instance) {
83          return false;
84      }
85  }