diff --git a/src/test/java/com/esp/espflow/data/service/ComPortServiceTest.java b/src/test/java/com/esp/espflow/data/service/ComPortServiceTest.java index 358c0e0..565d327 100644 --- a/src/test/java/com/esp/espflow/data/service/ComPortServiceTest.java +++ b/src/test/java/com/esp/espflow/data/service/ComPortServiceTest.java @@ -1,6 +1,6 @@ package com.esp.espflow.data.service; -import com.esp.espflow.data.service.provider.ComPortServiceArgumentProvider; +import com.esp.espflow.data.service.provider.ComPortServiceArgumentsProvider; import com.fazecast.jSerialComm.SerialPort; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.MethodOrderer; @@ -32,7 +32,7 @@ class ComPortServiceTest { @Order(1) @ParameterizedTest - @ArgumentsSource(ComPortServiceArgumentProvider.class) + @ArgumentsSource(ComPortServiceArgumentsProvider.class) @DisplayName("We obtain the list of serial ports, of the type comPort@friendlyName, " + "the portDescription is equal to the comPort") void getPortsListWithFriendlyName(SerialPort[] actualSerialPorts, String expectedDevUsb1, String expectedDevUsb2) { @@ -53,7 +53,7 @@ void getPortsListWithFriendlyName(SerialPort[] actualSerialPorts, String expecte @Order(2) @ParameterizedTest - @ArgumentsSource(ComPortServiceArgumentProvider.class) + @ArgumentsSource(ComPortServiceArgumentsProvider.class) @DisplayName("Serial port count, for this example there are 2 ports") void countAllDevices(SerialPort[] actualSerialPorts, String expectedDevUsb1, String expectedDevUsb2) { @@ -85,7 +85,7 @@ void countAllDevicesReturn0() { @Order(4) @ParameterizedTest - @ArgumentsSource(ComPortServiceArgumentProvider.class) + @ArgumentsSource(ComPortServiceArgumentsProvider.class) @DisplayName("We verify that you only have the name of the ports before the @, for linux") void getOnlyPortsList(SerialPort[] actualSerialPorts, String expectedDevUsb1, String expectedDevUsb2) { @@ -120,7 +120,7 @@ void emptyPortList() { @Order(6) @ParameterizedTest - @ArgumentsSource(ComPortServiceArgumentProvider.class) + @ArgumentsSource(ComPortServiceArgumentsProvider.class) @DisplayName("One of the serial ports is null") void oneSerialPortIsNull(SerialPort[] actualSerialPorts, String expectedDevUsb1, String expectedDevUsb2) { @@ -141,7 +141,7 @@ void oneSerialPortIsNull(SerialPort[] actualSerialPorts, String expectedDevUsb1, @Order(7) @SetSystemProperty(key = "os.name", value = "window") @ParameterizedTest - @ArgumentsSource(ComPortServiceArgumentProvider.class) + @ArgumentsSource(ComPortServiceArgumentsProvider.class) @DisplayName("We simulate window to replace the characters of the port") void replaceCharacters(SerialPort[] actualSerialPorts, String expectedDevUsb1, String expectedDevUsb2) { diff --git a/src/test/java/com/esp/espflow/data/service/EsptoolServiceTest.java b/src/test/java/com/esp/espflow/data/service/EsptoolServiceTest.java index 51d1cab..0b96e25 100644 --- a/src/test/java/com/esp/espflow/data/service/EsptoolServiceTest.java +++ b/src/test/java/com/esp/espflow/data/service/EsptoolServiceTest.java @@ -2,9 +2,9 @@ import com.esp.espflow.data.entity.EspDeviceInfo; import com.esp.espflow.data.enums.BaudRates; -import com.esp.espflow.data.service.provider.EsptoolServiceArgumentProvider; -import com.esp.espflow.data.service.provider.EsptoolServiceNoFlashSizeArgumentProvider; -import com.esp.espflow.data.service.provider.EsptoolServiceRawFlashIdFromPortArgumentProvider; +import com.esp.espflow.data.service.provider.EsptoolServiceArgumentsProvider; +import com.esp.espflow.data.service.provider.EsptoolServiceNoFlashSizeArgumentsProvider; +import com.esp.espflow.data.service.provider.EsptoolServiceRawFlashIdFromPortArgumentsProvider; import com.esp.espflow.data.util.GetOsName; import lombok.SneakyThrows; import lombok.extern.log4j.Log4j2; @@ -55,7 +55,7 @@ class EsptoolServiceTest { private EsptoolPathService esptoolPathService; @ParameterizedTest - @ArgumentsSource(EsptoolServiceArgumentProvider.class) + @ArgumentsSource(EsptoolServiceArgumentsProvider.class) @SneakyThrows @DisplayName("esptool.py --port /dev/ttyACM0 --baud 115200 flash_id, the port will come with the friendlyName") void readFlashIdWithCustomPort(String portForInputStream, @@ -78,7 +78,7 @@ void readFlashIdWithCustomPort(String portForInputStream, @ParameterizedTest - @ArgumentsSource(EsptoolServiceNoFlashSizeArgumentProvider.class) + @ArgumentsSource(EsptoolServiceNoFlashSizeArgumentsProvider.class) @SneakyThrows @DisplayName("esptool.py --port /dev/ttyACM0 --baud 115200 flash_id, " + "indicates that the response of the console is incomplete and the microcontroller reading was not correct") @@ -123,7 +123,7 @@ void showEsptoolVersion() { } @ParameterizedTest - @ArgumentsSource(EsptoolServiceRawFlashIdFromPortArgumentProvider.class) + @ArgumentsSource(EsptoolServiceRawFlashIdFromPortArgumentsProvider.class) @DisplayName("read raw each String from this inputStream") void readRawFlashIdFromPort(Flux actualLines, String expetedFirtsLine, String expetedSecondLine, String expetedThirdLine) { diff --git a/src/test/java/com/esp/espflow/data/service/provider/ComPortServiceArgumentProvider.java b/src/test/java/com/esp/espflow/data/service/provider/ComPortServiceArgumentsProvider.java similarity index 60% rename from src/test/java/com/esp/espflow/data/service/provider/ComPortServiceArgumentProvider.java rename to src/test/java/com/esp/espflow/data/service/provider/ComPortServiceArgumentsProvider.java index d1d21b1..fd63026 100644 --- a/src/test/java/com/esp/espflow/data/service/provider/ComPortServiceArgumentProvider.java +++ b/src/test/java/com/esp/espflow/data/service/provider/ComPortServiceArgumentsProvider.java @@ -9,7 +9,11 @@ import java.util.stream.Stream; -public class ComPortServiceArgumentProvider implements ArgumentsProvider { +public class ComPortServiceArgumentsProvider implements ArgumentsProvider { + + private static final String COM_PORT = "comPort"; + private static final String PORT_DESCRIPTION = "portDescription"; + private static final String FRIENDLY_NAME = "friendlyName"; @Override public Stream provideArguments(ExtensionContext extensionContext) throws Exception { @@ -43,14 +47,20 @@ public Stream provideArguments(ExtensionContext extensionCo private Arguments windowsSerialPorts() { final SerialPort serialPort1 = SerialPort.getCommPort("COM1"); - ReflectionTestUtils.setField(serialPort1, "comPort", "COM2"); - ReflectionTestUtils.setField(serialPort1, "portDescription", "COM2"); - ReflectionTestUtils.setField(serialPort1, "friendlyName", "Silicon Labs CP210x USB to UART Bridge (COM2)"); + /* + * Set custom port + */ + ReflectionTestUtils.setField(serialPort1, COM_PORT, "COM2"); + ReflectionTestUtils.setField(serialPort1, PORT_DESCRIPTION, "COM2"); + ReflectionTestUtils.setField(serialPort1, FRIENDLY_NAME, "Silicon Labs CP210x USB to UART Bridge (COM2)"); final SerialPort serialPort2 = SerialPort.getCommPort("COM1"); - ReflectionTestUtils.setField(serialPort1, "comPort", "COM3"); - ReflectionTestUtils.setField(serialPort1, "portDescription", "COM3"); - ReflectionTestUtils.setField(serialPort1, "friendlyName", "Silicon Labs CP210x USB to UART Bridge (COM3)"); + /* + * Set custom port + */ + ReflectionTestUtils.setField(serialPort2, COM_PORT, "COM3"); + ReflectionTestUtils.setField(serialPort2, PORT_DESCRIPTION, "COM3"); + ReflectionTestUtils.setField(serialPort2, FRIENDLY_NAME, "Silicon Labs CP210x USB to UART Bridge (COM3)"); final SerialPort[] actualSerialPorts = new SerialPort[]{serialPort1, serialPort2}; @@ -63,20 +73,20 @@ private Arguments windowsSerialPorts() { private Arguments linuxSerialPorts() { final SerialPort serialPort1 = SerialPort.getCommPort("/dev/ttyUSB0"); - /** + /* * Set custom port */ - ReflectionTestUtils.setField(serialPort1, "comPort", "/dev/ttyUSB1"); - ReflectionTestUtils.setField(serialPort1, "portDescription", "/dev/ttyUSB1"); - ReflectionTestUtils.setField(serialPort1, "friendlyName", "Serial-1"); + ReflectionTestUtils.setField(serialPort1, COM_PORT, "/dev/ttyUSB1"); + ReflectionTestUtils.setField(serialPort1, PORT_DESCRIPTION, "/dev/ttyUSB1"); + ReflectionTestUtils.setField(serialPort1, FRIENDLY_NAME, "Serial-1"); final SerialPort serialPort2 = SerialPort.getCommPort("/dev/ttyUSB0"); - /** + /* * Set custom port */ - ReflectionTestUtils.setField(serialPort2, "comPort", "/dev/ttyUSB2"); - ReflectionTestUtils.setField(serialPort2, "portDescription", "/dev/ttyUSB2"); - ReflectionTestUtils.setField(serialPort2, "friendlyName", "Serial-2"); + ReflectionTestUtils.setField(serialPort2, COM_PORT, "/dev/ttyUSB2"); + ReflectionTestUtils.setField(serialPort2, PORT_DESCRIPTION, "/dev/ttyUSB2"); + ReflectionTestUtils.setField(serialPort2, FRIENDLY_NAME, "Serial-2"); final SerialPort[] actualSerialPorts = new SerialPort[]{serialPort1, serialPort2}; @@ -91,20 +101,20 @@ private Arguments linuxSerialPorts() { private Arguments freeBsdSerialPorts() { final SerialPort serialPort1 = SerialPort.getCommPort("/dev/cuaU1"); - /** + /* * Set custom port */ - ReflectionTestUtils.setField(serialPort1, "comPort", "/dev/cuaU1"); - ReflectionTestUtils.setField(serialPort1, "portDescription", "/dev/cuaU1"); - ReflectionTestUtils.setField(serialPort1, "friendlyName", "Serial-1"); + ReflectionTestUtils.setField(serialPort1, COM_PORT, "/dev/cuaU1"); + ReflectionTestUtils.setField(serialPort1, PORT_DESCRIPTION, "/dev/cuaU1"); + ReflectionTestUtils.setField(serialPort1, FRIENDLY_NAME, "Serial-1"); final SerialPort serialPort2 = SerialPort.getCommPort("/dev/cuaU0"); - /** + /* * Set custom port */ - ReflectionTestUtils.setField(serialPort2, "comPort", "/dev/cuaU2"); - ReflectionTestUtils.setField(serialPort2, "portDescription", "/dev/cuaU2"); - ReflectionTestUtils.setField(serialPort2, "friendlyName", "Serial-2"); + ReflectionTestUtils.setField(serialPort2, COM_PORT, "/dev/cuaU2"); + ReflectionTestUtils.setField(serialPort2, PORT_DESCRIPTION, "/dev/cuaU2"); + ReflectionTestUtils.setField(serialPort2, FRIENDLY_NAME, "Serial-2"); final SerialPort[] actualSerialPorts = new SerialPort[]{serialPort1, serialPort2}; diff --git a/src/test/java/com/esp/espflow/data/service/provider/EsptoolServiceArgumentProvider.java b/src/test/java/com/esp/espflow/data/service/provider/EsptoolServiceArgumentsProvider.java similarity index 94% rename from src/test/java/com/esp/espflow/data/service/provider/EsptoolServiceArgumentProvider.java rename to src/test/java/com/esp/espflow/data/service/provider/EsptoolServiceArgumentsProvider.java index 9810e04..464fcc8 100644 --- a/src/test/java/com/esp/espflow/data/service/provider/EsptoolServiceArgumentProvider.java +++ b/src/test/java/com/esp/espflow/data/service/provider/EsptoolServiceArgumentsProvider.java @@ -8,7 +8,7 @@ import java.util.stream.Stream; -public class EsptoolServiceArgumentProvider implements ArgumentsProvider { +public class EsptoolServiceArgumentsProvider implements ArgumentsProvider { @Override public Stream provideArguments(ExtensionContext extensionContext) throws Exception { diff --git a/src/test/java/com/esp/espflow/data/service/provider/EsptoolServiceNoFlashSizeArgumentProvider.java b/src/test/java/com/esp/espflow/data/service/provider/EsptoolServiceNoFlashSizeArgumentsProvider.java similarity index 92% rename from src/test/java/com/esp/espflow/data/service/provider/EsptoolServiceNoFlashSizeArgumentProvider.java rename to src/test/java/com/esp/espflow/data/service/provider/EsptoolServiceNoFlashSizeArgumentsProvider.java index ca73cde..b62bff7 100644 --- a/src/test/java/com/esp/espflow/data/service/provider/EsptoolServiceNoFlashSizeArgumentProvider.java +++ b/src/test/java/com/esp/espflow/data/service/provider/EsptoolServiceNoFlashSizeArgumentsProvider.java @@ -8,7 +8,7 @@ import java.util.stream.Stream; -public class EsptoolServiceNoFlashSizeArgumentProvider implements ArgumentsProvider { +public class EsptoolServiceNoFlashSizeArgumentsProvider implements ArgumentsProvider { @Override public Stream provideArguments(ExtensionContext extensionContext) throws Exception { diff --git a/src/test/java/com/esp/espflow/data/service/provider/EsptoolServiceRawFlashIdFromPortArgumentProvider.java b/src/test/java/com/esp/espflow/data/service/provider/EsptoolServiceRawFlashIdFromPortArgumentsProvider.java similarity index 91% rename from src/test/java/com/esp/espflow/data/service/provider/EsptoolServiceRawFlashIdFromPortArgumentProvider.java rename to src/test/java/com/esp/espflow/data/service/provider/EsptoolServiceRawFlashIdFromPortArgumentsProvider.java index ce2666b..ac95ef7 100644 --- a/src/test/java/com/esp/espflow/data/service/provider/EsptoolServiceRawFlashIdFromPortArgumentProvider.java +++ b/src/test/java/com/esp/espflow/data/service/provider/EsptoolServiceRawFlashIdFromPortArgumentsProvider.java @@ -7,7 +7,7 @@ import java.util.stream.Stream; -public class EsptoolServiceRawFlashIdFromPortArgumentProvider implements ArgumentsProvider { +public class EsptoolServiceRawFlashIdFromPortArgumentsProvider implements ArgumentsProvider { @Override public Stream provideArguments(ExtensionContext extensionContext) throws Exception {