@@ -0,0 +1,2532 @@
+package info.izumin.android.bletia;%0A%0Aimport android.bluetooth.BluetoothGatt;%0Aimport android.bluetooth.BluetoothGattCharacteristic;%0Aimport android.content.Context;%0Aimport android.support.test.runner.AndroidJUnit4;%0Aimport android.test.AndroidTestCase;%0A%0Aimport org.jdeferred.DoneCallback;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.mockito.Mock;%0Aimport org.mockito.MockitoAnnotations;%0Aimport org.mockito.internal.util.reflection.Whitebox;%0A%0Aimport java.util.UUID;%0Aimport java.util.concurrent.CountDownLatch;%0Aimport java.util.concurrent.TimeUnit;%0A%0Aimport info.izumin.android.bletia.wrapper.BluetoothGattWrapper;%0A%0Aimport static org.assertj.core.api.Assertions.assertThat;%0Aimport static org.mockito.Mockito.when;%0A%0A/**%0A * Created by izumin on 9/8/15.%0A */%0A@RunWith(AndroidJUnit4.class)%0Apublic class BletiaTest extends AndroidTestCase %7B%0A%0A    @Mock private BluetoothGattCharacteristic mCharacteristic;%0A    @Mock private BluetoothGattWrapper mBluetoothGattWrapper;%0A%0A    private BluetoothGattCallbackHandler mCallbackHandler;%0A    private Bletia mBletia;%0A    private Context mContext;%0A%0A    @Before%0A    public void setUp() throws Exception %7B%0A        MockitoAnnotations.initMocks(this);%0A        mContext = getContext();%0A        mBletia = new Bletia(mContext);%0A        mCallbackHandler = new BluetoothGattCallbackHandler();%0A        Whitebox.setInternalState(mBletia, %22mCallbackHandler%22, mCallbackHandler);%0A    %7D%0A%0A    @Test%0A    public void writeCharacteristicSuccessfully() throws Exception %7B%0A        Whitebox.setInternalState(mBletia, %22mGattWrapper%22, mBluetoothGattWrapper);%0A        final CountDownLatch latch = new CountDownLatch(1);%0A        when(mBluetoothGattWrapper.writeCharacteristic(mCharacteristic)).thenReturn(true);%0A        when(mCharacteristic.getUuid()).thenReturn(UUID.randomUUID());%0A%0A        new Thread(new Runnable() %7B%0A            @Override%0A            public void run() %7B%0A                mBletia.writeCharacteristic(mCharacteristic).then(new DoneCallback%3CBluetoothGattCharacteristic%3E() %7B%0A                    @Override%0A                    public void onDone(BluetoothGattCharacteristic result) %7B%0A                        latch.countDown();%0A                    %7D%0A                %7D);%0A            %7D%0A        %7D).start();%0A%0A        Thread.sleep(1000);%0A        mCallbackHandler.onCharacteristicWrite(%0A                mBluetoothGattWrapper, mCharacteristic, BluetoothGatt.GATT_SUCCESS);%0A%0A        boolean res = latch.await(1000, TimeUnit.MILLISECONDS);%0A%0A        assertThat(res).isTrue();%0A    %7D%0A%7D%0A

Implement test for Bletia#writeCharacteristic()