2 * Copyright (c) 2010-2022 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.mielecloud.internal.webservice.api.json;
15 import static org.junit.jupiter.api.Assertions.*;
17 import java.io.IOException;
18 import java.util.Arrays;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.junit.jupiter.api.Test;
23 import com.google.gson.Gson;
26 * @author Björn Lange - Initial contribution
29 public class ActionsTest {
31 public void testNullProcessActionInJsonIsConvertedToEmptyList() throws IOException {
33 String json = "{ \"processAction\": null, \"light\": [1], \"startTime\": [ [0, 0],[23,59] ] }";
36 Actions actions = new Gson().fromJson(json, Actions.class);
39 assertNotNull(actions.getProcessAction());
40 assertTrue(actions.getProcessAction().isEmpty());
44 public void testNullLightInJsonIsConvertedToEmptyList() throws IOException {
46 String json = "{ \"processAction\": [1], \"light\": null, \"startTime\": [ [0, 0],[23,59] ] }";
49 Actions actions = new Gson().fromJson(json, Actions.class);
52 assertNotNull(actions.getLight());
53 assertTrue(actions.getLight().isEmpty());
57 public void testNullStartTimeInJsonIsReturnedAsNull() throws IOException {
59 String json = "{ \"processAction\": [1], \"light\": [1], \"startTime\": null }";
62 Actions actions = new Gson().fromJson(json, Actions.class);
65 assertFalse(actions.getStartTime().isPresent());
69 public void testIdListIsEmptyWhenProgramIdFieldIsMissing() {
71 String json = "{ \"processAction\": [1] }";
74 Actions actions = new Gson().fromJson(json, Actions.class);
77 assertTrue(actions.getProgramId().isEmpty());
81 public void testIdListIsEmptyWhenProgramIdFieldIsNull() {
83 String json = "{ \"programId\": null }";
86 Actions actions = new Gson().fromJson(json, Actions.class);
89 assertTrue(actions.getProgramId().isEmpty());
93 public void testIdListContainsEntriesWhenProgramIdFieldIsPresent() {
95 String json = "{ \"programId\": [1,2,3,4] }";
98 Actions actions = new Gson().fromJson(json, Actions.class);
101 assertEquals(Arrays.asList(1, 2, 3, 4), actions.getProgramId());