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.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;
21 import java.util.List;
23 import org.eclipse.jdt.annotation.NonNullByDefault;
24 import org.junit.jupiter.api.Test;
25 import org.openhab.binding.mielecloud.internal.webservice.api.json.Actions;
26 import org.openhab.binding.mielecloud.internal.webservice.api.json.Light;
27 import org.openhab.binding.mielecloud.internal.webservice.api.json.ProcessAction;
30 * @author Björn Lange - Initial contribution
33 public class ActionsStateTest {
34 private static final String DEVICE_IDENTIFIER = "003458276345";
37 public void testGetDeviceIdentifierReturnsDeviceIdentifier() {
39 Actions actions = mock(Actions.class);
40 ActionsState actionsState = new ActionsState(DEVICE_IDENTIFIER, actions);
43 String deviceId = actionsState.getDeviceIdentifier();
46 assertEquals(DEVICE_IDENTIFIER, deviceId);
50 public void testReturnValuesWhenActionsIsNull() {
52 ActionsState actionState = new ActionsState(DEVICE_IDENTIFIER, null);
55 boolean canBeStarted = actionState.canBeStarted();
56 boolean canBeStopped = actionState.canBeStopped();
57 boolean canBePaused = actionState.canBePaused();
58 boolean canStartSupercooling = actionState.canStartSupercooling();
59 boolean canStopSupercooling = actionState.canStopSupercooling();
60 boolean canContolSupercooling = actionState.canContolSupercooling();
61 boolean canStartSuperfreezing = actionState.canStartSuperfreezing();
62 boolean canStopSuperfreezing = actionState.canStopSuperfreezing();
63 boolean canControlSuperfreezing = actionState.canControlSuperfreezing();
64 boolean canEnableLight = actionState.canEnableLight();
65 boolean canDisableLight = actionState.canDisableLight();
68 assertFalse(canBeStarted);
69 assertFalse(canBeStopped);
70 assertFalse(canBePaused);
71 assertFalse(canStartSupercooling);
72 assertFalse(canStopSupercooling);
73 assertFalse(canContolSupercooling);
74 assertFalse(canStartSuperfreezing);
75 assertFalse(canStopSuperfreezing);
76 assertFalse(canControlSuperfreezing);
77 assertFalse(canEnableLight);
78 assertFalse(canDisableLight);
82 public void testReturnValuesWhenProcessActionIsEmpty() {
84 Actions actions = mock(Actions.class);
85 ActionsState actionState = new ActionsState(DEVICE_IDENTIFIER, null);
86 when(actions.getProcessAction()).thenReturn(Collections.emptyList());
89 boolean canBeStarted = actionState.canBeStarted();
90 boolean canBeStopped = actionState.canBeStopped();
91 boolean canBePaused = actionState.canBePaused();
92 boolean canStartSupercooling = actionState.canStartSupercooling();
93 boolean canStopSupercooling = actionState.canStopSupercooling();
94 boolean canStartSuperfreezing = actionState.canStartSuperfreezing();
95 boolean canStopSuperfreezing = actionState.canStopSuperfreezing();
98 assertFalse(canBeStarted);
99 assertFalse(canBeStopped);
100 assertFalse(canBePaused);
101 assertFalse(canStartSupercooling);
102 assertFalse(canStopSupercooling);
103 assertFalse(canStartSuperfreezing);
104 assertFalse(canStopSuperfreezing);
108 public void testReturnValuesWhenLightIsEmpty() {
110 Actions actions = mock(Actions.class);
111 ActionsState actionState = new ActionsState(DEVICE_IDENTIFIER, null);
112 when(actions.getLight()).thenReturn(Collections.emptyList());
115 boolean canEnableLight = actionState.canEnableLight();
116 boolean canDisableLight = actionState.canDisableLight();
119 assertFalse(canEnableLight);
120 assertFalse(canDisableLight);
124 public void testReturnValueWhenProcessActionStartIsAvailable() {
126 Actions actions = mock(Actions.class);
127 ActionsState actionState = new ActionsState(DEVICE_IDENTIFIER, actions);
128 when(actions.getProcessAction()).thenReturn(List.of(ProcessAction.START));
131 boolean canBeStarted = actionState.canBeStarted();
132 boolean canBeStopped = actionState.canBeStopped();
135 assertTrue(canBeStarted);
136 assertFalse(canBeStopped);
140 public void testReturnValueWhenProcessActionStopIsAvailable() {
142 Actions actions = mock(Actions.class);
143 ActionsState actionState = new ActionsState(DEVICE_IDENTIFIER, actions);
144 when(actions.getProcessAction()).thenReturn(List.of(ProcessAction.STOP));
147 boolean canBeStarted = actionState.canBeStarted();
148 boolean canBeStopped = actionState.canBeStopped();
151 assertFalse(canBeStarted);
152 assertTrue(canBeStopped);
156 public void testReturnValueWhenProcessActionStartAndStopAreAvailable() {
158 Actions actions = mock(Actions.class);
159 ActionsState actionState = new ActionsState(DEVICE_IDENTIFIER, actions);
160 when(actions.getProcessAction()).thenReturn(List.of(ProcessAction.START, ProcessAction.STOP));
163 boolean canBeStarted = actionState.canBeStarted();
164 boolean canBeStopped = actionState.canBeStopped();
167 assertTrue(canBeStarted);
168 assertTrue(canBeStopped);
172 public void testReturnValueWhenProcessActionStartSupercoolIsAvailable() {
174 Actions actions = mock(Actions.class);
175 ActionsState actionState = new ActionsState(DEVICE_IDENTIFIER, actions);
176 when(actions.getProcessAction()).thenReturn(List.of(ProcessAction.START_SUPERCOOLING));
179 boolean canStartSupercooling = actionState.canStartSupercooling();
180 boolean canContolSupercooling = actionState.canContolSupercooling();
183 assertTrue(canStartSupercooling);
184 assertTrue(canContolSupercooling);
188 public void testReturnValueWhenProcessActionStartSuperfreezeIsAvailable() {
190 Actions actions = mock(Actions.class);
191 ActionsState actionState = new ActionsState(DEVICE_IDENTIFIER, actions);
192 when(actions.getProcessAction()).thenReturn(List.of(ProcessAction.START_SUPERFREEZING));
195 boolean canStartSuperfreezing = actionState.canStartSuperfreezing();
196 boolean canControlSuperfreezing = actionState.canControlSuperfreezing();
199 assertTrue(canStartSuperfreezing);
200 assertTrue(canControlSuperfreezing);
204 public void testReturnValueWhenLightEnableIsAvailable() {
206 Actions actions = mock(Actions.class);
207 ActionsState actionState = new ActionsState(DEVICE_IDENTIFIER, actions);
208 when(actions.getLight()).thenReturn(List.of(Light.ENABLE));
211 boolean canEnableLight = actionState.canEnableLight();
214 assertTrue(canEnableLight);
218 public void testReturnValueWhenLightDisableIsAvailable() {
220 Actions actions = mock(Actions.class);
221 ActionsState actionState = new ActionsState(DEVICE_IDENTIFIER, actions);
222 when(actions.getLight()).thenReturn(List.of(Light.DISABLE));
225 boolean canDisableLight = actionState.canDisableLight();
228 assertTrue(canDisableLight);
232 public void testCanControlLightReturnsTrueWhenLightCanBeEnabled() {
234 Actions actions = mock(Actions.class);
235 when(actions.getLight()).thenReturn(List.of(Light.ENABLE));
237 ActionsState actionState = new ActionsState(DEVICE_IDENTIFIER, actions);
240 boolean canControlLight = actionState.canControlLight();
243 assertTrue(canControlLight);
247 public void testCanControlLightReturnsTrueWhenLightCanBeDisabled() {
249 Actions actions = mock(Actions.class);
250 when(actions.getLight()).thenReturn(List.of(Light.DISABLE));
252 ActionsState actionState = new ActionsState(DEVICE_IDENTIFIER, actions);
255 boolean canControlLight = actionState.canControlLight();
258 assertTrue(canControlLight);
262 public void testCanControlLightReturnsTrueWhenLightCanBeEnabledAndDisabled() {
264 Actions actions = mock(Actions.class);
265 when(actions.getLight()).thenReturn(Arrays.asList(Light.ENABLE, Light.DISABLE));
267 ActionsState actionState = new ActionsState(DEVICE_IDENTIFIER, actions);
270 boolean canControlLight = actionState.canControlLight();
273 assertTrue(canControlLight);
277 public void testCanControlLightReturnsFalseWhenNoLightOptionIsAvailable() {
279 Actions actions = mock(Actions.class);
280 when(actions.getLight()).thenReturn(new LinkedList<Light>());
282 ActionsState actionState = new ActionsState(DEVICE_IDENTIFIER, actions);
285 boolean canControlLight = actionState.canControlLight();
288 assertFalse(canControlLight);
292 public void testNoProgramCanBeSetWhenNoProgramIdIsPresent() {
294 Actions actions = mock(Actions.class);
295 when(actions.getProgramId()).thenReturn(Collections.emptyList());
297 ActionsState actionState = new ActionsState(DEVICE_IDENTIFIER, actions);
300 boolean canSetActiveProgram = actionState.canSetActiveProgramId();
303 assertFalse(canSetActiveProgram);
307 public void testProgramIdCanBeSetWhenProgramIdIsPresent() {
309 Actions actions = mock(Actions.class);
310 when(actions.getProgramId()).thenReturn(List.of(1));
312 ActionsState actionState = new ActionsState(DEVICE_IDENTIFIER, actions);
315 boolean canSetActiveProgram = actionState.canSetActiveProgramId();
318 assertTrue(canSetActiveProgram);