2 * Copyright 2017-2018 Gregory Moyer and contributors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.openhab.binding.lametrictime.api.local.model;
18 import static org.junit.jupiter.api.Assertions.*;
20 import java.io.FileReader;
21 import java.util.Arrays;
23 import org.junit.jupiter.api.BeforeAll;
24 import org.junit.jupiter.api.Test;
25 import org.openhab.binding.lametrictime.api.common.impl.GsonGenerator;
26 import org.openhab.binding.lametrictime.api.test.AbstractTest;
28 import com.google.gson.Gson;
30 public class FrameTest extends AbstractTest
32 private static Gson gson;
35 public static void setUpBeforeClass()
37 gson = GsonGenerator.create(true);
41 public void testSerializeSimple() throws Exception
43 Frame frame = new Frame().withIcon("i87").withText("Hello world!");
44 assertEquals(readJson("frame-simple.json"), gson.toJson(frame));
48 public void testSerializeGoal() throws Exception
50 Frame frame = new Frame().withIcon("i120").withGoalData(new GoalData());
51 assertEquals(readJson("frame-goal.json"), gson.toJson(frame));
55 public void testSerializeChart() throws Exception
57 Frame frame = new Frame().withChartData(Arrays.asList(1, 2, 3, 4, 5, 6, 7));
58 assertEquals(readJson("frame-chart.json"), gson.toJson(frame));
62 public void testDeserializeSimple() throws Exception
64 try (FileReader reader = new FileReader(getTestDataFile("frame-simple.json")))
66 Frame frame = gson.fromJson(reader, Frame.class);
67 assertEquals("i87", frame.getIcon());
68 assertEquals("Hello world!", frame.getText());
69 assertEquals(null, frame.getGoalData());
70 assertEquals(null, frame.getChartData());
75 public void testDeserializeGoal() throws Exception
77 try (FileReader reader = new FileReader(getTestDataFile("frame-goal.json")))
79 Frame frame = gson.fromJson(reader, Frame.class);
80 assertEquals("i120", frame.getIcon());
81 assertEquals(new GoalData(), frame.getGoalData());
86 public void testDeserializeChart() throws Exception
88 try (FileReader reader = new FileReader(getTestDataFile("frame-chart.json")))
90 Frame frame = gson.fromJson(reader, Frame.class);
91 assertEquals(Arrays.asList(1, 2, 3, 4, 5, 6, 7), frame.getChartData());