package com.uxxu.konashi.lib.action;

import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattService;

import com.uxxu.konashi.lib.Konashi;

import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import java.util.UUID;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

/**
 * Created by e10dokup on 2015/09/20
 **/
public class UartBaudrateActionTest {
    private static final String TAG = UartBaudrateActionTest.class.getSimpleName();
    private final UartBaudrateActionTest self = this;

    @Mock private BluetoothGattService mService;
    @Mock private BluetoothGattCharacteristic mCharacteristic;

    private UartBaudrateAction mAction;

    private ArgumentCaptor<byte[]> mValueCaptor;

    @Before
    public void setUp() throws Exception {
        MockitoAnnotations.initMocks(this);
        mValueCaptor = ArgumentCaptor.forClass(byte[].class);
        when(mService.getCharacteristic(any(UUID.class))).thenReturn(mCharacteristic);
    }

    @Test
    public void hasValidParams_ForValidValue() throws Exception {
        mAction = new UartBaudrateAction(mService, Konashi.UART_RATE_9K6);
        assertThat(mAction.hasValidParams()).isTrue();
    }

    @Test
    public void hasValidParams_FotInvalidValue() throws Exception {
        mAction = new UartBaudrateAction(mService, 0x00);
        assertThat(mAction.hasValidParams()).isFalse();
    }

    @Test
    public void setValue() throws Exception {
        mAction = new UartBaudrateAction(mService, Konashi.UART_RATE_9K6);
        mAction.setValue();
        verify(mCharacteristic, times(1)).setValue(mValueCaptor.capture());
        assertThat(mValueCaptor.getValue()[0]).isEqualTo((byte) Konashi.UART_RATE_9K6);
    }
}
@@ -169,16 +169,58 @@
 Konashi;
+%0Aimport com.uxxu.konashi.lib.KonashiUtils;
 %0A%0Aimport
@@ -1731,24 +1731,35 @@
 oid setValue
+_SingleByte
 () throws Ex
@@ -1760,32 +1760,32 @@
 ows Exception %7B%0A
-
         mAction 
@@ -1955,27 +1955,31 @@
         
-assertThat(
+byte%5B%5D value = 
 mValueCa
@@ -1997,53 +1997,681 @@
 ue()
-%5B0%5D).isEqualTo((byte) Konashi.UART_RATE_9K6);
+;%0A        byte%5B%5D expect = KonashiUtils.int2bytes(Konashi.UART_RATE_9K6);%0A        for(int i = 0; i %3C value.length; i++) %7B%0A            assertThat(value%5Bi%5D).isEqualTo(expect%5Bi%5D);%0A        %7D%0A    %7D%0A%0A    @Test%0A    public void setValue_MultiByte() throws Exception %7B%0A        mAction = new UartBaudrateAction(mService, Konashi.UART_RATE_115K2);%0A        mAction.setValue();%0A        verify(mCharacteristic, times(1)).setValue(mValueCaptor.capture());%0A        byte%5B%5D value = mValueCaptor.getValue();%0A        byte%5B%5D expect = KonashiUtils.int2bytes(Konashi.UART_RATE_115K2);%0A        for(int i = 0; i %3C value.length; i++) %7B%0A            assertThat(value%5Bi%5D).isEqualTo(expect%5Bi%5D);%0A        %7D
 %0A   

Fix UartBaudrateTest Methods and Add setValue_MultiByte