Skip to content

Commit

Permalink
[lametrictime] Fix the failing tests on Windows (#7990)
Browse files Browse the repository at this point in the history
Fix #7979

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
  • Loading branch information
lolodomo authored Jun 23, 2020
1 parent bcab859 commit 2c45d35
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
}

0 comments on commit 2c45d35

Please sign in to comment.