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;
15 import static org.junit.jupiter.api.Assertions.*;
16 import static org.mockito.Mockito.*;
18 import java.util.Arrays;
19 import java.util.Collections;
20 import java.util.LinkedList;
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.junit.jupiter.api.Test;
24 import org.openhab.binding.mielecloud.internal.webservice.api.json.Actions;
25 import org.openhab.binding.mielecloud.internal.webservice.api.json.Light;
26 import org.openhab.binding.mielecloud.internal.webservice.api.json.ProcessAction;
29 * @author Björn Lange - Initial contribution
32 public class ActionsStateTest {
33 private static final String DEVICE_IDENTIFIER = "003458276345";
36 public void testGetDeviceIdentifierReturnsDeviceIdentifier() {
38 Actions actions = mock(Actions.class);
39 ActionsState actionsState = new ActionsState(DEVICE_IDENTIFIER, actions);
42 String deviceId = actionsState.getDeviceIdentifier();
45 assertEquals(DEVICE_IDENTIFIER, deviceId);
49 public void testReturnValuesWhenActionsIsNull() {
51 ActionsState actionState = new ActionsState(DEVICE_IDENTIFIER, null);
54 boolean canBeStarted = actionState.canBeStarted();
55 boolean canBeStopped = actionState.canBeStopped();
56 boolean canBePaused = actionState.canBePaused();
57 boolean canStartSupercooling = actionState.canStartSupercooling();
58 boolean canStopSupercooling = actionState.canStopSupercooling();
59 boolean canContolSupercooling = actionState.canContolSupercooling();
60 boolean canStartSuperfreezing = actionState.canStartSuperfreezing();
61 boolean canStopSuperfreezing = actionState.canStopSuperfreezing();
62 boolean canControlSuperfreezing = actionState.canControlSuperfreezing();
63 boolean canEnableLight = actionState.canEnableLight();
64 boolean canDisableLight = actionState.canDisableLight();
67 assertFalse(canBeStarted);
68 assertFalse(canBeStopped);
69 assertFalse(canBePaused);
70 assertFalse(canStartSupercooling);
71 assertFalse(canStopSupercooling);
72 assertFalse(canContolSupercooling);
73 assertFalse(canStartSuperfreezing);
74 assertFalse(canStopSuperfreezing);
75 assertFalse(canControlSuperfreezing);
76 assertFalse(canEnableLight);
77 assertFalse(canDisableLight);
81 public void testReturnValuesWhenProcessActionIsEmpty() {
83 Actions actions = mock(Actions.class);
84 ActionsState actionState = new ActionsState(DEVICE_IDENTIFIER, null);
85 when(actions.getProcessAction()).thenReturn(Collections.emptyList());
88 boolean canBeStarted = actionState.canBeStarted();
89 boolean canBeStopped = actionState.canBeStopped();
90 boolean canBePaused = actionState.canBePaused();
91 boolean canStartSupercooling = actionState.canStartSupercooling();
92 boolean canStopSupercooling = actionState.canStopSupercooling();
93 boolean canStartSuperfreezing = actionState.canStartSuperfreezing();
94 boolean canStopSuperfreezing = actionState.canStopSuperfreezing();
97 assertFalse(canBeStarted);
98 assertFalse(canBeStopped);
99 assertFalse(canBePaused);
100 assertFalse(canStartSupercooling);
101 assertFalse(canStopSupercooling);
102 assertFalse(canStartSuperfreezing);
103 assertFalse(canStopSuperfreezing);
107 public void testReturnValuesWhenLightIsEmpty() {
109 Actions actions = mock(Actions.class);
110 ActionsState actionState = new ActionsState(DEVICE_IDENTIFIER, null);
111 when(actions.getLight()).thenReturn(Collections.emptyList());
114 boolean canEnableLight = actionState.canEnableLight();
115 boolean canDisableLight = actionState.canDisableLight();
118 assertFalse(canEnableLight);
119 assertFalse(canDisableLight);
123 public void testReturnValueWhenProcessActionStartIsAvailable() {
125 Actions actions = mock(Actions.class);
126 ActionsState actionState = new ActionsState(DEVICE_IDENTIFIER, actions);
127 when(actions.getProcessAction()).thenReturn(Collections.singletonList(ProcessAction.START));
130 boolean canBeStarted = actionState.canBeStarted();
133 assertTrue(canBeStarted);
137 public void testReturnValueWhenProcessActionStopIsAvailable() {
139 Actions actions = mock(Actions.class);
140 ActionsState actionState = new ActionsState(DEVICE_IDENTIFIER, actions);
141 when(actions.getProcessAction()).thenReturn(Collections.singletonList(ProcessAction.STOP));
144 boolean canBeStopped = actionState.canBeStopped();
147 assertTrue(canBeStopped);
151 public void testReturnValueWhenProcessActionStartSupercoolIsAvailable() {
153 Actions actions = mock(Actions.class);
154 ActionsState actionState = new ActionsState(DEVICE_IDENTIFIER, actions);
155 when(actions.getProcessAction()).thenReturn(Collections.singletonList(ProcessAction.START_SUPERCOOLING));
158 boolean canStartSupercooling = actionState.canStartSupercooling();
159 boolean canContolSupercooling = actionState.canContolSupercooling();
162 assertTrue(canStartSupercooling);
163 assertTrue(canContolSupercooling);
167 public void testReturnValueWhenProcessActionStartSuperfreezeIsAvailable() {
169 Actions actions = mock(Actions.class);
170 ActionsState actionState = new ActionsState(DEVICE_IDENTIFIER, actions);
171 when(actions.getProcessAction()).thenReturn(Collections.singletonList(ProcessAction.START_SUPERFREEZING));
174 boolean canStartSuperfreezing = actionState.canStartSuperfreezing();
175 boolean canControlSuperfreezing = actionState.canControlSuperfreezing();
178 assertTrue(canStartSuperfreezing);
179 assertTrue(canControlSuperfreezing);
183 public void testReturnValueWhenLightEnableIsAvailable() {
185 Actions actions = mock(Actions.class);
186 ActionsState actionState = new ActionsState(DEVICE_IDENTIFIER, actions);
187 when(actions.getLight()).thenReturn(Collections.singletonList(Light.ENABLE));
190 boolean canEnableLight = actionState.canEnableLight();
193 assertTrue(canEnableLight);
197 public void testReturnValueWhenLightDisableIsAvailable() {
199 Actions actions = mock(Actions.class);
200 ActionsState actionState = new ActionsState(DEVICE_IDENTIFIER, actions);
201 when(actions.getLight()).thenReturn(Collections.singletonList(Light.DISABLE));
204 boolean canDisableLight = actionState.canDisableLight();
207 assertTrue(canDisableLight);
211 public void testCanControlLightReturnsTrueWhenLightCanBeEnabled() {
213 Actions actions = mock(Actions.class);
214 when(actions.getLight()).thenReturn(Collections.singletonList(Light.ENABLE));
216 ActionsState actionState = new ActionsState(DEVICE_IDENTIFIER, actions);
219 boolean canControlLight = actionState.canControlLight();
222 assertTrue(canControlLight);
226 public void testCanControlLightReturnsTrueWhenLightCanBeDisabled() {
228 Actions actions = mock(Actions.class);
229 when(actions.getLight()).thenReturn(Collections.singletonList(Light.DISABLE));
231 ActionsState actionState = new ActionsState(DEVICE_IDENTIFIER, actions);
234 boolean canControlLight = actionState.canControlLight();
237 assertTrue(canControlLight);
241 public void testCanControlLightReturnsTrueWhenLightCanBeEnabledAndDisabled() {
243 Actions actions = mock(Actions.class);
244 when(actions.getLight()).thenReturn(Arrays.asList(Light.ENABLE, Light.DISABLE));
246 ActionsState actionState = new ActionsState(DEVICE_IDENTIFIER, actions);
249 boolean canControlLight = actionState.canControlLight();
252 assertTrue(canControlLight);
256 public void testCanControlLightReturnsFalseWhenNoLightOptionIsAvailable() {
258 Actions actions = mock(Actions.class);
259 when(actions.getLight()).thenReturn(new LinkedList<Light>());
261 ActionsState actionState = new ActionsState(DEVICE_IDENTIFIER, actions);
264 boolean canControlLight = actionState.canControlLight();
267 assertFalse(canControlLight);
271 public void testNoProgramCanBeSetWhenNoProgramIdIsPresent() {
273 Actions actions = mock(Actions.class);
274 when(actions.getProgramId()).thenReturn(Collections.emptyList());
276 ActionsState actionState = new ActionsState(DEVICE_IDENTIFIER, actions);
279 boolean canSetActiveProgram = actionState.canSetActiveProgramId();
282 assertFalse(canSetActiveProgram);
286 public void testProgramIdCanBeSetWhenProgramIdIsPresent() {
288 Actions actions = mock(Actions.class);
289 when(actions.getProgramId()).thenReturn(Collections.singletonList(1));
291 ActionsState actionState = new ActionsState(DEVICE_IDENTIFIER, actions);
294 boolean canSetActiveProgram = actionState.canSetActiveProgramId();
297 assertTrue(canSetActiveProgram);