I find in github example how with standart Mockito make instance of final class (BluetoothGatt.class) :
...
@RunWith(RobolectricTestRunner.class)
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public class OnBoardingServiceTest {
private BluetoothGattCharacteristic characteristic;
private OnBoardingService service;
private BluetoothGattReceiver receiver = new BluetoothGattReceiver();
@Before public void initialise() {
BleDevice bleDevice = mock(BleDevice.class);
when(bleDevice.getType()).thenReturn(BleDeviceType.WunderbarMIC);
BluetoothGatt gatt = mock(BluetoothGatt.class);
...
But From the Mockito FAQ :
What are the limitations of Mockito
- Needs java 1.5+
- Cannot mock final classes
- ...
I checked it is BluetoothGatt from standard android-sdk, so it look like mock final class. Now i try build project , for sure this test working. How it can make mock final class here with core mockito? And if it code finally not working, have you any idea how make mock of final class for android instrumentation testing? (i'm already try PowerMock). Thanks