From 79245b5d8944e70721da21a5614a6efd01137d27 Mon Sep 17 00:00:00 2001 From: Wouter Born Date: Sun, 3 Apr 2022 11:12:32 +0200 Subject: [PATCH] [networkupstools] Fix NutApiTest failing on Windows (#12564) On Windows the PrintWriter used in the NutConnector adds different line endings causing some tests to fail. Signed-off-by: Wouter Born --- .../internal/nut/NutApiTest.java | 17 ++++++++++------- .../internal/nut/var_get_commands.txt | 1 + .../internal/nut/var_list_commands.txt | 1 + 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/bundles/org.openhab.binding.networkupstools/src/test/java/org/openhab/binding/networkupstools/internal/nut/NutApiTest.java b/bundles/org.openhab.binding.networkupstools/src/test/java/org/openhab/binding/networkupstools/internal/nut/NutApiTest.java index cec903c9be5..ad6e876c56b 100644 --- a/bundles/org.openhab.binding.networkupstools/src/test/java/org/openhab/binding/networkupstools/internal/nut/NutApiTest.java +++ b/bundles/org.openhab.binding.networkupstools/src/test/java/org/openhab/binding/networkupstools/internal/nut/NutApiTest.java @@ -24,6 +24,7 @@ import java.net.URISyntaxException; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Map; +import java.util.stream.Collectors; import org.eclipse.jdt.annotation.NonNull; import org.junit.jupiter.api.BeforeEach; @@ -49,7 +50,7 @@ public class NutApiTest { @Override protected Socket newSocket() { return socket; - }; + } }; } @@ -58,9 +59,10 @@ public class NutApiTest { */ @Test public void testListVariables() throws IOException, NutException, URISyntaxException { - final String expectedCommands = new String( - Files.readAllBytes(Paths.get(getClass().getResource("var_list_commands.txt").toURI()))); - final StringBuffer actualCommands = new StringBuffer(); + final String expectedCommands = Files + .readAllLines(Paths.get(getClass().getResource("var_list_commands.txt").toURI())).stream() + .collect(Collectors.joining(System.lineSeparator())); + final StringBuilder actualCommands = new StringBuilder(); try (InputStream in = getClass().getResourceAsStream("var_list.txt"); OutputStream out = new OutputStream() { @Override public void write(int b) throws IOException { @@ -84,9 +86,10 @@ public class NutApiTest { */ @Test public void testGetVariable() throws IOException, NutException, URISyntaxException { - final String expectedCommands = new String( - Files.readAllBytes(Paths.get(getClass().getResource("var_get_commands.txt").toURI()))); - final StringBuffer actualCommands = new StringBuffer(); + final String expectedCommands = Files + .readAllLines(Paths.get(getClass().getResource("var_get_commands.txt").toURI())).stream() + .collect(Collectors.joining(System.lineSeparator())); + final StringBuilder actualCommands = new StringBuilder(); try (InputStream in = getClass().getResourceAsStream("var_get.txt"); OutputStream out = new OutputStream() { @Override public void write(int b) throws IOException { diff --git a/bundles/org.openhab.binding.networkupstools/src/test/resources/org/openhab/binding/networkupstools/internal/nut/var_get_commands.txt b/bundles/org.openhab.binding.networkupstools/src/test/resources/org/openhab/binding/networkupstools/internal/nut/var_get_commands.txt index 37a36a2dbed..37b5a4884e9 100644 --- a/bundles/org.openhab.binding.networkupstools/src/test/resources/org/openhab/binding/networkupstools/internal/nut/var_get_commands.txt +++ b/bundles/org.openhab.binding.networkupstools/src/test/resources/org/openhab/binding/networkupstools/internal/nut/var_get_commands.txt @@ -1,3 +1,4 @@ USERNAME test PASSWORD pwd GET VAR ups1 ups.status + diff --git a/bundles/org.openhab.binding.networkupstools/src/test/resources/org/openhab/binding/networkupstools/internal/nut/var_list_commands.txt b/bundles/org.openhab.binding.networkupstools/src/test/resources/org/openhab/binding/networkupstools/internal/nut/var_list_commands.txt index ca8b348978f..d2380a5e823 100644 --- a/bundles/org.openhab.binding.networkupstools/src/test/resources/org/openhab/binding/networkupstools/internal/nut/var_list_commands.txt +++ b/bundles/org.openhab.binding.networkupstools/src/test/resources/org/openhab/binding/networkupstools/internal/nut/var_list_commands.txt @@ -1,3 +1,4 @@ USERNAME test PASSWORD pwd LIST VAR ups1 +