2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.lametrictime.internal.api.local.dto;
15 import static org.junit.jupiter.api.Assertions.assertEquals;
17 import java.io.FileInputStream;
18 import java.io.InputStreamReader;
19 import java.nio.charset.StandardCharsets;
20 import java.util.Arrays;
22 import org.junit.jupiter.api.BeforeAll;
23 import org.junit.jupiter.api.Test;
24 import org.openhab.binding.lametrictime.internal.api.common.impl.GsonGenerator;
25 import org.openhab.binding.lametrictime.internal.api.test.AbstractTest;
27 import com.google.gson.Gson;
30 * widget updates test.
32 * @author Gregory Moyer - Initial contribution
34 public class WidgetUpdatesTest extends AbstractTest {
35 private static Gson gson;
38 public static void setUpBeforeClass() {
39 gson = GsonGenerator.create(true);
43 public void testSerialize() throws Exception {
44 WidgetUpdates widgetUpdates = new WidgetUpdates()
45 .withFrames(Arrays.asList(new Frame().withIcon("i120").withText("12°").withIndex(0)));
47 assertEquals(readJson("widget-updates.json"), gson.toJson(widgetUpdates));
51 public void testDeserialize() throws Exception {
52 try (InputStreamReader reader = new InputStreamReader(
53 new FileInputStream(getTestDataFile("widget-updates.json")), StandardCharsets.UTF_8)) {
54 WidgetUpdates widgetUpdates = gson.fromJson(reader, WidgetUpdates.class);
55 assertEquals("i120", widgetUpdates.getFrames().get(0).getIcon());
56 assertEquals("12°", widgetUpdates.getFrames().get(0).getText());
57 assertEquals(null, widgetUpdates.getFrames().get(0).getGoalData());
58 assertEquals(null, widgetUpdates.getFrames().get(0).getChartData());