@Test
public void autoconnectTest() throws Exception {

    peripheral.autoConnect();
    ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
    ArgumentCaptor<BluetoothGattCallback> captor = ArgumentCaptor.forClass(BluetoothGattCallback.class);
    ArgumentCaptor<Boolean> autoConnectCaptor = ArgumentCaptor.forClass(Boolean.class);
    verify(device).connectGatt(any(Context.class), autoConnectCaptor.capture(), captor.capture(), anyInt());
    boolean autoconnect = autoConnectCaptor.getValue();
    assertTrue(autoconnect);
    BluetoothGattCallback callback = captor.getValue();
    callback.onConnectionStateChange(gatt, GATT_SUCCESS, STATE_CONNECTED);
    assertEquals(STATE_CONNECTED,  peripheral.getState());
}