• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.mockito.android.internal.creation;
2 
3 import org.mockito.internal.creation.bytebuddy.SubclassByteBuddyMockMaker;
4 import org.mockito.internal.util.ConsoleMockitoLogger;
5 import org.mockito.internal.util.Platform;
6 import org.mockito.invocation.MockHandler;
7 import org.mockito.mock.MockCreationSettings;
8 import org.mockito.plugins.MockMaker;
9 
10 import static org.mockito.internal.util.StringUtil.join;
11 
12 public class AndroidByteBuddyMockMaker implements MockMaker {
13 
14     private final MockMaker delegate;
15 
AndroidByteBuddyMockMaker()16     public AndroidByteBuddyMockMaker() {
17         if (Platform.isAndroid() || Platform.isAndroidMockMakerRequired()) {
18             delegate = new SubclassByteBuddyMockMaker(new AndroidLoadingStrategy());
19         } else {
20             new ConsoleMockitoLogger().log(join(
21                     "IMPORTANT NOTE FROM MOCKITO:",
22                     "",
23                     "You included the 'mockito-android' dependency in a non-Android environment.",
24                     "The Android mock maker was disabled. You should only include the latter in your 'androidTestCompile' configuration",
25                     "If disabling was a mistake, you can set the 'org.mockito.mock.android' property to 'true' to override this detection.",
26                     "",
27                     "Visit https://javadoc.io/page/org.mockito/mockito-core/latest/org/mockito/Mockito.html#0.1 for more information"
28             ));
29             delegate = new SubclassByteBuddyMockMaker();
30         }
31     }
32 
33     @Override
createMock(MockCreationSettings<T> settings, MockHandler handler)34     public <T> T createMock(MockCreationSettings<T> settings, MockHandler handler) {
35         return delegate.createMock(settings, handler);
36     }
37 
38     @Override
getHandler(Object mock)39     public MockHandler getHandler(Object mock) {
40         return delegate.getHandler(mock);
41     }
42 
43     @Override
resetMock(Object mock, MockHandler newHandler, MockCreationSettings settings)44     public void resetMock(Object mock, MockHandler newHandler, MockCreationSettings settings) {
45         delegate.resetMock(mock, newHandler, settings);
46     }
47 
48     @Override
isTypeMockable(Class<?> type)49     public TypeMockability isTypeMockable(Class<?> type) {
50         return delegate.isTypeMockable(type);
51     }
52 }
53