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;
18 import java.util.Arrays;
19 import java.util.List;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.junit.jupiter.api.Test;
23 import org.openhab.binding.sleepiq.api.test.AbstractTest;
24 import org.openhab.binding.sleepiq.internal.api.dto.BedStatus;
25 import org.openhab.binding.sleepiq.internal.api.dto.FamilyStatusResponse;
26 import org.openhab.binding.sleepiq.internal.api.impl.GsonGenerator;
28 import com.google.gson.Gson;
31 * The {@link FamilyStatusText} tests deserialization of a family status object.
33 * @author Gregory Moyer - Initial contribution
36 public class FamilyStatusTest extends AbstractTest {
37 private static Gson gson = GsonGenerator.create(true);
40 public void testSerializeAllFields() throws Exception {
41 FamilyStatusResponse familyStatus = new FamilyStatusResponse()
42 .withBeds(Arrays.asList(new BedStatus().withStatus(1L)));
43 assertEquals(readJson("family-status.json"), gson.toJson(familyStatus));
47 public void testDeserializeAllFields() throws Exception {
48 try (FileReader reader = new FileReader(getTestDataFile("family-status.json"))) {
49 FamilyStatusResponse familyStatus = gson.fromJson(reader, FamilyStatusResponse.class);
51 List<BedStatus> beds = familyStatus.getBeds();
53 assertEquals(1, beds.size());
54 assertEquals(Long.valueOf(1L), beds.get(0).getStatus());