package com.heartbeat.pin.command.system;

import com.heartbeat.pin.Pin;
import com.heartbeat.pin.command.PinCommandException;
import org.junit.Test;

public class ChipSystemPinCommandTest {
    private Pin getPin() throws PinCommandException {
        final Pin pin = new Pin("P1", Pin.Mode.IN, new ChipSystemPinCommand());
        return pin;
    }

    @Test
    public void testGetMode() throws Exception {
        try {
            ChipSystemPinCommand cmd = new ChipSystemPinCommand();
            cmd.getMode(getPin());
        } catch (PinCommandException e) {
            System.out.println(e.getMessage());
            assert e.getMessage().contains("sudo:");
        }
    }

    @Test
    public void testSetMode() throws Exception {
        try {
            ChipSystemPinCommand cmd = new ChipSystemPinCommand();
            cmd.setMode(getPin(), Pin.Mode.IN);
            assert true;
        } catch (PinCommandException e) {
            System.out.println(e.getMessage());
            assert e.getMessage().contains("sudo:");
        }
    }

    @Test
    public void testEnable() throws Exception {
        try {
            ChipSystemPinCommand cmd = new ChipSystemPinCommand();
            cmd.enable(getPin());
            assert true;
        } catch (PinCommandException e) {
            System.out.println(e.getMessage());
            assert e.getMessage().contains("sudo:");
        }
    }

    @Test
    public void testDisable() throws Exception {
        try {
            ChipSystemPinCommand cmd = new ChipSystemPinCommand();
            cmd.disable(getPin());
            assert true;
        } catch (PinCommandException e) {
            System.out.println(e.getMessage());
            assert e.getMessage().contains("sudo:");
        }
    }

    @Test
    public void testRead() throws Exception {
        try {
            ChipSystemPinCommand cmd = new ChipSystemPinCommand();
            cmd.read(getPin());
            assert true;
        } catch (PinCommandException e) {
            System.out.println(e.getMessage());
            assert e.getMessage().contains("sudo:");
        }
    }

    @Test
    public void testWrite() throws Exception {
        try {
            ChipSystemPinCommand cmd = new ChipSystemPinCommand();
            cmd.write(getPin(), false);
            assert true;
        } catch (PinCommandException e) {
            System.out.println(e.getMessage());
            assert e.getMessage().contains("sudo:");
        }
    }

    @Test
    public void testPath() throws Exception {
        try {
            ChipSystemPinCommand cmd = new ChipSystemPinCommand();
            assert cmd.path(getPin()).equals("/sys/class/gpio/gpioP1");
        } catch (PinCommandException e) {
            System.out.println(e.getMessage());
            assert e.getMessage().contains("sudo:");
        }
    }
}
@@ -141,14 +141,63 @@
 nit.
-Test;%0A
+FixMethodOrder;%0Aimport org.junit.Test;%0A%0A@FixMethodOrder
 %0Apub
@@ -622,35 +622,35 @@
          System.
-out
+err
 .println(e.getMe
@@ -995,35 +995,35 @@
          System.
-out
+err
 .println(e.getMe
@@ -1353,35 +1353,35 @@
          System.
-out
+err
 .println(e.getMe
@@ -1713,35 +1713,35 @@
          System.
-out
+err
 .println(e.getMe
@@ -2067,35 +2067,35 @@
          System.
-out
+err
 .println(e.getMe
@@ -2430,35 +2430,35 @@
          System.
-out
+err
 .println(e.getMe
@@ -2811,11 +2811,11 @@
 tem.
-out
+err
 .pri

test debug info for travis OSX build