]> git.basschouten.com Git - openhab-addons.git/blob
e8a752206a5645932bef8f879b3d6db82ef28a89
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.lametrictime.internal.api.local.dto;
14
15 import static org.junit.jupiter.api.Assertions.assertEquals;
16
17 import java.io.FileReader;
18
19 import org.junit.jupiter.api.BeforeAll;
20 import org.junit.jupiter.api.Test;
21 import org.openhab.binding.lametrictime.internal.api.common.impl.GsonGenerator;
22 import org.openhab.binding.lametrictime.internal.api.test.AbstractTest;
23
24 import com.google.gson.Gson;
25
26 /**
27  * goal data test.
28  *
29  * @author Gregory Moyer - Initial contribution
30  */
31 public class GoalDataTest extends AbstractTest {
32     private static Gson gson;
33
34     @BeforeAll
35     public static void setUpBeforeClass() {
36         gson = GsonGenerator.create(true);
37     }
38
39     @Test
40     public void testSerializeSimple() throws Exception {
41         GoalData goalData = new GoalData().withStart(0).withEnd(100).withCurrent(50).withUnit("%");
42         assertEquals(readJson("goal-data.json"), gson.toJson(goalData));
43     }
44
45     @Test
46     public void testDeserializeSimple() throws Exception {
47         try (FileReader reader = new FileReader(getTestDataFile("goal-data.json"))) {
48             GoalData goalData = gson.fromJson(reader, GoalData.class);
49             assertEquals(Integer.valueOf(0), goalData.getStart());
50             assertEquals(Integer.valueOf(100), goalData.getEnd());
51             assertEquals(Integer.valueOf(50), goalData.getCurrent());
52             assertEquals("%", goalData.getUnit());
53         }
54     }
55 }