[transform/scale] Make unit tests compatible with Windows (#13910)

Fix #13900

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
This commit is contained in:
lolodomo 2022-12-11 10:57:57 +01:00 committed by GitHub
parent 8c0925a63b
commit 015cc847bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,8 +13,7 @@
package org.openhab.transform.scale.internal; package org.openhab.transform.scale.internal;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.*;
import static org.mockito.ArgumentMatchers.eq;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -80,12 +79,12 @@ public class ScaleTransformServiceTest {
@Test @Test
public void testTransformByScale() throws TransformationException { public void testTransformByScale() throws TransformationException {
// need to be sure we'll have the german version // need to be sure we'll have the german version
String existingscale = "scale/humidex_de.scale"; String existingscale = "scale" + File.separator + "humidex_de.scale";
String source = "10"; String source = "10";
String transformedResponse = processor.transform(existingscale, source); String transformedResponse = processor.transform(existingscale, source);
assertEquals("nicht wesentlich", transformedResponse); assertEquals("nicht wesentlich", transformedResponse);
existingscale = "scale/limits.scale"; existingscale = "scale" + File.separator + "limits.scale";
source = "10"; source = "10";
transformedResponse = processor.transform(existingscale, source); transformedResponse = processor.transform(existingscale, source);
assertEquals("middle", transformedResponse); assertEquals("middle", transformedResponse);
@ -93,7 +92,7 @@ public class ScaleTransformServiceTest {
@Test @Test
public void testTransformByScaleLimits() throws TransformationException { public void testTransformByScaleLimits() throws TransformationException {
String existingscale = "scale/limits.scale"; String existingscale = "scale" + File.separator + "limits.scale";
// Testing upper bound opened range // Testing upper bound opened range
String source = "500"; String source = "500";
@ -106,7 +105,7 @@ public class ScaleTransformServiceTest {
assertEquals("low", transformedResponse); assertEquals("low", transformedResponse);
// Testing unfinite up and down range // Testing unfinite up and down range
existingscale = "scale/catchall.scale"; existingscale = "scale" + File.separator + "catchall.scale";
source = "-10"; source = "-10";
transformedResponse = processor.transform(existingscale, source); transformedResponse = processor.transform(existingscale, source);
assertEquals("catchall", transformedResponse); assertEquals("catchall", transformedResponse);
@ -116,7 +115,7 @@ public class ScaleTransformServiceTest {
public void testTransformByScaleUndef() throws TransformationException { public void testTransformByScaleUndef() throws TransformationException {
// check that for undefined/non numeric value we return empty string // check that for undefined/non numeric value we return empty string
// Issue #1107 // Issue #1107
String existingscale = "scale/humidex_fr.scale"; String existingscale = "scale" + File.separator + "humidex_fr.scale";
String source = "-"; String source = "-";
assertThrows(TransformationException.class, () -> processor.transform(existingscale, source)); assertThrows(TransformationException.class, () -> processor.transform(existingscale, source));
} }
@ -125,7 +124,7 @@ public class ScaleTransformServiceTest {
public void testTransformByScaleErrorInBounds() throws TransformationException { public void testTransformByScaleErrorInBounds() throws TransformationException {
// the tested file contains inputs that generate a conversion error of the bounds // the tested file contains inputs that generate a conversion error of the bounds
// of range // of range
String existingscale = "scale/erroneous.scale"; String existingscale = "scale" + File.separator + "erroneous.scale";
String source = "15"; String source = "15";
try { try {
@SuppressWarnings("unused") @SuppressWarnings("unused")
@ -139,7 +138,7 @@ public class ScaleTransformServiceTest {
@Test @Test
public void testTransformByScaleErrorInValue() throws TransformationException { public void testTransformByScaleErrorInValue() throws TransformationException {
// checks that an error is raised when trying to scale an erroneous value // checks that an error is raised when trying to scale an erroneous value
String existingscale = "scale/evaluationorder.scale"; String existingscale = "scale" + File.separator + "evaluationorder.scale";
String source = "azerty"; String source = "azerty";
assertThrows(TransformationException.class, () -> processor.transform(existingscale, source)); assertThrows(TransformationException.class, () -> processor.transform(existingscale, source));
} }
@ -147,7 +146,7 @@ public class ScaleTransformServiceTest {
@Test @Test
public void testEvaluationOrder() throws TransformationException { public void testEvaluationOrder() throws TransformationException {
// Ensures that only first matching scale as presented in the file is taken in account // Ensures that only first matching scale as presented in the file is taken in account
String evaluationOrder = "scale/evaluationorder.scale"; String evaluationOrder = "scale" + File.separator + "evaluationorder.scale";
// This value matches two lines of the scale file // This value matches two lines of the scale file
String source = "12"; String source = "12";
@ -158,7 +157,7 @@ public class ScaleTransformServiceTest {
@Test @Test
public void testTransformQuantityType() throws TransformationException { public void testTransformQuantityType() throws TransformationException {
QuantityType<Dimensionless> airQuality = new QuantityType<>("992 ppm"); QuantityType<Dimensionless> airQuality = new QuantityType<>("992 ppm");
String aqScaleFile = "scale/netatmo_aq.scale"; String aqScaleFile = "scale" + File.separator + "netatmo_aq.scale";
String expected = "Correcte (992 ppm) !"; String expected = "Correcte (992 ppm) !";
String transformedResponse = processor.transform(aqScaleFile, airQuality.toString()); String transformedResponse = processor.transform(aqScaleFile, airQuality.toString());
@ -168,7 +167,7 @@ public class ScaleTransformServiceTest {
@Test @Test
public void testCatchNonNumericValue() throws TransformationException { public void testCatchNonNumericValue() throws TransformationException {
// checks that an error is raised when trying to scale an erroneous value // checks that an error is raised when trying to scale an erroneous value
String existingscale = "scale/catchnonnumeric.scale"; String existingscale = "scale" + File.separator + "catchnonnumeric.scale";
String source = "azerty"; String source = "azerty";
String transformedResponse = processor.transform(existingscale, source); String transformedResponse = processor.transform(existingscale, source);
assertEquals("Non Numeric", transformedResponse); assertEquals("Non Numeric", transformedResponse);
@ -176,7 +175,7 @@ public class ScaleTransformServiceTest {
@Test @Test
public void testTransformAndFormat() throws TransformationException { public void testTransformAndFormat() throws TransformationException {
String existingscale = "scale/netatmo_aq.scale"; String existingscale = "scale" + File.separator + "netatmo_aq.scale";
String source = "992"; String source = "992";
String transformedResponse = processor.transform(existingscale, source); String transformedResponse = processor.transform(existingscale, source);
assertEquals("Correcte (992) !", transformedResponse); assertEquals("Correcte (992) !", transformedResponse);
@ -184,7 +183,7 @@ public class ScaleTransformServiceTest {
@Test @Test
public void testValueExceedsRange() throws TransformationException { public void testValueExceedsRange() throws TransformationException {
String existingscale = "scale/humidex.scale"; String existingscale = "scale" + File.separator + "humidex.scale";
String source = "200"; String source = "200";
assertThrows(TransformationException.class, () -> processor.transform(existingscale, source)); assertThrows(TransformationException.class, () -> processor.transform(existingscale, source));
} }