]> git.basschouten.com Git - openhab-addons.git/blob
438c05e01fd7b1752234f55645924bd6642b00f8
[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.sleepiq.api.model;
14
15 import static org.junit.jupiter.api.Assertions.assertEquals;
16
17 import java.io.FileReader;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.junit.jupiter.api.Test;
21 import org.openhab.binding.sleepiq.api.test.AbstractTest;
22 import org.openhab.binding.sleepiq.internal.api.dto.PauseModeResponse;
23 import org.openhab.binding.sleepiq.internal.api.impl.GsonGenerator;
24
25 import com.google.gson.Gson;
26
27 /**
28  * The {@link PauseModeTest} tests deserialization of a pause mode object.
29  *
30  * @author Mark Hilbush - Initial contribution
31  */
32 @NonNullByDefault
33 public class PauseModeTest extends AbstractTest {
34     private static Gson gson = GsonGenerator.create(true);
35
36     @Test
37     public void testSerializeAllFields() throws Exception {
38         PauseModeResponse pauseMode = new PauseModeResponse().withAccountId("-8888888888888888888")
39                 .withBedId("-9999999999999999999").withPauseMode("off");
40         assertEquals(readJson("pause-mode.json"), gson.toJson(pauseMode));
41     }
42
43     @Test
44     public void testDeserializeAllFields() throws Exception {
45         try (FileReader reader = new FileReader(getTestDataFile("pause-mode.json"))) {
46             PauseModeResponse pauseMode = gson.fromJson(reader, PauseModeResponse.class);
47             assertEquals("-8888888888888888888", pauseMode.getAccountId());
48             assertEquals("-9999999999999999999", pauseMode.getBedId());
49             assertEquals("off", pauseMode.getPauseMode());
50         }
51     }
52 }