]> git.basschouten.com Git - openhab-addons.git/blob
a7fe5c92ee896456dbcf3faaf207f1f13ebeb78c
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.mielecloud.internal.webservice.api;
14
15 import static org.junit.jupiter.api.Assertions.*;
16 import static org.mockito.Mockito.*;
17
18 import java.util.Arrays;
19 import java.util.Collections;
20 import java.util.LinkedList;
21
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;
27
28 /**
29  * @author Björn Lange - Initial contribution
30  */
31 @NonNullByDefault
32 public class ActionsStateTest {
33     private static final String DEVICE_IDENTIFIER = "003458276345";
34
35     @Test
36     public void testGetDeviceIdentifierReturnsDeviceIdentifier() {
37         // given:
38         Actions actions = mock(Actions.class);
39         ActionsState actionsState = new ActionsState(DEVICE_IDENTIFIER, actions);
40
41         // when:
42         String deviceId = actionsState.getDeviceIdentifier();
43
44         // then:
45         assertEquals(DEVICE_IDENTIFIER, deviceId);
46     }
47
48     @Test
49     public void testReturnValuesWhenActionsIsNull() {
50         // given:
51         ActionsState actionState = new ActionsState(DEVICE_IDENTIFIER, null);
52
53         // when:
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();
65
66         // then:
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);
78     }
79
80     @Test
81     public void testReturnValuesWhenProcessActionIsEmpty() {
82         // given:
83         Actions actions = mock(Actions.class);
84         ActionsState actionState = new ActionsState(DEVICE_IDENTIFIER, null);
85         when(actions.getProcessAction()).thenReturn(Collections.emptyList());
86
87         // when:
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();
95
96         // then:
97         assertFalse(canBeStarted);
98         assertFalse(canBeStopped);
99         assertFalse(canBePaused);
100         assertFalse(canStartSupercooling);
101         assertFalse(canStopSupercooling);
102         assertFalse(canStartSuperfreezing);
103         assertFalse(canStopSuperfreezing);
104     }
105
106     @Test
107     public void testReturnValuesWhenLightIsEmpty() {
108         // given:
109         Actions actions = mock(Actions.class);
110         ActionsState actionState = new ActionsState(DEVICE_IDENTIFIER, null);
111         when(actions.getLight()).thenReturn(Collections.emptyList());
112
113         // when:
114         boolean canEnableLight = actionState.canEnableLight();
115         boolean canDisableLight = actionState.canDisableLight();
116
117         // then:
118         assertFalse(canEnableLight);
119         assertFalse(canDisableLight);
120     }
121
122     @Test
123     public void testReturnValueWhenProcessActionStartIsAvailable() {
124         // given:
125         Actions actions = mock(Actions.class);
126         ActionsState actionState = new ActionsState(DEVICE_IDENTIFIER, actions);
127         when(actions.getProcessAction()).thenReturn(Collections.singletonList(ProcessAction.START));
128
129         // when:
130         boolean canBeStarted = actionState.canBeStarted();
131
132         // then:
133         assertTrue(canBeStarted);
134     }
135
136     @Test
137     public void testReturnValueWhenProcessActionStopIsAvailable() {
138         // given:
139         Actions actions = mock(Actions.class);
140         ActionsState actionState = new ActionsState(DEVICE_IDENTIFIER, actions);
141         when(actions.getProcessAction()).thenReturn(Collections.singletonList(ProcessAction.STOP));
142
143         // when:
144         boolean canBeStopped = actionState.canBeStopped();
145
146         // then:
147         assertTrue(canBeStopped);
148     }
149
150     @Test
151     public void testReturnValueWhenProcessActionStartSupercoolIsAvailable() {
152         // given:
153         Actions actions = mock(Actions.class);
154         ActionsState actionState = new ActionsState(DEVICE_IDENTIFIER, actions);
155         when(actions.getProcessAction()).thenReturn(Collections.singletonList(ProcessAction.START_SUPERCOOLING));
156
157         // when:
158         boolean canStartSupercooling = actionState.canStartSupercooling();
159         boolean canContolSupercooling = actionState.canContolSupercooling();
160
161         // then:
162         assertTrue(canStartSupercooling);
163         assertTrue(canContolSupercooling);
164     }
165
166     @Test
167     public void testReturnValueWhenProcessActionStartSuperfreezeIsAvailable() {
168         // given:
169         Actions actions = mock(Actions.class);
170         ActionsState actionState = new ActionsState(DEVICE_IDENTIFIER, actions);
171         when(actions.getProcessAction()).thenReturn(Collections.singletonList(ProcessAction.START_SUPERFREEZING));
172
173         // when:
174         boolean canStartSuperfreezing = actionState.canStartSuperfreezing();
175         boolean canControlSuperfreezing = actionState.canControlSuperfreezing();
176
177         // then:
178         assertTrue(canStartSuperfreezing);
179         assertTrue(canControlSuperfreezing);
180     }
181
182     @Test
183     public void testReturnValueWhenLightEnableIsAvailable() {
184         // given:
185         Actions actions = mock(Actions.class);
186         ActionsState actionState = new ActionsState(DEVICE_IDENTIFIER, actions);
187         when(actions.getLight()).thenReturn(Collections.singletonList(Light.ENABLE));
188
189         // when:
190         boolean canEnableLight = actionState.canEnableLight();
191
192         // then:
193         assertTrue(canEnableLight);
194     }
195
196     @Test
197     public void testReturnValueWhenLightDisableIsAvailable() {
198         // given:
199         Actions actions = mock(Actions.class);
200         ActionsState actionState = new ActionsState(DEVICE_IDENTIFIER, actions);
201         when(actions.getLight()).thenReturn(Collections.singletonList(Light.DISABLE));
202
203         // when:
204         boolean canDisableLight = actionState.canDisableLight();
205
206         // then:
207         assertTrue(canDisableLight);
208     }
209
210     @Test
211     public void testCanControlLightReturnsTrueWhenLightCanBeEnabled() {
212         // given:
213         Actions actions = mock(Actions.class);
214         when(actions.getLight()).thenReturn(Collections.singletonList(Light.ENABLE));
215
216         ActionsState actionState = new ActionsState(DEVICE_IDENTIFIER, actions);
217
218         // when:
219         boolean canControlLight = actionState.canControlLight();
220
221         // then:
222         assertTrue(canControlLight);
223     }
224
225     @Test
226     public void testCanControlLightReturnsTrueWhenLightCanBeDisabled() {
227         // given:
228         Actions actions = mock(Actions.class);
229         when(actions.getLight()).thenReturn(Collections.singletonList(Light.DISABLE));
230
231         ActionsState actionState = new ActionsState(DEVICE_IDENTIFIER, actions);
232
233         // when:
234         boolean canControlLight = actionState.canControlLight();
235
236         // then:
237         assertTrue(canControlLight);
238     }
239
240     @Test
241     public void testCanControlLightReturnsTrueWhenLightCanBeEnabledAndDisabled() {
242         // given:
243         Actions actions = mock(Actions.class);
244         when(actions.getLight()).thenReturn(Arrays.asList(Light.ENABLE, Light.DISABLE));
245
246         ActionsState actionState = new ActionsState(DEVICE_IDENTIFIER, actions);
247
248         // when:
249         boolean canControlLight = actionState.canControlLight();
250
251         // then:
252         assertTrue(canControlLight);
253     }
254
255     @Test
256     public void testCanControlLightReturnsFalseWhenNoLightOptionIsAvailable() {
257         // given:
258         Actions actions = mock(Actions.class);
259         when(actions.getLight()).thenReturn(new LinkedList<Light>());
260
261         ActionsState actionState = new ActionsState(DEVICE_IDENTIFIER, actions);
262
263         // when:
264         boolean canControlLight = actionState.canControlLight();
265
266         // then:
267         assertFalse(canControlLight);
268     }
269
270     @Test
271     public void testNoProgramCanBeSetWhenNoProgramIdIsPresent() {
272         // given:
273         Actions actions = mock(Actions.class);
274         when(actions.getProgramId()).thenReturn(Collections.emptyList());
275
276         ActionsState actionState = new ActionsState(DEVICE_IDENTIFIER, actions);
277
278         // when:
279         boolean canSetActiveProgram = actionState.canSetActiveProgramId();
280
281         // then:
282         assertFalse(canSetActiveProgram);
283     }
284
285     @Test
286     public void testProgramIdCanBeSetWhenProgramIdIsPresent() {
287         // given:
288         Actions actions = mock(Actions.class);
289         when(actions.getProgramId()).thenReturn(Collections.singletonList(1));
290
291         ActionsState actionState = new ActionsState(DEVICE_IDENTIFIER, actions);
292
293         // when:
294         boolean canSetActiveProgram = actionState.canSetActiveProgramId();
295
296         // then:
297         assertTrue(canSetActiveProgram);
298     }
299 }