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