2 * Copyright (c) 2010-2024 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.FileReader;
18 import java.util.HashMap;
20 import org.junit.jupiter.api.BeforeAll;
21 import org.junit.jupiter.api.Test;
22 import org.openhab.binding.lametrictime.internal.api.common.impl.GsonGenerator;
23 import org.openhab.binding.lametrictime.internal.api.test.AbstractTest;
25 import com.google.gson.Gson;
26 import com.google.gson.JsonPrimitive;
31 * @author Gregory Moyer - Initial contribution
33 public class WidgetTest extends AbstractTest {
34 private static Gson gson;
37 public static void setUpBeforeClass() {
38 gson = GsonGenerator.create(true);
42 @SuppressWarnings("serial")
43 public void testSerialize() throws Exception {
44 Widget widget = new Widget().withPackageName("com.lametric.radio").withIndex(Integer.valueOf(-1))
45 .withSettings(new HashMap<String, JsonPrimitive>() {
47 put("_title", new JsonPrimitive("Radio"));
50 assertEquals(readJson("widget.json"), gson.toJson(widget));
54 @SuppressWarnings("serial")
55 public void testDeserialize() throws Exception {
56 try (FileReader reader = new FileReader(getTestDataFile("widget.json"))) {
57 Widget widget = gson.fromJson(reader, Widget.class);
58 assertEquals("com.lametric.radio", widget.getPackageName());
59 assertEquals(Integer.valueOf(-1), widget.getIndex());
60 assertEquals(new HashMap<String, JsonPrimitive>() {
62 put("_title", new JsonPrimitive("Radio"));
64 }, widget.getSettings());