]> git.basschouten.com Git - openhab-addons.git/blob
d2387d0d0f78599f9e24ff2a0795064ac2ff9b4f
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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 import java.util.Optional;
22
23 import org.eclipse.jdt.annotation.NonNullByDefault;
24 import org.junit.jupiter.api.Test;
25 import org.openhab.binding.mielecloud.internal.webservice.api.json.Device;
26 import org.openhab.binding.mielecloud.internal.webservice.api.json.DeviceIdentLabel;
27 import org.openhab.binding.mielecloud.internal.webservice.api.json.DeviceType;
28 import org.openhab.binding.mielecloud.internal.webservice.api.json.DryingStep;
29 import org.openhab.binding.mielecloud.internal.webservice.api.json.Ident;
30 import org.openhab.binding.mielecloud.internal.webservice.api.json.Light;
31 import org.openhab.binding.mielecloud.internal.webservice.api.json.PlateStep;
32 import org.openhab.binding.mielecloud.internal.webservice.api.json.ProgramId;
33 import org.openhab.binding.mielecloud.internal.webservice.api.json.ProgramPhase;
34 import org.openhab.binding.mielecloud.internal.webservice.api.json.ProgramType;
35 import org.openhab.binding.mielecloud.internal.webservice.api.json.RemoteEnable;
36 import org.openhab.binding.mielecloud.internal.webservice.api.json.SpinningSpeed;
37 import org.openhab.binding.mielecloud.internal.webservice.api.json.State;
38 import org.openhab.binding.mielecloud.internal.webservice.api.json.StateType;
39 import org.openhab.binding.mielecloud.internal.webservice.api.json.Status;
40 import org.openhab.binding.mielecloud.internal.webservice.api.json.Temperature;
41 import org.openhab.binding.mielecloud.internal.webservice.api.json.Type;
42 import org.openhab.binding.mielecloud.internal.webservice.api.json.VentilationStep;
43
44 /**
45  * @author Björn Lange - Initial contribution
46  * @author Benjamin Bolte - Add pre-heat finished, plate step, door state, door alarm and info state channels and map
47  *         signal flags from API
48  * @author Björn Lange - Add elapsed time channel, robotic vacuum cleaner
49  */
50 @NonNullByDefault
51 public class DeviceStateTest {
52     private static final String DEVICE_IDENTIFIER = "mac-f83001f37d45ffff";
53
54     @Test
55     public void testGetDeviceIdentifierReturnsDeviceIdentifier() {
56         // given:
57         Device device = mock(Device.class);
58         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
59
60         // when:
61         String deviceId = deviceState.getDeviceIdentifier();
62
63         // then:
64         assertEquals(DEVICE_IDENTIFIER, deviceId);
65     }
66
67     @Test
68     public void testReturnValuesWhenDeviceIsNull() {
69         // given:
70         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, null);
71
72         // when:
73         Optional<String> status = deviceState.getStatus();
74         Optional<Integer> statusRaw = deviceState.getStatusRaw();
75         Optional<StateType> stateType = deviceState.getStateType();
76         Optional<String> selectedProgram = deviceState.getSelectedProgram();
77         Optional<Long> selectedProgramId = deviceState.getSelectedProgramId();
78         Optional<String> programPhase = deviceState.getProgramPhase();
79         Optional<Integer> programPhaseRaw = deviceState.getProgramPhaseRaw();
80         Optional<String> dryingTarget = deviceState.getDryingTarget();
81         Optional<Integer> dryingTargetRaw = deviceState.getDryingTargetRaw();
82         Optional<Boolean> hasPreHeatFinished = deviceState.hasPreHeatFinished();
83         Optional<Integer> targetTemperature = deviceState.getTargetTemperature(0);
84         Optional<Integer> temperature = deviceState.getTemperature(0);
85         Optional<Boolean> remoteControlEnabled = deviceState.isRemoteControlEnabled();
86         Optional<String> ventilationStep = deviceState.getVentilationStep();
87         Optional<Integer> ventilationStepRaw = deviceState.getVentilationStepRaw();
88         Optional<Integer> plateStepCount = deviceState.getPlateStepCount();
89         Optional<String> plateStep = deviceState.getPlateStep(0);
90         Optional<Integer> plateStepRaw = deviceState.getPlateStepRaw(0);
91         boolean hasError = deviceState.hasError();
92         boolean hasInfo = deviceState.hasInfo();
93         Optional<Boolean> doorState = deviceState.getDoorState();
94         Optional<Boolean> doorAlarm = deviceState.getDoorAlarm();
95         Optional<String> type = deviceState.getType();
96         DeviceType rawType = deviceState.getRawType();
97         Optional<Integer> batteryLevel = deviceState.getBatteryLevel();
98
99         Optional<String> deviceName = deviceState.getDeviceName();
100         Optional<String> fabNumber = deviceState.getFabNumber();
101         Optional<String> techType = deviceState.getTechType();
102         Optional<Integer> progress = deviceState.getProgress();
103
104         // then:
105         assertFalse(status.isPresent());
106         assertFalse(statusRaw.isPresent());
107         assertFalse(stateType.isPresent());
108         assertFalse(selectedProgram.isPresent());
109         assertFalse(selectedProgramId.isPresent());
110         assertFalse(programPhase.isPresent());
111         assertFalse(programPhaseRaw.isPresent());
112         assertFalse(dryingTarget.isPresent());
113         assertFalse(dryingTargetRaw.isPresent());
114         assertFalse(hasPreHeatFinished.isPresent());
115         assertFalse(targetTemperature.isPresent());
116         assertFalse(temperature.isPresent());
117         assertFalse(remoteControlEnabled.isPresent());
118         assertFalse(ventilationStep.isPresent());
119         assertFalse(ventilationStepRaw.isPresent());
120         assertFalse(plateStepCount.isPresent());
121         assertFalse(plateStep.isPresent());
122         assertFalse(plateStepRaw.isPresent());
123         assertFalse(hasError);
124         assertFalse(hasInfo);
125         assertFalse(doorState.isPresent());
126         assertFalse(doorAlarm.isPresent());
127         assertFalse(type.isPresent());
128         assertEquals(DeviceType.UNKNOWN, rawType);
129         assertFalse(deviceName.isPresent());
130         assertFalse(fabNumber.isPresent());
131         assertFalse(techType.isPresent());
132         assertFalse(progress.isPresent());
133         assertFalse(batteryLevel.isPresent());
134     }
135
136     @Test
137     public void testReturnValuesWhenStateIsNull() {
138         // given:
139         Device device = mock(Device.class);
140         when(device.getState()).thenReturn(Optional.empty());
141         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
142
143         // when:
144         Optional<String> status = deviceState.getStatus();
145         Optional<Integer> statusRaw = deviceState.getStatusRaw();
146         Optional<StateType> stateType = deviceState.getStateType();
147         Optional<String> selectedProgram = deviceState.getSelectedProgram();
148         Optional<Long> selectedProgramId = deviceState.getSelectedProgramId();
149         Optional<String> programPhase = deviceState.getProgramPhase();
150         Optional<Integer> programPhaseRaw = deviceState.getProgramPhaseRaw();
151         Optional<String> dryingTarget = deviceState.getDryingTarget();
152         Optional<Integer> dryingTargetRaw = deviceState.getDryingTargetRaw();
153         Optional<Boolean> hasPreHeatFinished = deviceState.hasPreHeatFinished();
154         Optional<Integer> targetTemperature = deviceState.getTargetTemperature(0);
155         Optional<Integer> temperature = deviceState.getTemperature(0);
156         Optional<Boolean> remoteControlEnabled = deviceState.isRemoteControlEnabled();
157         Optional<Integer> progress = deviceState.getProgress();
158         Optional<String> ventilationStep = deviceState.getVentilationStep();
159         Optional<Integer> ventilationStepRaw = deviceState.getVentilationStepRaw();
160         Optional<Integer> plateStepCount = deviceState.getPlateStepCount();
161         Optional<String> plateStep = deviceState.getPlateStep(0);
162         Optional<Integer> plateStepRaw = deviceState.getPlateStepRaw(0);
163         Boolean hasError = deviceState.hasError();
164         Optional<Boolean> doorState = deviceState.getDoorState();
165         Optional<Boolean> doorAlarm = deviceState.getDoorAlarm();
166         Optional<Integer> batteryLevel = deviceState.getBatteryLevel();
167
168         // then:
169         assertFalse(status.isPresent());
170         assertFalse(statusRaw.isPresent());
171         assertFalse(stateType.isPresent());
172         assertFalse(selectedProgram.isPresent());
173         assertFalse(selectedProgramId.isPresent());
174         assertFalse(programPhase.isPresent());
175         assertFalse(programPhaseRaw.isPresent());
176         assertFalse(dryingTarget.isPresent());
177         assertFalse(dryingTargetRaw.isPresent());
178         assertFalse(hasPreHeatFinished.isPresent());
179         assertFalse(targetTemperature.isPresent());
180         assertFalse(temperature.isPresent());
181         assertFalse(remoteControlEnabled.isPresent());
182         assertFalse(progress.isPresent());
183         assertFalse(ventilationStep.isPresent());
184         assertFalse(ventilationStepRaw.isPresent());
185         assertFalse(plateStepCount.isPresent());
186         assertFalse(plateStep.isPresent());
187         assertFalse(plateStepRaw.isPresent());
188         assertFalse(hasError);
189         assertFalse(doorState.isPresent());
190         assertFalse(doorAlarm.isPresent());
191         assertFalse(batteryLevel.isPresent());
192     }
193
194     @Test
195     public void testReturnValuesWhenStatusIsEmpty() {
196         // given:
197         State state = mock(State.class);
198         when(state.getStatus()).thenReturn(Optional.empty());
199
200         Device device = mock(Device.class);
201         when(device.getState()).thenReturn(Optional.of(state));
202         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
203
204         // when:
205         Optional<String> status = deviceState.getStatus();
206         Optional<Integer> statusRaw = deviceState.getStatusRaw();
207         Optional<StateType> stateType = deviceState.getStateType();
208
209         // then:
210         assertFalse(status.isPresent());
211         assertFalse(statusRaw.isPresent());
212         assertFalse(stateType.isPresent());
213     }
214
215     @Test
216     public void testReturnValuesWhenStatusValuesAreEmpty() {
217         // given:
218         Status statusMock = mock(Status.class);
219         when(statusMock.getValueLocalized()).thenReturn(Optional.empty());
220         when(statusMock.getValueRaw()).thenReturn(Optional.empty());
221
222         State state = mock(State.class);
223         when(state.getStatus()).thenReturn(Optional.of(statusMock));
224
225         Device device = mock(Device.class);
226         when(device.getState()).thenReturn(Optional.of(state));
227         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
228
229         // when:
230         Optional<String> status = deviceState.getStatus();
231         Optional<Integer> statusRaw = deviceState.getStatusRaw();
232         Optional<StateType> stateType = deviceState.getStateType();
233
234         // then:
235         assertFalse(status.isPresent());
236         assertFalse(statusRaw.isPresent());
237         assertFalse(stateType.isPresent());
238     }
239
240     @Test
241     public void testReturnValuesWhenStatusValueLocalizedIsNotNull() {
242         // given:
243         Status statusMock = mock(Status.class);
244         when(statusMock.getValueLocalized()).thenReturn(Optional.of("Not connected"));
245         when(statusMock.getValueRaw()).thenReturn(Optional.of(StateType.NOT_CONNECTED.getCode()));
246
247         State state = mock(State.class);
248         when(state.getStatus()).thenReturn(Optional.of(statusMock));
249
250         Device device = mock(Device.class);
251         when(device.getState()).thenReturn(Optional.of(state));
252         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
253
254         // when:
255         String status = deviceState.getStatus().get();
256         int statusRaw = deviceState.getStatusRaw().get();
257         StateType stateType = deviceState.getStateType().get();
258
259         // then:
260         assertEquals("Not connected", status);
261         assertEquals(StateType.NOT_CONNECTED.getCode(), statusRaw);
262         assertEquals(StateType.NOT_CONNECTED, stateType);
263     }
264
265     @Test
266     public void testReturnValuesWhenStatusValueRawIsNotNull() {
267         // given:
268         Status statusMock = mock(Status.class);
269         when(statusMock.getValueRaw()).thenReturn(Optional.of(StateType.END_PROGRAMMED.getCode()));
270
271         State state = mock(State.class);
272         when(state.getStatus()).thenReturn(Optional.of(statusMock));
273
274         Device device = mock(Device.class);
275         when(device.getState()).thenReturn(Optional.of(state));
276         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
277
278         // when:
279         StateType stateType = deviceState.getStateType().get();
280
281         // then:
282         assertEquals(StateType.END_PROGRAMMED, stateType);
283     }
284
285     @Test
286     public void testReturnValuesWhenProgramTypeIsEmpty() {
287         // given:
288         State state = mock(State.class);
289         when(state.getProgramType()).thenReturn(Optional.empty());
290
291         Device device = mock(Device.class);
292         when(device.getState()).thenReturn(Optional.of(state));
293         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
294
295         // when:
296         Optional<String> selectedProgram = deviceState.getSelectedProgram();
297         Optional<Long> selectedProgramId = deviceState.getSelectedProgramId();
298
299         // then:
300         assertFalse(selectedProgram.isPresent());
301         assertFalse(selectedProgramId.isPresent());
302     }
303
304     @Test
305     public void testReturnValuesWhenProgramTypeValueLocalizedIsEmpty() {
306         // given:
307         ProgramType programType = mock(ProgramType.class);
308         when(programType.getValueLocalized()).thenReturn(Optional.empty());
309
310         State state = mock(State.class);
311         when(state.getProgramType()).thenReturn(Optional.of(programType));
312
313         Device device = mock(Device.class);
314         when(device.getState()).thenReturn(Optional.of(state));
315         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
316
317         // when:
318         Optional<String> selectedProgram = deviceState.getSelectedProgram();
319         Optional<Long> selectedProgramId = deviceState.getSelectedProgramId();
320
321         // then:
322         assertFalse(selectedProgram.isPresent());
323         assertFalse(selectedProgramId.isPresent());
324     }
325
326     @Test
327     public void testReturnValuesWhenProgramTypeValueLocalizedIsNotNull() {
328         // given:
329         ProgramId programId = mock(ProgramId.class);
330         when(programId.getValueRaw()).thenReturn(Optional.of(3L));
331         when(programId.getValueLocalized()).thenReturn(Optional.of("Washing"));
332
333         State state = mock(State.class);
334         Status status = mock(Status.class);
335         Device device = mock(Device.class);
336         when(state.getStatus()).thenReturn(Optional.of(status));
337         when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
338         when(state.getProgramId()).thenReturn(Optional.of(programId));
339         when(device.getState()).thenReturn(Optional.of(state));
340         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
341
342         // when:
343         String selectedProgram = deviceState.getSelectedProgram().get();
344         long selectedProgramId = deviceState.getSelectedProgramId().get();
345
346         // then:
347         assertEquals("Washing", selectedProgram);
348         assertEquals(3L, selectedProgramId);
349     }
350
351     @Test
352     public void testReturnValuesWhenProgramPhaseIsEmpty() {
353         // given:
354         State state = mock(State.class);
355         when(state.getProgramPhase()).thenReturn(Optional.empty());
356
357         Device device = mock(Device.class);
358         when(device.getState()).thenReturn(Optional.of(state));
359         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
360
361         // when:
362         Optional<String> programPhase = deviceState.getProgramPhase();
363         Optional<Integer> programPhaseRaw = deviceState.getProgramPhaseRaw();
364
365         // then:
366         assertFalse(programPhase.isPresent());
367         assertFalse(programPhaseRaw.isPresent());
368     }
369
370     @Test
371     public void testReturnValuesWhenProgramPhaseValueLocalizedIsEmpty() {
372         // given:
373         ProgramPhase programPhaseMock = mock(ProgramPhase.class);
374         when(programPhaseMock.getValueLocalized()).thenReturn(Optional.empty());
375
376         State state = mock(State.class);
377         when(state.getProgramPhase()).thenReturn(Optional.of(programPhaseMock));
378
379         Device device = mock(Device.class);
380         when(device.getState()).thenReturn(Optional.of(state));
381         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
382
383         // when:
384         Optional<String> programPhase = deviceState.getProgramPhase();
385         Optional<Integer> programPhaseRaw = deviceState.getProgramPhaseRaw();
386
387         // then:
388         assertFalse(programPhase.isPresent());
389         assertFalse(programPhaseRaw.isPresent());
390     }
391
392     @Test
393     public void testReturnValuesWhenProgramPhaseValueLocalizedIsNotNull() {
394         // given:
395         ProgramPhase programPhaseMock = mock(ProgramPhase.class);
396         when(programPhaseMock.getValueLocalized()).thenReturn(Optional.of("Spülen"));
397         when(programPhaseMock.getValueRaw()).thenReturn(Optional.of(4));
398
399         State state = mock(State.class);
400         Status status = mock(Status.class);
401         Device device = mock(Device.class);
402         when(state.getStatus()).thenReturn(Optional.of(status));
403         when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
404         when(state.getProgramPhase()).thenReturn(Optional.of(programPhaseMock));
405         when(device.getState()).thenReturn(Optional.of(state));
406         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
407
408         // when:
409         String programPhase = deviceState.getProgramPhase().get();
410         int programPhaseRaw = deviceState.getProgramPhaseRaw().get();
411
412         // then:
413         assertEquals("Spülen", programPhase);
414         assertEquals(4, programPhaseRaw);
415     }
416
417     @Test
418     public void testReturnValuesWhenDryingStepIsEmpty() {
419         // given:
420         State state = mock(State.class);
421         when(state.getDryingStep()).thenReturn(Optional.empty());
422
423         Device device = mock(Device.class);
424         when(device.getState()).thenReturn(Optional.of(state));
425         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
426
427         // when:
428         Optional<String> dryingTarget = deviceState.getDryingTarget();
429         Optional<Integer> dryingTargetRaw = deviceState.getDryingTargetRaw();
430
431         // then:
432         assertFalse(dryingTarget.isPresent());
433         assertFalse(dryingTargetRaw.isPresent());
434     }
435
436     @Test
437     public void testReturnValuesWhenDryingStepValueLocalizedIsEmpty() {
438         // given:
439         DryingStep dryingStep = mock(DryingStep.class);
440         when(dryingStep.getValueLocalized()).thenReturn(Optional.empty());
441         when(dryingStep.getValueRaw()).thenReturn(Optional.empty());
442
443         State state = mock(State.class);
444         when(state.getDryingStep()).thenReturn(Optional.of(dryingStep));
445
446         Device device = mock(Device.class);
447         when(device.getState()).thenReturn(Optional.of(state));
448         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
449
450         // when:
451         Optional<String> dryingTarget = deviceState.getDryingTarget();
452         Optional<Integer> dryingTargetRaw = deviceState.getDryingTargetRaw();
453
454         // then:
455         assertFalse(dryingTarget.isPresent());
456         assertFalse(dryingTargetRaw.isPresent());
457     }
458
459     @Test
460     public void testReturnValuesWhenDryingStepValueLocalizedIsNotNull() {
461         // given:
462         DryingStep dryingStep = mock(DryingStep.class);
463         when(dryingStep.getValueLocalized()).thenReturn(Optional.of("Hot"));
464         when(dryingStep.getValueRaw()).thenReturn(Optional.of(5));
465
466         State state = mock(State.class);
467         Device device = mock(Device.class);
468         Status status = mock(Status.class);
469         when(state.getDryingStep()).thenReturn(Optional.of(dryingStep));
470         when(state.getStatus()).thenReturn(Optional.of(status));
471         when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
472         when(device.getState()).thenReturn(Optional.of(state));
473         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
474
475         // when:
476         String dryingTarget = deviceState.getDryingTarget().get();
477         int dryingTargetRaw = deviceState.getDryingTargetRaw().get();
478
479         // then:
480         assertEquals("Hot", dryingTarget);
481         assertEquals(5, dryingTargetRaw);
482     }
483
484     @Test
485     public void testReturnValuesPreHeatFinishedWhenStateIsNotRunning() {
486         // given:
487         Temperature targetTemperature = mock(Temperature.class);
488         when(targetTemperature.getValueLocalized()).thenReturn(Optional.of(0));
489         Temperature currentTemperature = mock(Temperature.class);
490         when(currentTemperature.getValueLocalized()).thenReturn(Optional.of(0));
491
492         Status status = mock(Status.class);
493         when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
494
495         State state = mock(State.class);
496         when(state.getTargetTemperature()).thenReturn(Arrays.asList(targetTemperature));
497         when(state.getTemperature()).thenReturn(Arrays.asList(currentTemperature));
498         when(state.getStatus()).thenReturn(Optional.of(status));
499
500         Device device = mock(Device.class);
501         when(device.getState()).thenReturn(Optional.of(state));
502
503         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
504
505         // when:
506         Optional<Boolean> hasPreHeatFinished = deviceState.hasPreHeatFinished();
507
508         // then:
509         assertFalse(hasPreHeatFinished.get());
510     }
511
512     @Test
513     public void testReturnValuesPreHeatFinishedWhenTargetTemperatureIsEmpty() {
514         // given:
515         Temperature targetTemperature = mock(Temperature.class);
516         when(targetTemperature.getValueLocalized()).thenReturn(Optional.empty());
517         Temperature currentTemperature = mock(Temperature.class);
518         when(currentTemperature.getValueLocalized()).thenReturn(Optional.of(180));
519
520         Status status = mock(Status.class);
521         when(status.getValueRaw()).thenReturn(Optional.of(StateType.RUNNING.getCode()));
522
523         State state = mock(State.class);
524         when(state.getTargetTemperature()).thenReturn(Arrays.asList(targetTemperature));
525         when(state.getTemperature()).thenReturn(Arrays.asList(currentTemperature));
526         when(state.getStatus()).thenReturn(Optional.of(status));
527
528         Device device = mock(Device.class);
529         when(device.getState()).thenReturn(Optional.of(state));
530
531         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
532
533         // when:
534         Optional<Boolean> hasPreHeatFinished = deviceState.hasPreHeatFinished();
535
536         // then:
537         assertFalse(hasPreHeatFinished.isPresent());
538     }
539
540     @Test
541     public void testReturnValuesPreHeatFinishedWhenCurrentTemperatureIsEmpty() {
542         // given:
543         Temperature targetTemperature = mock(Temperature.class);
544         when(targetTemperature.getValueLocalized()).thenReturn(Optional.of(180));
545         Temperature currentTemperature = mock(Temperature.class);
546         when(currentTemperature.getValueLocalized()).thenReturn(Optional.empty());
547
548         Status status = mock(Status.class);
549         when(status.getValueRaw()).thenReturn(Optional.of(StateType.RUNNING.getCode()));
550
551         State state = mock(State.class);
552         when(state.getTargetTemperature()).thenReturn(Arrays.asList(targetTemperature));
553         when(state.getTemperature()).thenReturn(Arrays.asList(currentTemperature));
554         when(state.getStatus()).thenReturn(Optional.of(status));
555
556         Device device = mock(Device.class);
557         when(device.getState()).thenReturn(Optional.of(state));
558
559         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
560
561         // when:
562         Optional<Boolean> hasPreHeatFinished = deviceState.hasPreHeatFinished();
563
564         // then:
565         assertFalse(hasPreHeatFinished.isPresent());
566     }
567
568     @Test
569     public void testReturnValuesPreHeatFinishedWhenPreHeatingHasFinished() {
570         // given:
571         Temperature targetTemperature = mock(Temperature.class);
572         when(targetTemperature.getValueLocalized()).thenReturn(Optional.of(180));
573         Temperature currentTemperature = mock(Temperature.class);
574         when(currentTemperature.getValueLocalized()).thenReturn(Optional.of(180));
575
576         Status status = mock(Status.class);
577         when(status.getValueRaw()).thenReturn(Optional.of(StateType.RUNNING.getCode()));
578
579         State state = mock(State.class);
580         when(state.getTargetTemperature()).thenReturn(Arrays.asList(targetTemperature));
581         when(state.getTemperature()).thenReturn(Arrays.asList(currentTemperature));
582         when(state.getStatus()).thenReturn(Optional.of(status));
583
584         Device device = mock(Device.class);
585         when(device.getState()).thenReturn(Optional.of(state));
586
587         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
588
589         // when:
590         Optional<Boolean> hasPreHeatFinished = deviceState.hasPreHeatFinished();
591
592         // then:
593         assertTrue(hasPreHeatFinished.get());
594     }
595
596     @Test
597     public void testReturnValuesPreHeatFinishedWhenPreHeatingHasNotFinished() {
598         // given:
599         Temperature targetTemperature = mock(Temperature.class);
600         when(targetTemperature.getValueLocalized()).thenReturn(Optional.of(180));
601         Temperature currentTemperature = mock(Temperature.class);
602         when(currentTemperature.getValueLocalized()).thenReturn(Optional.of(179));
603
604         Status status = mock(Status.class);
605         when(status.getValueRaw()).thenReturn(Optional.of(StateType.RUNNING.getCode()));
606
607         State state = mock(State.class);
608         when(state.getTargetTemperature()).thenReturn(Arrays.asList(targetTemperature));
609         when(state.getTemperature()).thenReturn(Arrays.asList(currentTemperature));
610         when(state.getStatus()).thenReturn(Optional.of(status));
611
612         Device device = mock(Device.class);
613         when(device.getState()).thenReturn(Optional.of(state));
614
615         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
616
617         // when:
618         Optional<Boolean> hasPreHeatFinished = deviceState.hasPreHeatFinished();
619
620         // then:
621         assertFalse(hasPreHeatFinished.get());
622     }
623
624     @Test
625     public void testReturnValuesWhenTargetTemperatureIsEmpty() {
626         // given:
627         State state = mock(State.class);
628         when(state.getTargetTemperature()).thenReturn(Collections.emptyList());
629
630         Device device = mock(Device.class);
631         when(device.getState()).thenReturn(Optional.of(state));
632         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
633
634         // when:
635         Optional<Integer> targetTemperature = deviceState.getTargetTemperature(0);
636
637         // then:
638         assertFalse(targetTemperature.isPresent());
639     }
640
641     @Test
642     public void testReturnValuesWhenTargetTemperatureIndexIsOutOfRange() {
643         // given:
644         Status status = mock(Status.class);
645         when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
646
647         State state = mock(State.class);
648         when(state.getTargetTemperature()).thenReturn(new LinkedList<>());
649         when(state.getStatus()).thenReturn(Optional.of(status));
650
651         Device device = mock(Device.class);
652         when(device.getState()).thenReturn(Optional.of(state));
653         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
654
655         // when:
656         Optional<Integer> targetTemperature = deviceState.getTargetTemperature(0);
657
658         // then:
659         assertFalse(targetTemperature.isPresent());
660     }
661
662     @Test
663     public void testReturnValuesWhenTargetTemperatureValueLocalizedIsEmpty() {
664         // given:
665         Status status = mock(Status.class);
666         when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
667
668         Temperature temperature = mock(Temperature.class);
669         when(temperature.getValueLocalized()).thenReturn(Optional.empty());
670
671         State state = mock(State.class);
672         when(state.getTargetTemperature()).thenReturn(Arrays.asList(temperature));
673         when(state.getStatus()).thenReturn(Optional.of(status));
674
675         Device device = mock(Device.class);
676         when(device.getState()).thenReturn(Optional.of(state));
677         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
678
679         // when:
680         Optional<Integer> targetTemperature = deviceState.getTargetTemperature(0);
681
682         // then:
683         assertFalse(targetTemperature.isPresent());
684     }
685
686     @Test
687     public void testReturnValuesWhenTargetTemperatureValueLocalizedIsValid() {
688         // given:
689         Temperature temperature = mock(Temperature.class);
690         when(temperature.getValueLocalized()).thenReturn(Optional.of(20));
691
692         State state = mock(State.class);
693         Status status = mock(Status.class);
694         Device device = mock(Device.class);
695         when(state.getStatus()).thenReturn(Optional.of(status));
696         when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
697         when(state.getTargetTemperature()).thenReturn(Arrays.asList(temperature));
698         when(device.getState()).thenReturn(Optional.of(state));
699         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
700
701         // when:
702         Integer targetTemperature = deviceState.getTargetTemperature(0).get();
703
704         // then:
705         assertEquals(Integer.valueOf(20), targetTemperature);
706     }
707
708     @Test
709     public void testReturnValuesWhenTemperatureIsEmpty() {
710         // given:
711         Status status = mock(Status.class);
712         when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
713
714         State state = mock(State.class);
715         when(state.getTemperature()).thenReturn(Collections.emptyList());
716         when(state.getStatus()).thenReturn(Optional.of(status));
717
718         Device device = mock(Device.class);
719         when(device.getState()).thenReturn(Optional.of(state));
720         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
721
722         // when:
723         Optional<Integer> temperature = deviceState.getTemperature(0);
724
725         // then:
726         assertFalse(temperature.isPresent());
727     }
728
729     @Test
730     public void testReturnValuesWhenVentilationStepIsEmpty() {
731         // given:
732         State state = mock(State.class);
733         when(state.getVentilationStep()).thenReturn(Optional.empty());
734
735         Device device = mock(Device.class);
736         when(device.getState()).thenReturn(Optional.of(state));
737         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
738
739         // when:
740         Optional<String> ventilationStep = deviceState.getVentilationStep();
741         Optional<Integer> ventilationStepRaw = deviceState.getVentilationStepRaw();
742
743         // then:
744         assertFalse(ventilationStep.isPresent());
745         assertFalse(ventilationStepRaw.isPresent());
746     }
747
748     @Test
749     public void testReturnValuesWhenTemperatureIndexIsOutOfRange() {
750         // given:
751         Status status = mock(Status.class);
752         when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
753
754         State state = mock(State.class);
755         when(state.getTemperature()).thenReturn(new LinkedList<>());
756         when(state.getStatus()).thenReturn(Optional.of(status));
757
758         Device device = mock(Device.class);
759         when(device.getState()).thenReturn(Optional.of(state));
760         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
761
762         // when:
763         Optional<Integer> temperature = deviceState.getTemperature(-1);
764
765         // then:
766         assertFalse(temperature.isPresent());
767     }
768
769     @Test
770     public void testReturnValuesWhenTemperatureValueLocalizedIsEmpty() {
771         // given:
772         Status status = mock(Status.class);
773         when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
774
775         Temperature temperatureMock = mock(Temperature.class);
776         when(temperatureMock.getValueLocalized()).thenReturn(Optional.empty());
777
778         State state = mock(State.class);
779         when(state.getTemperature()).thenReturn(Arrays.asList(temperatureMock));
780         when(state.getStatus()).thenReturn(Optional.of(status));
781
782         Device device = mock(Device.class);
783         when(device.getState()).thenReturn(Optional.of(state));
784         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
785
786         // when:
787         Optional<Integer> temperature = deviceState.getTemperature(0);
788
789         // then:
790         assertFalse(temperature.isPresent());
791     }
792
793     @Test
794     public void testReturnValuesWhenTemperatureValueLocalizedIsValid() {
795         // given:
796         Temperature temperatureMock = mock(Temperature.class);
797         when(temperatureMock.getValueLocalized()).thenReturn(Optional.of(10));
798
799         State state = mock(State.class);
800         Device device = mock(Device.class);
801         Status status = mock(Status.class);
802         when(state.getTemperature()).thenReturn(Arrays.asList(temperatureMock));
803         when(state.getStatus()).thenReturn(Optional.of(status));
804         when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
805         when(device.getState()).thenReturn(Optional.of(state));
806         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
807
808         // when:
809         Integer temperature = deviceState.getTemperature(0).get();
810
811         // then:
812         assertEquals(Integer.valueOf(10), temperature);
813     }
814
815     @Test
816     public void testReturnValuesWhenPlatStepIndexIsOutOfRange() {
817         // given:
818         Status status = mock(Status.class);
819         when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
820
821         State state = mock(State.class);
822         when(state.getPlateStep()).thenReturn(Collections.emptyList());
823         when(state.getStatus()).thenReturn(Optional.of(status));
824
825         Device device = mock(Device.class);
826         when(device.getState()).thenReturn(Optional.of(state));
827         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
828
829         // when:
830         int plateStepCount = deviceState.getPlateStepCount().get();
831         Optional<String> plateStep = deviceState.getPlateStep(0);
832         Optional<Integer> plateStepRaw = deviceState.getPlateStepRaw(0);
833
834         // then:
835         assertEquals(0, plateStepCount);
836         assertFalse(plateStep.isPresent());
837         assertFalse(plateStepRaw.isPresent());
838     }
839
840     @Test
841     public void testReturnValuesWhenPlateStepValueIsEmpty() {
842         // given:
843         Status status = mock(Status.class);
844         when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
845
846         PlateStep plateStepMock = mock(PlateStep.class);
847         when(plateStepMock.getValueRaw()).thenReturn(Optional.empty());
848         when(plateStepMock.getValueLocalized()).thenReturn(Optional.empty());
849
850         State state = mock(State.class);
851         when(state.getPlateStep()).thenReturn(Collections.singletonList(plateStepMock));
852         when(state.getStatus()).thenReturn(Optional.of(status));
853
854         Device device = mock(Device.class);
855         when(device.getState()).thenReturn(Optional.of(state));
856         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
857
858         // when:
859         int plateStepCount = deviceState.getPlateStepCount().get();
860         Optional<String> plateStep = deviceState.getPlateStep(0);
861         Optional<Integer> plateStepRaw = deviceState.getPlateStepRaw(0);
862
863         // then:
864         assertEquals(1, plateStepCount);
865         assertFalse(plateStep.isPresent());
866         assertFalse(plateStepRaw.isPresent());
867     }
868
869     @Test
870     public void testReturnValuesWhenPlateStepValueIsValid() {
871         // given:
872         PlateStep plateStepMock = mock(PlateStep.class);
873         when(plateStepMock.getValueRaw()).thenReturn(Optional.of(2));
874         when(plateStepMock.getValueLocalized()).thenReturn(Optional.of("1."));
875
876         State state = mock(State.class);
877         Status status = mock(Status.class);
878         Device device = mock(Device.class);
879         when(state.getStatus()).thenReturn(Optional.of(status));
880         when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
881         when(state.getPlateStep()).thenReturn(Arrays.asList(plateStepMock));
882         when(device.getState()).thenReturn(Optional.of(state));
883         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
884
885         // when:
886         int plateStepCount = deviceState.getPlateStepCount().get();
887         String plateStep = deviceState.getPlateStep(0).get();
888         int plateStepRaw = deviceState.getPlateStepRaw(0).get();
889
890         // then:
891         assertEquals(1, plateStepCount);
892         assertEquals("1.", plateStep);
893         assertEquals(2, plateStepRaw);
894     }
895
896     @Test
897     public void testReturnValuesWhenRemainingTimeIsEmpty() {
898         // given:
899         State state = mock(State.class);
900         when(state.getRemainingTime()).thenReturn(Optional.empty());
901         when(state.getElapsedTime()).thenReturn(Optional.of(Arrays.asList(0, 0)));
902
903         Device device = mock(Device.class);
904         when(device.getState()).thenReturn(Optional.of(state));
905         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
906
907         // when:
908         Optional<Integer> progress = deviceState.getProgress();
909
910         // then:
911         assertFalse(progress.isPresent());
912     }
913
914     @Test
915     public void testReturnValuesWhenRemainingTimeSizeIsNotTwo() {
916         // given:
917         Status status = mock(Status.class);
918         when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
919
920         State state = mock(State.class);
921         when(state.getRemainingTime()).thenReturn(Optional.of(Arrays.asList(2)));
922         when(state.getElapsedTime()).thenReturn(Optional.of(Arrays.asList(0, 0)));
923         when(state.getStatus()).thenReturn(Optional.of(status));
924
925         Device device = mock(Device.class);
926         when(device.getState()).thenReturn(Optional.of(state));
927         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
928
929         // when:
930         Optional<Integer> progress = deviceState.getProgress();
931
932         // then:
933         assertFalse(progress.isPresent());
934     }
935
936     @Test
937     public void testReturnValuesWhenRemoteEnableIsEmpty() {
938         // given:
939         State state = mock(State.class);
940         when(state.getRemoteEnable()).thenReturn(Optional.empty());
941
942         Device device = mock(Device.class);
943         when(device.getState()).thenReturn(Optional.of(state));
944         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
945
946         // when:
947         Optional<Boolean> remoteControlEnabled = deviceState.isRemoteControlEnabled();
948
949         // then:
950         assertFalse(remoteControlEnabled.isPresent());
951     }
952
953     @Test
954     public void testReturnValuesWhenFullRemoteControlIsEmpty() {
955         // given:
956         RemoteEnable remoteEnable = mock(RemoteEnable.class);
957         when(remoteEnable.getFullRemoteControl()).thenReturn(Optional.empty());
958
959         State state = mock(State.class);
960         when(state.getRemoteEnable()).thenReturn(Optional.of(remoteEnable));
961
962         Device device = mock(Device.class);
963         when(device.getState()).thenReturn(Optional.of(state));
964         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
965
966         // when:
967         Optional<Boolean> remoteControlEnabled = deviceState.isRemoteControlEnabled();
968
969         // then:
970         assertFalse(remoteControlEnabled.isPresent());
971     }
972
973     @Test
974     public void testReturnValuesWhenFullRemoteControlIsNotNull() {
975         // given:
976         RemoteEnable remoteEnable = mock(RemoteEnable.class);
977         when(remoteEnable.getFullRemoteControl()).thenReturn(Optional.of(true));
978
979         State state = mock(State.class);
980         when(state.getRemoteEnable()).thenReturn(Optional.of(remoteEnable));
981
982         Device device = mock(Device.class);
983         when(device.getState()).thenReturn(Optional.of(state));
984         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
985
986         // when:
987         Boolean remoteControlEnabled = deviceState.isRemoteControlEnabled().get();
988
989         // then:
990         assertTrue(remoteControlEnabled);
991     }
992
993     @Test
994     public void testReturnValuesWhenElapsedTimeIsEmpty() {
995         // given:
996         Status status = mock(Status.class);
997         when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
998
999         State state = mock(State.class);
1000         when(state.getElapsedTime()).thenReturn(Optional.empty());
1001         when(state.getRemainingTime()).thenReturn(Optional.of(Arrays.asList(0, 0)));
1002         when(state.getStatus()).thenReturn(Optional.of(status));
1003
1004         Device device = mock(Device.class);
1005         when(device.getState()).thenReturn(Optional.of(state));
1006         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1007
1008         // when:
1009         Optional<Integer> progress = deviceState.getProgress();
1010
1011         // then:
1012         assertFalse(progress.isPresent());
1013     }
1014
1015     @Test
1016     public void testReturnValuesWhenElapsedTimeSizeIsNotTwo() {
1017         // given:
1018         Status status = mock(Status.class);
1019         when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1020
1021         State state = mock(State.class);
1022         when(state.getElapsedTime()).thenReturn(Optional.of(Arrays.asList(0)));
1023         when(state.getRemainingTime()).thenReturn(Optional.of(Arrays.asList(0, 0)));
1024         when(state.getStatus()).thenReturn(Optional.of(status));
1025
1026         Device device = mock(Device.class);
1027         when(device.getState()).thenReturn(Optional.of(state));
1028         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1029
1030         // when:
1031         Optional<Integer> progress = deviceState.getProgress();
1032
1033         // then:
1034         assertFalse(progress.isPresent());
1035     }
1036
1037     @Test
1038     public void testReturnValuesWhenElapsedTimeAndRemainingTimeIsZero() {
1039         // given:
1040         Status status = mock(Status.class);
1041         when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1042
1043         State state = mock(State.class);
1044         when(state.getElapsedTime()).thenReturn(Optional.of(Arrays.asList(0, 0)));
1045         when(state.getRemainingTime()).thenReturn(Optional.of(Arrays.asList(0, 0)));
1046         when(state.getStatus()).thenReturn(Optional.of(status));
1047
1048         Device device = mock(Device.class);
1049         when(device.getState()).thenReturn(Optional.of(state));
1050         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1051
1052         // when:
1053         Optional<Integer> progress = deviceState.getProgress();
1054
1055         // then:
1056         assertFalse(progress.isPresent());
1057     }
1058
1059     @Test
1060     public void whenElapsedTimeIsNotPresentThenEmptyIsReturned() {
1061         // given:
1062         Status status = mock(Status.class);
1063         when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1064
1065         State state = mock(State.class);
1066         when(state.getStatus()).thenReturn(Optional.of(status));
1067         when(state.getElapsedTime()).thenReturn(Optional.empty());
1068
1069         Device device = mock(Device.class);
1070         when(device.getState()).thenReturn(Optional.of(state));
1071
1072         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1073
1074         // when:
1075         Optional<Integer> elapsedTime = deviceState.getElapsedTime();
1076
1077         // then:
1078         assertFalse(elapsedTime.isPresent());
1079     }
1080
1081     @Test
1082     public void whenElapsedTimeIsAnEmptyListThenEmptyIsReturned() {
1083         // given:
1084         Status status = mock(Status.class);
1085         when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1086
1087         State state = mock(State.class);
1088         when(state.getStatus()).thenReturn(Optional.of(status));
1089         when(state.getElapsedTime()).thenReturn(Optional.of(Collections.emptyList()));
1090
1091         Device device = mock(Device.class);
1092         when(device.getState()).thenReturn(Optional.of(state));
1093
1094         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1095
1096         // when:
1097         Optional<Integer> elapsedTime = deviceState.getElapsedTime();
1098
1099         // then:
1100         assertFalse(elapsedTime.isPresent());
1101     }
1102
1103     @Test
1104     public void whenElapsedTimeHasOnlyOneElementThenEmptyIsReturned() {
1105         // given:
1106         Status status = mock(Status.class);
1107         when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1108
1109         State state = mock(State.class);
1110         when(state.getStatus()).thenReturn(Optional.of(status));
1111         when(state.getElapsedTime()).thenReturn(Optional.of(Collections.singletonList(2)));
1112
1113         Device device = mock(Device.class);
1114         when(device.getState()).thenReturn(Optional.of(state));
1115
1116         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1117
1118         // when:
1119         Optional<Integer> elapsedTime = deviceState.getElapsedTime();
1120
1121         // then:
1122         assertFalse(elapsedTime.isPresent());
1123     }
1124
1125     @Test
1126     public void whenElapsedTimeHasThreeElementsThenEmptyIsReturned() {
1127         // given:
1128         Status status = mock(Status.class);
1129         when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1130
1131         State state = mock(State.class);
1132         when(state.getStatus()).thenReturn(Optional.of(status));
1133         when(state.getElapsedTime()).thenReturn(Optional.of(Arrays.asList(1, 2, 3)));
1134
1135         Device device = mock(Device.class);
1136         when(device.getState()).thenReturn(Optional.of(state));
1137
1138         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1139
1140         // when:
1141         Optional<Integer> elapsedTime = deviceState.getElapsedTime();
1142
1143         // then:
1144         assertFalse(elapsedTime.isPresent());
1145     }
1146
1147     @Test
1148     public void whenElapsedTimeHasTwoElementsThenTheTotalNumberOfSecondsIsReturned() {
1149         // given:
1150         Status status = mock(Status.class);
1151         when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1152
1153         State state = mock(State.class);
1154         when(state.getStatus()).thenReturn(Optional.of(status));
1155         when(state.getElapsedTime()).thenReturn(Optional.of(Arrays.asList(1, 2)));
1156
1157         Device device = mock(Device.class);
1158         when(device.getState()).thenReturn(Optional.of(state));
1159
1160         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1161
1162         // when:
1163         Optional<Integer> elapsedTime = deviceState.getElapsedTime();
1164
1165         // then:
1166         assertTrue(elapsedTime.isPresent());
1167         assertEquals(Integer.valueOf((60 + 2) * 60), elapsedTime.get());
1168     }
1169
1170     @Test
1171     public void whenDeviceIsInOffStateThenElapsedTimeIsEmpty() {
1172         // given:
1173         Status status = mock(Status.class);
1174         when(status.getValueRaw()).thenReturn(Optional.of(StateType.OFF.getCode()));
1175
1176         State state = mock(State.class);
1177         when(state.getStatus()).thenReturn(Optional.of(status));
1178         when(state.getElapsedTime()).thenReturn(Optional.of(Arrays.asList(1, 2)));
1179
1180         Device device = mock(Device.class);
1181         when(device.getState()).thenReturn(Optional.of(state));
1182
1183         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1184
1185         // when:
1186         Optional<Integer> elapsedTime = deviceState.getElapsedTime();
1187
1188         // then:
1189         assertFalse(elapsedTime.isPresent());
1190     }
1191
1192     @Test
1193     public void testReturnValuesWhenProgressIs50Percent() {
1194         // given:
1195         State state = mock(State.class);
1196         when(state.getElapsedTime()).thenReturn(Optional.of(Arrays.asList(0, 45)));
1197         when(state.getRemainingTime()).thenReturn(Optional.of(Arrays.asList(0, 45)));
1198
1199         Device device = mock(Device.class);
1200         Status status = mock(Status.class);
1201         when(state.getStatus()).thenReturn(Optional.of(status));
1202         when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1203         when(device.getState()).thenReturn(Optional.of(state));
1204         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1205
1206         // when:
1207         Integer progress = deviceState.getProgress().get();
1208
1209         // then:
1210         assertEquals(Integer.valueOf(50), progress);
1211     }
1212
1213     @Test
1214     public void testReturnValuesWhenProgressIs25Percent() {
1215         // given:
1216         State state = mock(State.class);
1217         when(state.getElapsedTime()).thenReturn(Optional.of(Arrays.asList(0, 15)));
1218         when(state.getRemainingTime()).thenReturn(Optional.of(Arrays.asList(0, 45)));
1219
1220         Device device = mock(Device.class);
1221         Status status = mock(Status.class);
1222         when(state.getStatus()).thenReturn(Optional.of(status));
1223         when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1224         when(device.getState()).thenReturn(Optional.of(state));
1225         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1226
1227         // when:
1228         Integer progress = deviceState.getProgress().get();
1229
1230         // then:
1231         assertEquals(Integer.valueOf(25), progress);
1232     }
1233
1234     @Test
1235     public void testReturnValuesWhenProgressIs0Percent() {
1236         // given:
1237         State state = mock(State.class);
1238         when(state.getElapsedTime()).thenReturn(Optional.of(Arrays.asList(0, 0)));
1239         when(state.getRemainingTime()).thenReturn(Optional.of(Arrays.asList(0, 45)));
1240
1241         Device device = mock(Device.class);
1242         Status status = mock(Status.class);
1243         when(state.getStatus()).thenReturn(Optional.of(status));
1244         when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1245         when(device.getState()).thenReturn(Optional.of(state));
1246         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1247
1248         // when:
1249         Integer progress = deviceState.getProgress().get();
1250
1251         // then:
1252         assertEquals(Integer.valueOf(0), progress);
1253     }
1254
1255     @Test
1256     public void testReturnValuesWhenSignalDoorIsEmpty() {
1257         // given:
1258         State state = mock(State.class);
1259         when(state.getSignalDoor()).thenReturn(Optional.empty());
1260
1261         Status status = mock(Status.class);
1262         when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1263         when(state.getStatus()).thenReturn(Optional.of(status));
1264
1265         Device device = mock(Device.class);
1266         when(device.getState()).thenReturn(Optional.of(state));
1267
1268         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1269
1270         // when:
1271         Optional<Boolean> doorState = deviceState.getDoorState();
1272         Optional<Boolean> doorAlarm = deviceState.getDoorAlarm();
1273
1274         // then:
1275         assertFalse(doorState.isPresent());
1276         assertFalse(doorAlarm.isPresent());
1277     }
1278
1279     @Test
1280     public void testReturnValuesWhenSignalDoorIsTrue() {
1281         // given:
1282         State state = mock(State.class);
1283         when(state.getSignalDoor()).thenReturn(Optional.of(true));
1284
1285         Status status = mock(Status.class);
1286         when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1287         when(state.getStatus()).thenReturn(Optional.of(status));
1288
1289         Device device = mock(Device.class);
1290         when(device.getState()).thenReturn(Optional.of(state));
1291
1292         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1293
1294         // when:
1295         Optional<Boolean> doorState = deviceState.getDoorState();
1296
1297         // then:
1298         assertTrue(doorState.get());
1299     }
1300
1301     @Test
1302     public void testReturnValuesWhenSignalDoorIsFalse() {
1303         // given:
1304         State state = mock(State.class);
1305         when(state.getSignalDoor()).thenReturn(Optional.of(false));
1306
1307         Status status = mock(Status.class);
1308         when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1309         when(state.getStatus()).thenReturn(Optional.of(status));
1310
1311         Device device = mock(Device.class);
1312         when(device.getState()).thenReturn(Optional.of(state));
1313
1314         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1315
1316         // when:
1317         Optional<Boolean> doorState = deviceState.getDoorState();
1318
1319         // then:
1320         assertFalse(doorState.get());
1321     }
1322
1323     @Test
1324     public void testReturnValuesWhenSignalFailureIsEmpty() {
1325         // given:
1326         State state = mock(State.class);
1327         when(state.getSignalDoor()).thenReturn(Optional.of(true));
1328         when(state.getSignalFailure()).thenReturn(Optional.empty());
1329
1330         Status status = mock(Status.class);
1331         when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1332         when(state.getStatus()).thenReturn(Optional.of(status));
1333
1334         Device device = mock(Device.class);
1335         when(device.getState()).thenReturn(Optional.of(state));
1336
1337         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1338
1339         // when:
1340         Optional<Boolean> doorAlarm = deviceState.getDoorAlarm();
1341
1342         // then:
1343         assertFalse(doorAlarm.isPresent());
1344     }
1345
1346     @Test
1347     public void testReturnValuesWhenDoorAlarmIsActive() {
1348         // given:
1349         State state = mock(State.class);
1350         when(state.getSignalDoor()).thenReturn(Optional.of(true));
1351         when(state.getSignalFailure()).thenReturn(Optional.of(true));
1352
1353         Status status = mock(Status.class);
1354         when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1355         when(state.getStatus()).thenReturn(Optional.of(status));
1356
1357         Device device = mock(Device.class);
1358         when(device.getState()).thenReturn(Optional.of(state));
1359
1360         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1361
1362         // when:
1363         Optional<Boolean> doorAlarm = deviceState.getDoorAlarm();
1364
1365         // then:
1366         assertTrue(doorAlarm.get());
1367     }
1368
1369     @Test
1370     public void testReturnValuesWhenDoorAlarmIsNotActiveBecauseOfNoDoorSignal() {
1371         // given:
1372         State state = mock(State.class);
1373         when(state.getSignalDoor()).thenReturn(Optional.of(false));
1374         when(state.getSignalFailure()).thenReturn(Optional.of(true));
1375
1376         Status status = mock(Status.class);
1377         when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1378         when(state.getStatus()).thenReturn(Optional.of(status));
1379
1380         Device device = mock(Device.class);
1381         when(device.getState()).thenReturn(Optional.of(state));
1382
1383         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1384
1385         // when:
1386         Optional<Boolean> doorAlarm = deviceState.getDoorAlarm();
1387
1388         // then:
1389         assertFalse(doorAlarm.get());
1390     }
1391
1392     @Test
1393     public void testReturnValuesWhenDoorAlarmIsNotActiveBecauseOfNoFailureSignal() {
1394         // given:
1395         State state = mock(State.class);
1396         when(state.getSignalDoor()).thenReturn(Optional.of(true));
1397         when(state.getSignalFailure()).thenReturn(Optional.of(false));
1398
1399         Status status = mock(Status.class);
1400         when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1401         when(state.getStatus()).thenReturn(Optional.of(status));
1402
1403         Device device = mock(Device.class);
1404         when(device.getState()).thenReturn(Optional.of(state));
1405
1406         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1407
1408         // when:
1409         Optional<Boolean> doorAlarm = deviceState.getDoorAlarm();
1410
1411         // then:
1412         assertFalse(doorAlarm.get());
1413     }
1414
1415     @Test
1416     public void testReturnValuesWhenIdentIsEmpty() {
1417         // given:
1418         Device device = mock(Device.class);
1419         when(device.getIdent()).thenReturn(Optional.empty());
1420         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1421
1422         // when:
1423         Optional<String> type = deviceState.getType();
1424         DeviceType rawType = deviceState.getRawType();
1425         Optional<String> deviceName = deviceState.getDeviceName();
1426         Optional<String> fabNumber = deviceState.getFabNumber();
1427         Optional<String> techType = deviceState.getTechType();
1428
1429         // then:
1430         assertFalse(type.isPresent());
1431         assertEquals(DeviceType.UNKNOWN, rawType);
1432         assertFalse(deviceName.isPresent());
1433         assertFalse(fabNumber.isPresent());
1434         assertFalse(techType.isPresent());
1435     }
1436
1437     @Test
1438     public void testReturnValuesWhenTypeIsEmpty() {
1439         // given:
1440         Ident ident = mock(Ident.class);
1441         when(ident.getType()).thenReturn(Optional.empty());
1442
1443         Device device = mock(Device.class);
1444         when(device.getIdent()).thenReturn(Optional.of(ident));
1445         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1446
1447         // when:
1448         Optional<String> type = deviceState.getType();
1449         DeviceType rawType = deviceState.getRawType();
1450
1451         // then:
1452         assertFalse(type.isPresent());
1453         assertEquals(DeviceType.UNKNOWN, rawType);
1454     }
1455
1456     @Test
1457     public void testReturnValuesWhenTypeValueLocalizedIsEmpty() {
1458         // given:
1459         Type typeMock = mock(Type.class);
1460         when(typeMock.getValueLocalized()).thenReturn(Optional.empty());
1461
1462         Ident ident = mock(Ident.class);
1463         when(ident.getType()).thenReturn(Optional.of(typeMock));
1464
1465         Device device = mock(Device.class);
1466         when(device.getIdent()).thenReturn(Optional.of(ident));
1467         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1468
1469         // when:
1470         Optional<String> type = deviceState.getType();
1471
1472         // then:
1473         assertFalse(type.isPresent());
1474     }
1475
1476     @Test
1477     public void testReturnValuesWhenTypeValueLocalizedIsNotNull() {
1478         // given:
1479         Type typeMock = mock(Type.class);
1480         when(typeMock.getValueLocalized()).thenReturn(Optional.of("Hood"));
1481
1482         Ident ident = mock(Ident.class);
1483         when(ident.getType()).thenReturn(Optional.of(typeMock));
1484
1485         Device device = mock(Device.class);
1486         when(device.getIdent()).thenReturn(Optional.of(ident));
1487         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1488
1489         // when:
1490         String type = deviceState.getType().get();
1491
1492         // then:
1493         assertEquals("Hood", type);
1494     }
1495
1496     @Test
1497     public void testReturnValuesWhenTypeValueRawIsNotNull() {
1498         // given:
1499         Type typeMock = mock(Type.class);
1500         when(typeMock.getValueRaw()).thenReturn(DeviceType.COFFEE_SYSTEM);
1501
1502         Ident ident = mock(Ident.class);
1503         when(ident.getType()).thenReturn(Optional.of(typeMock));
1504
1505         Device device = mock(Device.class);
1506         when(device.getIdent()).thenReturn(Optional.of(ident));
1507         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1508
1509         // when:
1510         DeviceType rawType = deviceState.getRawType();
1511
1512         // then:
1513         assertEquals(DeviceType.COFFEE_SYSTEM, rawType);
1514     }
1515
1516     @Test
1517     public void testReturnValuesWhenDeviceNameIsEmpty() {
1518         // given:
1519         Ident ident = mock(Ident.class);
1520         when(ident.getDeviceName()).thenReturn(Optional.empty());
1521
1522         Device device = mock(Device.class);
1523         when(device.getIdent()).thenReturn(Optional.of(ident));
1524         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1525
1526         // when:
1527         Optional<String> deviceName = deviceState.getDeviceName();
1528
1529         // then:
1530         assertFalse(deviceName.isPresent());
1531     }
1532
1533     @Test
1534     public void testReturnValuesWhenDeviceNameIsEmptyString() {
1535         // given:
1536         Ident ident = mock(Ident.class);
1537         when(ident.getDeviceName()).thenReturn(Optional.of(""));
1538
1539         Device device = mock(Device.class);
1540         when(device.getIdent()).thenReturn(Optional.of(ident));
1541         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1542
1543         // when:
1544         Optional<String> deviceName = deviceState.getDeviceName();
1545
1546         // then:
1547         assertFalse(deviceName.isPresent());
1548     }
1549
1550     @Test
1551     public void testReturnValuesWhenDeviceNameIsValid() {
1552         // given:
1553         Ident ident = mock(Ident.class);
1554         when(ident.getDeviceName()).thenReturn(Optional.of("MyWashingMachine"));
1555
1556         Device device = mock(Device.class);
1557         when(device.getIdent()).thenReturn(Optional.of(ident));
1558         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1559
1560         // when:
1561         Optional<String> deviceName = deviceState.getDeviceName();
1562
1563         // then:
1564         assertEquals(Optional.of("MyWashingMachine"), deviceName);
1565     }
1566
1567     @Test
1568     public void testReturnValuesWhenFabNumberIsNotNull() {
1569         // given:
1570         DeviceIdentLabel deviceIdentLabel = mock(DeviceIdentLabel.class);
1571         when(deviceIdentLabel.getFabNumber()).thenReturn(Optional.of("000061431659"));
1572
1573         Ident ident = mock(Ident.class);
1574         when(ident.getDeviceIdentLabel()).thenReturn(Optional.of(deviceIdentLabel));
1575
1576         Device device = mock(Device.class);
1577         when(device.getIdent()).thenReturn(Optional.of(ident));
1578         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1579
1580         // when:
1581         String fabNumber = deviceState.getFabNumber().get();
1582
1583         // then:
1584         assertEquals("000061431659", fabNumber);
1585     }
1586
1587     @Test
1588     public void testReturnValuesWhenTechTypeIsNotNull() {
1589         // given:
1590         DeviceIdentLabel deviceIdentLabel = mock(DeviceIdentLabel.class);
1591         when(deviceIdentLabel.getTechType()).thenReturn(Optional.of("XKM3100WEC"));
1592
1593         Ident ident = mock(Ident.class);
1594         when(ident.getDeviceIdentLabel()).thenReturn(Optional.of(deviceIdentLabel));
1595
1596         Device device = mock(Device.class);
1597         when(device.getIdent()).thenReturn(Optional.of(ident));
1598         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1599
1600         // when:
1601         String techType = deviceState.getTechType().get();
1602
1603         // then:
1604         assertEquals("XKM3100WEC", techType);
1605     }
1606
1607     @Test
1608     public void whenDeviceIsInFailureStateThenItHasAnError() {
1609         // given:
1610         Status status = mock(Status.class);
1611         when(status.getValueRaw()).thenReturn(Optional.of(StateType.FAILURE.getCode()));
1612
1613         State state = mock(State.class);
1614         when(state.getStatus()).thenReturn(Optional.of(status));
1615
1616         Device device = mock(Device.class);
1617         when(device.getState()).thenReturn(Optional.of(state));
1618         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1619
1620         // when:
1621         boolean hasError = deviceState.hasError();
1622
1623         // then:
1624         assertTrue(hasError);
1625     }
1626
1627     @Test
1628     public void whenDeviceIsInRunningStateAndDoesNotSignalAFailureThenItHasNoError() {
1629         // given:
1630         Status status = mock(Status.class);
1631         when(status.getValueRaw()).thenReturn(Optional.of(StateType.RUNNING.getCode()));
1632
1633         State state = mock(State.class);
1634         when(state.getStatus()).thenReturn(Optional.of(status));
1635
1636         Device device = mock(Device.class);
1637         when(device.getState()).thenReturn(Optional.of(state));
1638         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1639
1640         // when:
1641         boolean hasError = deviceState.hasError();
1642
1643         // then:
1644         assertFalse(hasError);
1645     }
1646
1647     @Test
1648     public void whenDeviceSignalsAFailureThenItHasAnError() {
1649         // given:
1650         Status status = mock(Status.class);
1651         when(status.getValueRaw()).thenReturn(Optional.of(StateType.RUNNING.getCode()));
1652
1653         State state = mock(State.class);
1654         when(state.getStatus()).thenReturn(Optional.of(status));
1655         when(state.getSignalFailure()).thenReturn(Optional.of(true));
1656
1657         Device device = mock(Device.class);
1658         when(device.getState()).thenReturn(Optional.of(state));
1659         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1660
1661         // when:
1662         boolean hasError = deviceState.hasError();
1663
1664         // then:
1665         assertTrue(hasError);
1666     }
1667
1668     @Test
1669     public void testReturnValuesForHasInfoWhenSignalInfoIsEmpty() {
1670         // given:
1671         State state = mock(State.class);
1672         when(state.getSignalInfo()).thenReturn(Optional.empty());
1673
1674         Status status = mock(Status.class);
1675         when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1676         when(state.getStatus()).thenReturn(Optional.of(status));
1677
1678         Device device = mock(Device.class);
1679         when(device.getState()).thenReturn(Optional.of(state));
1680         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1681
1682         // when:
1683         boolean hasInfo = deviceState.hasInfo();
1684
1685         // then:
1686         assertFalse(hasInfo);
1687     }
1688
1689     @Test
1690     public void whenDeviceSignalsAnInfoThenItHasAnInfo() {
1691         // given:
1692         State state = mock(State.class);
1693         when(state.getSignalInfo()).thenReturn(Optional.of(true));
1694
1695         Status status = mock(Status.class);
1696         when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1697         when(state.getStatus()).thenReturn(Optional.of(status));
1698
1699         Device device = mock(Device.class);
1700         when(device.getState()).thenReturn(Optional.of(state));
1701         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1702
1703         // when:
1704         boolean hasInfo = deviceState.hasInfo();
1705
1706         // then:
1707         assertTrue(hasInfo);
1708     }
1709
1710     @Test
1711     public void whenDeviceSignalsNoInfoThenItHasNoInfo() {
1712         // given:
1713         State state = mock(State.class);
1714         when(state.getSignalInfo()).thenReturn(Optional.of(false));
1715
1716         Status status = mock(Status.class);
1717         when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1718         when(state.getStatus()).thenReturn(Optional.of(status));
1719
1720         Device device = mock(Device.class);
1721         when(device.getState()).thenReturn(Optional.of(state));
1722         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1723
1724         // when:
1725         boolean hasInfo = deviceState.hasInfo();
1726
1727         // then:
1728         assertFalse(hasInfo);
1729     }
1730
1731     @Test
1732     public void testReturnValuesForVentilationStep() {
1733         // given:
1734         VentilationStep ventilationStepMock = mock(VentilationStep.class);
1735         when(ventilationStepMock.getValueLocalized()).thenReturn(Optional.of("Step 1"));
1736         when(ventilationStepMock.getValueRaw()).thenReturn(Optional.of(1));
1737
1738         Status status = mock(Status.class);
1739         when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1740
1741         State state = mock(State.class);
1742         when(state.getVentilationStep()).thenReturn(Optional.of(ventilationStepMock));
1743         when(state.getStatus()).thenReturn(Optional.of(status));
1744
1745         Device device = mock(Device.class);
1746         when(device.getState()).thenReturn(Optional.of(state));
1747
1748         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1749
1750         // when:
1751         String ventilationStep = deviceState.getVentilationStep().get();
1752         int ventilationStepRaw = deviceState.getVentilationStepRaw().get();
1753
1754         // then:
1755         assertEquals("Step 1", ventilationStep);
1756         assertEquals(1, ventilationStepRaw);
1757     }
1758
1759     @Test
1760     public void testProgramPhaseWhenDeviceIsInOffState() {
1761         // given:
1762         ProgramPhase programPhase = mock(ProgramPhase.class);
1763         when(programPhase.getValueLocalized()).thenReturn(Optional.of("Washing"));
1764         when(programPhase.getValueRaw()).thenReturn(Optional.of(3));
1765
1766         Status status = mock(Status.class);
1767         when(status.getValueRaw()).thenReturn(Optional.of(StateType.OFF.getCode()));
1768
1769         State state = mock(State.class);
1770         when(state.getProgramPhase()).thenReturn(Optional.of(programPhase));
1771         when(state.getStatus()).thenReturn(Optional.of(status));
1772
1773         Device device = mock(Device.class);
1774         when(device.getState()).thenReturn(Optional.of(state));
1775
1776         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1777
1778         // when:
1779         Optional<String> phase = deviceState.getProgramPhase();
1780         Optional<Integer> phaseRaw = deviceState.getProgramPhaseRaw();
1781
1782         // then:
1783         assertFalse(phase.isPresent());
1784         assertFalse(phaseRaw.isPresent());
1785     }
1786
1787     @Test
1788     public void testDryingTargetWhenDeviceIsInOffState() {
1789         // given:
1790         DryingStep dryingStep = mock(DryingStep.class);
1791         when(dryingStep.getValueLocalized()).thenReturn(Optional.of("Schranktrocken"));
1792         when(dryingStep.getValueRaw()).thenReturn(Optional.of(3));
1793
1794         Status status = mock(Status.class);
1795         when(status.getValueRaw()).thenReturn(Optional.of(StateType.OFF.getCode()));
1796
1797         State state = mock(State.class);
1798         when(state.getDryingStep()).thenReturn(Optional.of(dryingStep));
1799         when(state.getStatus()).thenReturn(Optional.of(status));
1800
1801         Device device = mock(Device.class);
1802         when(device.getState()).thenReturn(Optional.of(state));
1803
1804         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1805
1806         // when:
1807         Optional<String> dryingTarget = deviceState.getDryingTarget();
1808         Optional<Integer> dryingTargetRaw = deviceState.getDryingTargetRaw();
1809
1810         // then:
1811         assertFalse(dryingTarget.isPresent());
1812         assertFalse(dryingTargetRaw.isPresent());
1813     }
1814
1815     @Test
1816     public void testVentilationStepWhenDeviceIsInOffState() {
1817         // given:
1818         VentilationStep ventilationStep = mock(VentilationStep.class);
1819         when(ventilationStep.getValueLocalized()).thenReturn(Optional.of("Stufe 1"));
1820         when(ventilationStep.getValueRaw()).thenReturn(Optional.of(1));
1821
1822         Status status = mock(Status.class);
1823         when(status.getValueRaw()).thenReturn(Optional.of(StateType.OFF.getCode()));
1824
1825         State state = mock(State.class);
1826         when(state.getVentilationStep()).thenReturn(Optional.of(ventilationStep));
1827         when(state.getStatus()).thenReturn(Optional.of(status));
1828
1829         Device device = mock(Device.class);
1830         when(device.getState()).thenReturn(Optional.of(state));
1831
1832         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1833
1834         // when:
1835         Optional<String> step = deviceState.getVentilationStep();
1836         Optional<Integer> stepRaw = deviceState.getVentilationStepRaw();
1837
1838         // then:
1839         assertFalse(step.isPresent());
1840         assertFalse(stepRaw.isPresent());
1841     }
1842
1843     @Test
1844     public void testReturnValuesWhenDeviceIsInOffState() {
1845         // given:
1846         Device device = mock(Device.class);
1847         State state = mock(State.class);
1848         Status status = mock(Status.class);
1849
1850         when(device.getState()).thenReturn(Optional.of(state));
1851         when(state.getStatus()).thenReturn(Optional.of(status));
1852         when(status.getValueRaw()).thenReturn(Optional.of(StateType.OFF.getCode()));
1853         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1854
1855         // Test SelectedProgram:
1856         ProgramId programId = mock(ProgramId.class);
1857         when(state.getProgramId()).thenReturn(Optional.of(programId));
1858         when(programId.getValueLocalized()).thenReturn(Optional.of("Washing"));
1859         // when:
1860         Optional<String> selectedProgram = deviceState.getSelectedProgram();
1861         // then:
1862         assertFalse(selectedProgram.isPresent());
1863
1864         // Test TargetTemperature:
1865         Temperature targetTemperatureMock = mock(Temperature.class);
1866         when(state.getTargetTemperature()).thenReturn(Collections.singletonList(targetTemperatureMock));
1867         when(targetTemperatureMock.getValueLocalized()).thenReturn(Optional.of(200));
1868         // when:
1869         Optional<Integer> targetTemperature = deviceState.getTargetTemperature(0);
1870         // then:
1871         assertFalse(targetTemperature.isPresent());
1872
1873         // Test Temperature:
1874         Temperature temperature = mock(Temperature.class);
1875         when(state.getTemperature()).thenReturn(Collections.singletonList(temperature));
1876         when(temperature.getValueLocalized()).thenReturn(Optional.of(200));
1877         // when:
1878         Optional<Integer> t = deviceState.getTemperature(0);
1879         // then:
1880         assertFalse(t.isPresent());
1881
1882         // Test Progress:
1883         when(state.getElapsedTime()).thenReturn(Optional.of(Arrays.asList(0, 5)));
1884         when(state.getRemainingTime()).thenReturn(Optional.of(Arrays.asList(1, 5)));
1885         // when:
1886         Optional<Integer> progress = deviceState.getProgress();
1887         // then:
1888         assertFalse(progress.isPresent());
1889     }
1890
1891     @Test
1892     public void testWhenDeviceIsInOffStateThenGetSpinningSpeedReturnsNull() {
1893         // given:
1894         Status status = mock(Status.class);
1895         when(status.getValueRaw()).thenReturn(Optional.of(StateType.OFF.getCode()));
1896
1897         SpinningSpeed spinningSpeed = mock(SpinningSpeed.class);
1898         when(spinningSpeed.getValueRaw()).thenReturn(Optional.of(800));
1899         when(spinningSpeed.getValueLocalized()).thenReturn(Optional.of("800"));
1900         when(spinningSpeed.getUnit()).thenReturn(Optional.of("rpm"));
1901
1902         State state = mock(State.class);
1903         when(state.getStatus()).thenReturn(Optional.of(status));
1904         when(state.getSpinningSpeed()).thenReturn(Optional.of(spinningSpeed));
1905
1906         Device device = mock(Device.class);
1907         when(device.getState()).thenReturn(Optional.of(state));
1908
1909         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1910
1911         // when:
1912         Optional<String> speed = deviceState.getSpinningSpeed();
1913         Optional<Integer> speedRaw = deviceState.getSpinningSpeedRaw();
1914
1915         // then:
1916         assertFalse(speed.isPresent());
1917         assertFalse(speedRaw.isPresent());
1918     }
1919
1920     @Test
1921     public void testGetSpinningSpeedReturnsNullWhenSpinningSpeedIsEmpty() {
1922         // given:
1923         Status status = mock(Status.class);
1924         when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1925
1926         State state = mock(State.class);
1927         when(state.getStatus()).thenReturn(Optional.of(status));
1928         when(state.getSpinningSpeed()).thenReturn(Optional.empty());
1929
1930         Device device = mock(Device.class);
1931         when(device.getState()).thenReturn(Optional.of(state));
1932
1933         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1934
1935         // when:
1936         Optional<String> spinningSpeed = deviceState.getSpinningSpeed();
1937         Optional<Integer> spinningSpeedRaw = deviceState.getSpinningSpeedRaw();
1938
1939         // then:
1940         assertFalse(spinningSpeed.isPresent());
1941         assertFalse(spinningSpeedRaw.isPresent());
1942     }
1943
1944     @Test
1945     public void testGetSpinningSpeedReturnsNullWhenSpinningSpeedRawValueIsEmpty() {
1946         // given:
1947         Status status = mock(Status.class);
1948         when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1949
1950         SpinningSpeed spinningSpeedMock = mock(SpinningSpeed.class);
1951         when(spinningSpeedMock.getValueRaw()).thenReturn(Optional.empty());
1952         when(spinningSpeedMock.getValueLocalized()).thenReturn(Optional.of("1200"));
1953
1954         State state = mock(State.class);
1955         when(state.getStatus()).thenReturn(Optional.of(status));
1956         when(state.getSpinningSpeed()).thenReturn(Optional.of(spinningSpeedMock));
1957
1958         Device device = mock(Device.class);
1959         when(device.getState()).thenReturn(Optional.of(state));
1960
1961         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1962
1963         // when:
1964         Optional<String> spinningSpeed = deviceState.getSpinningSpeed();
1965         Optional<Integer> spinningSpeedRaw = deviceState.getSpinningSpeedRaw();
1966
1967         // then:
1968         assertFalse(spinningSpeed.isPresent());
1969         assertFalse(spinningSpeedRaw.isPresent());
1970     }
1971
1972     @Test
1973     public void testGetSpinningSpeedReturnsValidValueWhenSpinningSpeedRawValueIsNotNull() {
1974         // given:
1975         Status status = mock(Status.class);
1976         when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1977
1978         SpinningSpeed spinningSpeedMock = mock(SpinningSpeed.class);
1979         when(spinningSpeedMock.getValueRaw()).thenReturn(Optional.of(1200));
1980         when(spinningSpeedMock.getValueLocalized()).thenReturn(Optional.of("1200"));
1981
1982         State state = mock(State.class);
1983         when(state.getStatus()).thenReturn(Optional.of(status));
1984         when(state.getSpinningSpeed()).thenReturn(Optional.of(spinningSpeedMock));
1985
1986         Device device = mock(Device.class);
1987         when(device.getState()).thenReturn(Optional.of(state));
1988
1989         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1990
1991         // when:
1992         String spinningSpeed = deviceState.getSpinningSpeed().get();
1993         int spinningSpeedRaw = deviceState.getSpinningSpeedRaw().get();
1994
1995         // then:
1996         assertEquals("1200", spinningSpeed);
1997         assertEquals(1200, spinningSpeedRaw);
1998     }
1999
2000     @Test
2001     public void testGetLightStateWhenDeviceIsOff() {
2002         // given:
2003         Status status = mock(Status.class);
2004         when(status.getValueRaw()).thenReturn(Optional.of(StateType.OFF.getCode()));
2005
2006         State state = mock(State.class);
2007         when(state.getStatus()).thenReturn(Optional.of(status));
2008
2009         Device device = mock(Device.class);
2010         when(device.getState()).thenReturn(Optional.of(state));
2011
2012         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2013
2014         // when:
2015         Optional<Boolean> lightState = deviceState.getLightState();
2016
2017         // then:
2018         assertFalse(lightState.isPresent());
2019     }
2020
2021     @Test
2022     public void testGetLightStateWhenLightIsUnknown() {
2023         // given:
2024         Status status = mock(Status.class);
2025         when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
2026
2027         State state = mock(State.class);
2028         when(state.getStatus()).thenReturn(Optional.of(status));
2029         when(state.getLight()).thenReturn(Light.UNKNOWN);
2030
2031         Device device = mock(Device.class);
2032         when(device.getState()).thenReturn(Optional.of(state));
2033
2034         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2035
2036         // when:
2037         Optional<Boolean> lightState = deviceState.getLightState();
2038
2039         // then:
2040         assertFalse(lightState.isPresent());
2041     }
2042
2043     @Test
2044     public void testGetLightStateWhenLightIsEnabled() {
2045         // given:
2046         Status status = mock(Status.class);
2047         when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
2048
2049         State state = mock(State.class);
2050         when(state.getStatus()).thenReturn(Optional.of(status));
2051         when(state.getLight()).thenReturn(Light.ENABLE);
2052
2053         Device device = mock(Device.class);
2054         when(device.getState()).thenReturn(Optional.of(state));
2055
2056         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2057
2058         // when:
2059         Boolean lightState = deviceState.getLightState().get();
2060
2061         // then:
2062         assertEquals(Boolean.valueOf(true), lightState);
2063     }
2064
2065     @Test
2066     public void testGetLightStateWhenLightIsDisabled() {
2067         // given:
2068         Status status = mock(Status.class);
2069         when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
2070
2071         State state = mock(State.class);
2072         when(state.getStatus()).thenReturn(Optional.of(status));
2073         when(state.getLight()).thenReturn(Light.DISABLE);
2074
2075         Device device = mock(Device.class);
2076         when(device.getState()).thenReturn(Optional.of(state));
2077
2078         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2079
2080         // when:
2081         Boolean lightState = deviceState.getLightState().get();
2082
2083         // then:
2084         assertEquals(Boolean.valueOf(false), lightState);
2085     }
2086
2087     @Test
2088     public void testGetLightStateWhenLightIsNotSupported() {
2089         // given:
2090         Status status = mock(Status.class);
2091         when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
2092
2093         State state = mock(State.class);
2094         when(state.getStatus()).thenReturn(Optional.of(status));
2095         when(state.getLight()).thenReturn(Light.NOT_SUPPORTED);
2096
2097         Device device = mock(Device.class);
2098         when(device.getState()).thenReturn(Optional.of(state));
2099
2100         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2101
2102         // when:
2103         Optional<Boolean> lightState = deviceState.getLightState();
2104
2105         // then:
2106         assertFalse(lightState.isPresent());
2107     }
2108
2109     @Test
2110     public void testGetBatteryLevel() {
2111         // given:
2112         Status status = mock(Status.class);
2113         when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
2114
2115         State state = mock(State.class);
2116         when(state.getStatus()).thenReturn(Optional.of(status));
2117         when(state.getBatteryLevel()).thenReturn(Optional.of(4));
2118
2119         Device device = mock(Device.class);
2120         when(device.getState()).thenReturn(Optional.of(state));
2121
2122         DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2123
2124         // when:
2125         Integer batteryLevel = deviceState.getBatteryLevel().get();
2126
2127         // then:
2128         assertEquals(Integer.valueOf(4), batteryLevel);
2129     }
2130 }