Skip to content

Commit

Permalink
🚧 #70
Browse files Browse the repository at this point in the history
  • Loading branch information
rucko24 committed Oct 25, 2024
1 parent bcdd31e commit 594c188
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {

Expand Down Expand Up @@ -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) {

Expand Down Expand Up @@ -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) {

Expand All @@ -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) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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")
Expand Down Expand Up @@ -123,7 +123,7 @@ void showEsptoolVersion() {
}

@ParameterizedTest
@ArgumentsSource(EsptoolServiceRawFlashIdFromPortArgumentProvider.class)
@ArgumentsSource(EsptoolServiceRawFlashIdFromPortArgumentsProvider.class)
@DisplayName("read raw each String from this inputStream")
void readRawFlashIdFromPort(Flux<String> actualLines, String expetedFirtsLine,
String expetedSecondLine, String expetedThirdLine) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<? extends Arguments> provideArguments(ExtensionContext extensionContext) throws Exception {
Expand Down Expand Up @@ -43,14 +47,20 @@ public Stream<? extends Arguments> 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};

Expand All @@ -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};

Expand All @@ -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};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import java.util.stream.Stream;

public class EsptoolServiceArgumentProvider implements ArgumentsProvider {
public class EsptoolServiceArgumentsProvider implements ArgumentsProvider {

@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext extensionContext) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import java.util.stream.Stream;

public class EsptoolServiceNoFlashSizeArgumentProvider implements ArgumentsProvider {
public class EsptoolServiceNoFlashSizeArgumentsProvider implements ArgumentsProvider {

@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext extensionContext) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import java.util.stream.Stream;

public class EsptoolServiceRawFlashIdFromPortArgumentProvider implements ArgumentsProvider {
public class EsptoolServiceRawFlashIdFromPortArgumentsProvider implements ArgumentsProvider {

@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext extensionContext) throws Exception {
Expand Down

0 comments on commit 594c188

Please sign in to comment.