package com.uxxu.konashi.lib.action;

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

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 izumin on 9/18/15.
 */
public class PwmPinModeActionTest {

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

    private PwmPinModeAction 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_WithInvalidPin() throws Exception {
        mAction = new PwmPinModeAction(mService, 3, 1, 0x02);
        assertThat(mAction.hasValidParams()).isFalse();
    }

    @Test
    public void hasValidParams_WithInvalidMode() throws Exception {
        mAction = new PwmPinModeAction(mService, 2, 3, 0x02);
        assertThat(mAction.hasValidParams()).isFalse();
    }

    @Test
    public void hasValidParams_WithValidParams() throws Exception {
        mAction = new PwmPinModeAction(mService, 2, 1, 0x02);
        assertThat(mAction.hasValidParams()).isTrue();
    }

    @Test
    public void setValue_ToOutput() throws Exception {
        mAction = new PwmPinModeAction(mService, 2, 1, 0x01);
        mAction.setValue();
        verify(mCharacteristic, times(1)).setValue(mValueCaptor.capture());
        assertThat(mValueCaptor.getValue()[0]).isEqualTo((byte) 0x05);
    }

    @Test
    public void setValue_ToInput() throws Exception {
        mAction = new PwmPinModeAction(mService, 2, 0, 0x05);
        mAction.setValue();
        verify(mCharacteristic, times(1)).setValue(mValueCaptor.capture());
        assertThat(mValueCaptor.getValue()[0]).isEqualTo((byte) 0x01);
    }
}

@@ -133,16 +133,63 @@
 rvice;%0A%0A
+import com.uxxu.konashi.lib.KonashiErrorType;%0A%0A
 import o
@@ -1279,34 +1279,65 @@
 ion.
-hasValidParams()).isFalse(
+validate()).isEqualTo(KonashiErrorType.INVALID_PIN_NUMBER
 );%0A 
@@ -1513,34 +1513,59 @@
 ion.
-hasValidParams()).isFalse(
+validate()).isEqualTo(KonashiErrorType.INVALID_MODE
 );%0A 
@@ -1741,33 +1741,55 @@
 ion.
-hasValidParams()).isTrue(
+validate()).isEqualTo(KonashiErrorType.NO_ERROR
 );%0A 

Modify PwmPinModeActionTest TestCase