/*                                                                      *\
**                    SICU Stress Measurement System                    **
**                      Project P04  |  C380 Team A                     **
**          EBME 380: Biomedical Engineering Design Experience          **
**                    Case Western Reserve University                   **
**                          2016 Fall Semester                          **
\*                                                                      */

package edu.cwru.sicu_sms.util;

import org.junit.jupiter.api.*;

import java.util.Arrays;

import static org.junit.jupiter.api.Assertions.*;

/**
 * Test class for {@link EKGSerialPort}.
 *
 * @since December 14, 2016
 * @author Ted Frohlich <ttf10@case.edu>
 * @author Abby Walker <amw138@case.edu>
 */
class EKGSerialPortTest {
    
    private static long READ_DURATION = (long) 3e9;  // 3 seconds, expressed in nanoseconds
    
    private EKGSerialPort serialPort;
    
    @BeforeEach
    void openPort() {
        serialPort = new EKGSerialPort();
        serialPort.openPort();
    }
    
    @Test
    void readData() {
        byte[] data;
        
        long startTime = System.nanoTime();
        do {
            data = serialPort.readData();
            
            if (data != null && data.length > 0) {
                System.out.println(Arrays.toString(data));
            }
        } while (System.nanoTime() - startTime < READ_DURATION);
    }
    
    @AfterEach
    void closePort() {
        serialPort.closePort();
    }
    
}
@@ -552,16 +552,45 @@
 .util;%0A%0A
+import jssc.SerialPortEvent;%0A
 import o
@@ -1049,24 +1049,21 @@
    void 
-openPort
+setUp
 () %7B%0A   
@@ -1095,24 +1095,160 @@
 SerialPort()
+ %7B%0A            @Override%0A            public void serialEvent(SerialPortEvent serialPortEvent) %7B%0A                %0A            %7D%0A        %7D
 ;%0A        se
@@ -1284,20 +1284,25 @@
   %0A    @
-Test
+AfterEach
 %0A    voi
@@ -1303,24 +1303,105 @@
    void 
-readData
+tearDown() %7B%0A        serialPort.closePort();%0A    %7D%0A    %0A    @Test%0A    void testInTerminal
 () %7B%0A   
@@ -1743,86 +1743,5 @@
    %0A
-    @AfterEach%0A    void closePort() %7B%0A        serialPort.closePort();%0A    %7D%0A    %0A
 %7D

Revise and add further framework