]> git.basschouten.com Git - openhab-addons.git/blob
8c510540d1a68c357f5f82d9dec491a84b57a11c
[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.*;
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.BedSideStatus;
23 import org.openhab.binding.sleepiq.internal.api.dto.TimeSince;
24 import org.openhab.binding.sleepiq.internal.api.impl.GsonGenerator;
25
26 import com.google.gson.Gson;
27
28 /**
29  * The {@link BedSideStatusTest} tests deserialization of a bed side status object.
30  *
31  * @author Gregory Moyer - Initial contribution
32  */
33 @NonNullByDefault
34 public class BedSideStatusTest extends AbstractTest {
35     private static Gson gson = GsonGenerator.create(true);
36
37     @Test
38     public void testSerializeAllFields() throws Exception {
39         BedSideStatus bedSideStatus = new BedSideStatus().withAlertDetailedMessage("No Alert").withAlertId(0L)
40                 .withInBed(false).withLastLink(new TimeSince().withDuration(3, 5, 4, 38)).withPressure(573)
41                 .withSleepNumber(55);
42         assertEquals(readJson("bed-side-status.json"), gson.toJson(bedSideStatus));
43     }
44
45     @Test
46     public void testDeserializeAllFields() throws Exception {
47         try (FileReader reader = new FileReader(getTestDataFile("bed-side-status.json"))) {
48             BedSideStatus bedSideStatus = gson.fromJson(reader, BedSideStatus.class);
49             assertEquals("No Alert", bedSideStatus.getAlertDetailedMessage());
50             assertEquals(Long.valueOf(0L), bedSideStatus.getAlertId());
51             assertFalse(bedSideStatus.isInBed());
52             assertEquals(new TimeSince().withDuration(3, 5, 4, 38), bedSideStatus.getLastLink());
53             assertEquals(Integer.valueOf(573), bedSideStatus.getPressure());
54             assertEquals(Integer.valueOf(55), bedSideStatus.getSleepNumber());
55         }
56     }
57 }