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.Bed;
25 import org.openhab.binding.sleepiq.internal.api.dto.BedsResponse;
26 import org.openhab.binding.sleepiq.internal.api.impl.GsonGenerator;
28 import com.google.gson.Gson;
31 * The {@link BedsResponseTest} tests deserialization of a beds response object.
33 * @author Gregory Moyer - Initial contribution
36 public class BedsResponseTest extends AbstractTest {
37 private static Gson gson = GsonGenerator.create(true);
40 public void testSerializeAllFields() throws Exception {
41 BedsResponse bedsResponse = new BedsResponse()
42 .withBeds(Arrays.asList(new Bed().withName("Bed1"), new Bed().withName("Bed2")));
43 assertEquals(readJson("beds-response.json"), gson.toJson(bedsResponse));
47 public void testDeserializeAllFields() throws Exception {
48 try (FileReader reader = new FileReader(getTestDataFile("beds-response.json"))) {
49 BedsResponse bedsResponse = gson.fromJson(reader, BedsResponse.class);
51 List<Bed> beds = bedsResponse.getBeds();
53 assertEquals(2, beds.size());
54 assertEquals("Bed1", beds.get(0).getName());
55 assertEquals("Bed2", beds.get(1).getName());