2 * Copyright (c) 2010-2023 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.sleepiq.api.model;
15 import static org.junit.jupiter.api.Assertions.*;
17 import java.io.FileReader;
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.BedStatus;
24 import org.openhab.binding.sleepiq.internal.api.impl.GsonGenerator;
26 import com.google.gson.Gson;
29 * The {@link BedStatusText} tests deserialization of a bed status object.
31 * @author Gregory Moyer - Initial contribution
34 public class BedStatusTest extends AbstractTest {
35 private static Gson gson = GsonGenerator.create(true);
38 public void testSerializeAllFields() throws Exception {
39 BedStatus bedStatus = new BedStatus().withBedId("-9999999999999999999")
40 .withLeftSide(new BedSideStatus().withInBed(true)).withRightSide(new BedSideStatus().withInBed(false))
42 assertEquals(readJson("bed-status.json"), gson.toJson(bedStatus));
46 public void testDeserializeAllFields() throws Exception {
47 try (FileReader reader = new FileReader(getTestDataFile("bed-status.json"))) {
48 BedStatus bedStatus = gson.fromJson(reader, BedStatus.class);
49 assertEquals("-9999999999999999999", bedStatus.getBedId());
50 assertEquals(Long.valueOf(1L), bedStatus.getStatus());
52 BedSideStatus leftSide = bedStatus.getLeftSide();
53 assertNotNull(leftSide);
54 assertTrue(leftSide.isInBed());
56 BedSideStatus rightSide = bedStatus.getRightSide();
57 assertNotNull(rightSide);
58 assertFalse(rightSide.isInBed());