-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
188 additions
and
2 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/test/java/com/esp/espflow/mappers/EspDeviceWithTotalDevicesMapperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.esp.espflow.mappers; | ||
|
||
import com.esp.espflow.entity.EspDeviceInfo; | ||
import com.esp.espflow.entity.EspDeviceWithTotalDevices; | ||
import com.esp.espflow.mappers.provider.EspDeviceWithTotalDevicesMapperProvider; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ArgumentsSource; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class EspDeviceWithTotalDevicesMapperTest { | ||
|
||
@ParameterizedTest | ||
@ArgumentsSource(EspDeviceWithTotalDevicesMapperProvider.class) | ||
@DisplayName("Counting 3 devices and mapping to EspDeviceWithTotalDevices") | ||
void espDeviceWithTotalDevices(EspDeviceInfo actualEspDeviceInfo, | ||
EspDeviceWithTotalDevices expectedEspDeviceWithTotalDevices, | ||
long totalDevices) { | ||
|
||
var actualEspDeviceWithTotalDevices = EspDeviceWithTotalDevicesMapper.INSTANCE.espDeviceWithTotalDevices(actualEspDeviceInfo, totalDevices); | ||
|
||
assertThat(actualEspDeviceWithTotalDevices) | ||
.usingRecursiveAssertion() | ||
.isEqualTo(expectedEspDeviceWithTotalDevices); | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
src/test/java/com/esp/espflow/mappers/provider/EspDeviceWithTotalDevicesMapperProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.esp.espflow.mappers.provider; | ||
|
||
import com.esp.espflow.entity.EspDeviceInfo; | ||
import com.esp.espflow.entity.EspDeviceWithTotalDevices; | ||
import org.junit.jupiter.api.extension.ExtensionContext; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.ArgumentsProvider; | ||
|
||
import java.util.stream.Stream; | ||
|
||
public class EspDeviceWithTotalDevicesMapperProvider implements ArgumentsProvider { | ||
|
||
@Override | ||
public Stream<? extends Arguments> provideArguments(ExtensionContext extensionContext) throws Exception { | ||
|
||
long totalDevices = 3L; | ||
|
||
EspDeviceInfo actualEspDeviceInfo = EspDeviceInfo.builder() | ||
.port("/dev/ttyUSB0") | ||
.descriptivePortName("/dev/ttyUSB0") | ||
.chipType("ESP8266") | ||
.chipIs("ESP8266EX") | ||
.crystalIs("24MHz") | ||
.macAddress("2c:f4:32:10:1d:bf") | ||
.decimal("2097152") | ||
.hex("200000") | ||
.detectedFlashSize("2MB") | ||
.build(); | ||
|
||
EspDeviceWithTotalDevices expectedEspDeviceWithTotalDevices = EspDeviceWithTotalDevices.builder() | ||
.espDeviceInfo(actualEspDeviceInfo) | ||
.totalDevices(totalDevices) | ||
.build(); | ||
|
||
return Stream.of(Arguments.of(actualEspDeviceInfo, expectedEspDeviceWithTotalDevices, totalDevices)); | ||
|
||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
src/test/java/com/esp/espflow/service/EsptoolPathServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.esp.espflow.service; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.junitpioneer.jupiter.SetSystemProperty; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class EsptoolPathServiceTest { | ||
|
||
@InjectMocks | ||
private EsptoolPathService esptoolPathService; | ||
|
||
@Test | ||
@SetSystemProperty(key = "os.name", value = "window") | ||
@DisplayName("Checking temporary directory with esptool Windows") | ||
void esptoolPathWin() { | ||
|
||
assertThat(esptoolPathService.esptoolPath()) | ||
.isEqualTo("/tmp/esptool-bundle-dir/esptool-winx64/esptool.exe"); | ||
|
||
} | ||
|
||
@Test | ||
@SetSystemProperty(key = "os.name", value = "linux") | ||
@DisplayName("Checking temporary directory with esptool Linux") | ||
void esptoolPathLinux() { | ||
|
||
assertThat(esptoolPathService.esptoolPath()) | ||
.isEqualTo("/tmp/esptool-bundle-dir/esptool-linux-amd64/esptool"); | ||
|
||
} | ||
|
||
@Test | ||
@SetSystemProperty(key = "os.name", value = "mac os") | ||
@DisplayName("Checking esptool.py MacOs") | ||
void esptoolPathMac() { | ||
|
||
assertThat(esptoolPathService.esptoolPath()) | ||
.isEqualTo("esptool.py"); | ||
|
||
} | ||
|
||
@Test | ||
@SetSystemProperty(key = "os.name", value = "freebsd") | ||
@DisplayName("Checking esptool.py FreeBSD") | ||
void esptoolPathFreeBSD() { | ||
|
||
assertThat(esptoolPathService.esptoolPath()) | ||
.isEqualTo("esptool.py"); | ||
|
||
} | ||
|
||
@Test | ||
@SetSystemProperty(key = "os.name", value = "WTFOS") | ||
@DisplayName("OS is not recognized") | ||
void esptoolPathWtfOs() { | ||
|
||
assertThat(esptoolPathService.esptoolPath()) | ||
.isEqualTo(StringUtils.EMPTY); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters