From 2c45d354b268d6bf6a16dcee69fe3df27e00f161 Mon Sep 17 00:00:00 2001 From: lolodomo Date: Tue, 23 Jun 2020 21:34:59 +0200 Subject: [PATCH] [lametrictime] Fix the failing tests on Windows (#7990) Fix #7979 Signed-off-by: Laurent Garnier --- .../api/local/model/WidgetUpdatesTest.java | 25 ++++++++----------- .../lametrictime/api/test/AbstractTest.java | 14 ++++------- 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/bundles/org.openhab.binding.lametrictime/src/3rdparty/test/org/openhab/binding/lametrictime/api/local/model/WidgetUpdatesTest.java b/bundles/org.openhab.binding.lametrictime/src/3rdparty/test/org/openhab/binding/lametrictime/api/local/model/WidgetUpdatesTest.java index ad43020e7a7b5..04b80e99b8630 100644 --- a/bundles/org.openhab.binding.lametrictime/src/3rdparty/test/org/openhab/binding/lametrictime/api/local/model/WidgetUpdatesTest.java +++ b/bundles/org.openhab.binding.lametrictime/src/3rdparty/test/org/openhab/binding/lametrictime/api/local/model/WidgetUpdatesTest.java @@ -17,7 +17,9 @@ import static org.junit.Assert.assertEquals; -import java.io.FileReader; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import org.junit.BeforeClass; @@ -27,31 +29,26 @@ import com.google.gson.Gson; -public class WidgetUpdatesTest extends AbstractTest -{ +public class WidgetUpdatesTest extends AbstractTest { private static Gson gson; @BeforeClass - public static void setUpBeforeClass() - { + public static void setUpBeforeClass() { gson = GsonGenerator.create(true); } @Test - public void testSerialize() throws Exception - { - WidgetUpdates widgetUpdates = new WidgetUpdates().withFrames(Arrays.asList(new Frame().withIcon("i120") - .withText("12°") - .withIndex(0))); + public void testSerialize() throws Exception { + WidgetUpdates widgetUpdates = new WidgetUpdates() + .withFrames(Arrays.asList(new Frame().withIcon("i120").withText("12°").withIndex(0))); assertEquals(readJson("widget-updates.json"), gson.toJson(widgetUpdates)); } @Test - public void testDeserialize() throws Exception - { - try (FileReader reader = new FileReader(getTestDataFile("widget-updates.json"))) - { + public void testDeserialize() throws Exception { + try (InputStreamReader reader = new InputStreamReader( + new FileInputStream(getTestDataFile("widget-updates.json")), StandardCharsets.UTF_8)) { WidgetUpdates widgetUpdates = gson.fromJson(reader, WidgetUpdates.class); assertEquals("i120", widgetUpdates.getFrames().get(0).getIcon()); assertEquals("12°", widgetUpdates.getFrames().get(0).getText()); diff --git a/bundles/org.openhab.binding.lametrictime/src/3rdparty/test/org/openhab/binding/lametrictime/api/test/AbstractTest.java b/bundles/org.openhab.binding.lametrictime/src/3rdparty/test/org/openhab/binding/lametrictime/api/test/AbstractTest.java index cbb516b38f576..18b0f814899fd 100644 --- a/bundles/org.openhab.binding.lametrictime/src/3rdparty/test/org/openhab/binding/lametrictime/api/test/AbstractTest.java +++ b/bundles/org.openhab.binding.lametrictime/src/3rdparty/test/org/openhab/binding/lametrictime/api/test/AbstractTest.java @@ -20,20 +20,16 @@ import java.nio.file.Files; import java.nio.file.Path; -public abstract class AbstractTest -{ - protected File getTestDataFile(String name) - { +public abstract class AbstractTest { + protected File getTestDataFile(String name) { return getTestDataPath(name).toFile(); } - protected Path getTestDataPath(String name) - { + protected Path getTestDataPath(String name) { return TestUtil.getTestDataPath(this.getClass(), name); } - protected String readJson(String jsonFileName) throws IOException - { - return new String(Files.readAllBytes(getTestDataPath(jsonFileName))); + protected String readJson(String jsonFileName) throws IOException { + return String.join("\n", Files.readAllLines(getTestDataPath(jsonFileName))); } }