2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.mielecloud.internal.webservice.api;
15 import static org.junit.jupiter.api.Assertions.*;
16 import static org.mockito.Mockito.*;
18 import java.util.Arrays;
19 import java.util.Collections;
20 import java.util.LinkedList;
21 import java.util.Optional;
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;
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
51 public class DeviceStateTest {
52 private static final String DEVICE_IDENTIFIER = "mac-f83001f37d45ffff";
55 public void testGetDeviceIdentifierReturnsDeviceIdentifier() {
57 Device device = mock(Device.class);
58 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
61 String deviceId = deviceState.getDeviceIdentifier();
64 assertEquals(DEVICE_IDENTIFIER, deviceId);
68 public void testReturnValuesWhenDeviceIsNull() {
70 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, null);
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();
99 Optional<String> deviceName = deviceState.getDeviceName();
100 Optional<String> fabNumber = deviceState.getFabNumber();
101 Optional<String> techType = deviceState.getTechType();
102 Optional<Integer> progress = deviceState.getProgress();
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());
137 public void testReturnValuesWhenStateIsNull() {
139 Device device = mock(Device.class);
140 when(device.getState()).thenReturn(Optional.empty());
141 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
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();
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());
195 public void testReturnValuesWhenStatusIsEmpty() {
197 State state = mock(State.class);
198 when(state.getStatus()).thenReturn(Optional.empty());
200 Device device = mock(Device.class);
201 when(device.getState()).thenReturn(Optional.of(state));
202 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
205 Optional<String> status = deviceState.getStatus();
206 Optional<Integer> statusRaw = deviceState.getStatusRaw();
207 Optional<StateType> stateType = deviceState.getStateType();
210 assertFalse(status.isPresent());
211 assertFalse(statusRaw.isPresent());
212 assertFalse(stateType.isPresent());
216 public void testReturnValuesWhenStatusValuesAreEmpty() {
218 Status statusMock = mock(Status.class);
219 when(statusMock.getValueLocalized()).thenReturn(Optional.empty());
220 when(statusMock.getValueRaw()).thenReturn(Optional.empty());
222 State state = mock(State.class);
223 when(state.getStatus()).thenReturn(Optional.of(statusMock));
225 Device device = mock(Device.class);
226 when(device.getState()).thenReturn(Optional.of(state));
227 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
230 Optional<String> status = deviceState.getStatus();
231 Optional<Integer> statusRaw = deviceState.getStatusRaw();
232 Optional<StateType> stateType = deviceState.getStateType();
235 assertFalse(status.isPresent());
236 assertFalse(statusRaw.isPresent());
237 assertFalse(stateType.isPresent());
241 public void testReturnValuesWhenStatusValueLocalizedIsNotNull() {
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()));
247 State state = mock(State.class);
248 when(state.getStatus()).thenReturn(Optional.of(statusMock));
250 Device device = mock(Device.class);
251 when(device.getState()).thenReturn(Optional.of(state));
252 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
255 String status = deviceState.getStatus().get();
256 int statusRaw = deviceState.getStatusRaw().get();
257 StateType stateType = deviceState.getStateType().get();
260 assertEquals("Not connected", status);
261 assertEquals(StateType.NOT_CONNECTED.getCode(), statusRaw);
262 assertEquals(StateType.NOT_CONNECTED, stateType);
266 public void testReturnValuesWhenStatusValueRawIsNotNull() {
268 Status statusMock = mock(Status.class);
269 when(statusMock.getValueRaw()).thenReturn(Optional.of(StateType.END_PROGRAMMED.getCode()));
271 State state = mock(State.class);
272 when(state.getStatus()).thenReturn(Optional.of(statusMock));
274 Device device = mock(Device.class);
275 when(device.getState()).thenReturn(Optional.of(state));
276 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
279 StateType stateType = deviceState.getStateType().get();
282 assertEquals(StateType.END_PROGRAMMED, stateType);
286 public void testReturnValuesWhenProgramTypeIsEmpty() {
288 State state = mock(State.class);
289 when(state.getProgramType()).thenReturn(Optional.empty());
291 Device device = mock(Device.class);
292 when(device.getState()).thenReturn(Optional.of(state));
293 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
296 Optional<String> selectedProgram = deviceState.getSelectedProgram();
297 Optional<Long> selectedProgramId = deviceState.getSelectedProgramId();
300 assertFalse(selectedProgram.isPresent());
301 assertFalse(selectedProgramId.isPresent());
305 public void testReturnValuesWhenProgramTypeValueLocalizedIsEmpty() {
307 ProgramType programType = mock(ProgramType.class);
308 when(programType.getValueLocalized()).thenReturn(Optional.empty());
310 State state = mock(State.class);
311 when(state.getProgramType()).thenReturn(Optional.of(programType));
313 Device device = mock(Device.class);
314 when(device.getState()).thenReturn(Optional.of(state));
315 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
318 Optional<String> selectedProgram = deviceState.getSelectedProgram();
319 Optional<Long> selectedProgramId = deviceState.getSelectedProgramId();
322 assertFalse(selectedProgram.isPresent());
323 assertFalse(selectedProgramId.isPresent());
327 public void testReturnValuesWhenProgramTypeValueLocalizedIsNotNull() {
329 ProgramId programId = mock(ProgramId.class);
330 when(programId.getValueRaw()).thenReturn(Optional.of(3L));
331 when(programId.getValueLocalized()).thenReturn(Optional.of("Washing"));
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);
343 String selectedProgram = deviceState.getSelectedProgram().get();
344 long selectedProgramId = deviceState.getSelectedProgramId().get();
347 assertEquals("Washing", selectedProgram);
348 assertEquals(3L, selectedProgramId);
352 public void testReturnValuesWhenProgramPhaseIsEmpty() {
354 State state = mock(State.class);
355 when(state.getProgramPhase()).thenReturn(Optional.empty());
357 Device device = mock(Device.class);
358 when(device.getState()).thenReturn(Optional.of(state));
359 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
362 Optional<String> programPhase = deviceState.getProgramPhase();
363 Optional<Integer> programPhaseRaw = deviceState.getProgramPhaseRaw();
366 assertFalse(programPhase.isPresent());
367 assertFalse(programPhaseRaw.isPresent());
371 public void testReturnValuesWhenProgramPhaseValueLocalizedIsEmpty() {
373 ProgramPhase programPhaseMock = mock(ProgramPhase.class);
374 when(programPhaseMock.getValueLocalized()).thenReturn(Optional.empty());
376 State state = mock(State.class);
377 when(state.getProgramPhase()).thenReturn(Optional.of(programPhaseMock));
379 Device device = mock(Device.class);
380 when(device.getState()).thenReturn(Optional.of(state));
381 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
384 Optional<String> programPhase = deviceState.getProgramPhase();
385 Optional<Integer> programPhaseRaw = deviceState.getProgramPhaseRaw();
388 assertFalse(programPhase.isPresent());
389 assertFalse(programPhaseRaw.isPresent());
393 public void testReturnValuesWhenProgramPhaseValueLocalizedIsNotNull() {
395 ProgramPhase programPhaseMock = mock(ProgramPhase.class);
396 when(programPhaseMock.getValueLocalized()).thenReturn(Optional.of("Spülen"));
397 when(programPhaseMock.getValueRaw()).thenReturn(Optional.of(4));
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);
409 String programPhase = deviceState.getProgramPhase().get();
410 int programPhaseRaw = deviceState.getProgramPhaseRaw().get();
413 assertEquals("Spülen", programPhase);
414 assertEquals(4, programPhaseRaw);
418 public void testReturnValuesWhenDryingStepIsEmpty() {
420 State state = mock(State.class);
421 when(state.getDryingStep()).thenReturn(Optional.empty());
423 Device device = mock(Device.class);
424 when(device.getState()).thenReturn(Optional.of(state));
425 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
428 Optional<String> dryingTarget = deviceState.getDryingTarget();
429 Optional<Integer> dryingTargetRaw = deviceState.getDryingTargetRaw();
432 assertFalse(dryingTarget.isPresent());
433 assertFalse(dryingTargetRaw.isPresent());
437 public void testReturnValuesWhenDryingStepValueLocalizedIsEmpty() {
439 DryingStep dryingStep = mock(DryingStep.class);
440 when(dryingStep.getValueLocalized()).thenReturn(Optional.empty());
441 when(dryingStep.getValueRaw()).thenReturn(Optional.empty());
443 State state = mock(State.class);
444 when(state.getDryingStep()).thenReturn(Optional.of(dryingStep));
446 Device device = mock(Device.class);
447 when(device.getState()).thenReturn(Optional.of(state));
448 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
451 Optional<String> dryingTarget = deviceState.getDryingTarget();
452 Optional<Integer> dryingTargetRaw = deviceState.getDryingTargetRaw();
455 assertFalse(dryingTarget.isPresent());
456 assertFalse(dryingTargetRaw.isPresent());
460 public void testReturnValuesWhenDryingStepValueLocalizedIsNotNull() {
462 DryingStep dryingStep = mock(DryingStep.class);
463 when(dryingStep.getValueLocalized()).thenReturn(Optional.of("Hot"));
464 when(dryingStep.getValueRaw()).thenReturn(Optional.of(5));
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);
476 String dryingTarget = deviceState.getDryingTarget().get();
477 int dryingTargetRaw = deviceState.getDryingTargetRaw().get();
480 assertEquals("Hot", dryingTarget);
481 assertEquals(5, dryingTargetRaw);
485 public void testReturnValuesPreHeatFinishedWhenStateIsNotRunning() {
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));
492 Status status = mock(Status.class);
493 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
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));
500 Device device = mock(Device.class);
501 when(device.getState()).thenReturn(Optional.of(state));
503 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
506 Optional<Boolean> hasPreHeatFinished = deviceState.hasPreHeatFinished();
509 assertFalse(hasPreHeatFinished.get());
513 public void testReturnValuesPreHeatFinishedWhenTargetTemperatureIsEmpty() {
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));
520 Status status = mock(Status.class);
521 when(status.getValueRaw()).thenReturn(Optional.of(StateType.RUNNING.getCode()));
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));
528 Device device = mock(Device.class);
529 when(device.getState()).thenReturn(Optional.of(state));
531 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
534 Optional<Boolean> hasPreHeatFinished = deviceState.hasPreHeatFinished();
537 assertFalse(hasPreHeatFinished.isPresent());
541 public void testReturnValuesPreHeatFinishedWhenCurrentTemperatureIsEmpty() {
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());
548 Status status = mock(Status.class);
549 when(status.getValueRaw()).thenReturn(Optional.of(StateType.RUNNING.getCode()));
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));
556 Device device = mock(Device.class);
557 when(device.getState()).thenReturn(Optional.of(state));
559 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
562 Optional<Boolean> hasPreHeatFinished = deviceState.hasPreHeatFinished();
565 assertFalse(hasPreHeatFinished.isPresent());
569 public void testReturnValuesPreHeatFinishedWhenPreHeatingHasFinished() {
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));
576 Status status = mock(Status.class);
577 when(status.getValueRaw()).thenReturn(Optional.of(StateType.RUNNING.getCode()));
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));
584 Device device = mock(Device.class);
585 when(device.getState()).thenReturn(Optional.of(state));
587 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
590 Optional<Boolean> hasPreHeatFinished = deviceState.hasPreHeatFinished();
593 assertTrue(hasPreHeatFinished.get());
597 public void testReturnValuesPreHeatFinishedWhenPreHeatingHasNotFinished() {
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));
604 Status status = mock(Status.class);
605 when(status.getValueRaw()).thenReturn(Optional.of(StateType.RUNNING.getCode()));
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));
612 Device device = mock(Device.class);
613 when(device.getState()).thenReturn(Optional.of(state));
615 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
618 Optional<Boolean> hasPreHeatFinished = deviceState.hasPreHeatFinished();
621 assertFalse(hasPreHeatFinished.get());
625 public void testReturnValuesWhenTargetTemperatureIsEmpty() {
627 State state = mock(State.class);
628 when(state.getTargetTemperature()).thenReturn(Collections.emptyList());
630 Device device = mock(Device.class);
631 when(device.getState()).thenReturn(Optional.of(state));
632 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
635 Optional<Integer> targetTemperature = deviceState.getTargetTemperature(0);
638 assertFalse(targetTemperature.isPresent());
642 public void testReturnValuesWhenTargetTemperatureIndexIsOutOfRange() {
644 Status status = mock(Status.class);
645 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
647 State state = mock(State.class);
648 when(state.getTargetTemperature()).thenReturn(new LinkedList<>());
649 when(state.getStatus()).thenReturn(Optional.of(status));
651 Device device = mock(Device.class);
652 when(device.getState()).thenReturn(Optional.of(state));
653 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
656 Optional<Integer> targetTemperature = deviceState.getTargetTemperature(0);
659 assertFalse(targetTemperature.isPresent());
663 public void testReturnValuesWhenTargetTemperatureValueLocalizedIsEmpty() {
665 Status status = mock(Status.class);
666 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
668 Temperature temperature = mock(Temperature.class);
669 when(temperature.getValueLocalized()).thenReturn(Optional.empty());
671 State state = mock(State.class);
672 when(state.getTargetTemperature()).thenReturn(Arrays.asList(temperature));
673 when(state.getStatus()).thenReturn(Optional.of(status));
675 Device device = mock(Device.class);
676 when(device.getState()).thenReturn(Optional.of(state));
677 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
680 Optional<Integer> targetTemperature = deviceState.getTargetTemperature(0);
683 assertFalse(targetTemperature.isPresent());
687 public void testReturnValuesWhenTargetTemperatureValueLocalizedIsValid() {
689 Temperature temperature = mock(Temperature.class);
690 when(temperature.getValueLocalized()).thenReturn(Optional.of(20));
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);
702 Integer targetTemperature = deviceState.getTargetTemperature(0).get();
705 assertEquals(Integer.valueOf(20), targetTemperature);
709 public void testReturnValuesWhenTemperatureIsEmpty() {
711 Status status = mock(Status.class);
712 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
714 State state = mock(State.class);
715 when(state.getTemperature()).thenReturn(Collections.emptyList());
716 when(state.getStatus()).thenReturn(Optional.of(status));
718 Device device = mock(Device.class);
719 when(device.getState()).thenReturn(Optional.of(state));
720 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
723 Optional<Integer> temperature = deviceState.getTemperature(0);
726 assertFalse(temperature.isPresent());
730 public void testReturnValuesWhenVentilationStepIsEmpty() {
732 State state = mock(State.class);
733 when(state.getVentilationStep()).thenReturn(Optional.empty());
735 Device device = mock(Device.class);
736 when(device.getState()).thenReturn(Optional.of(state));
737 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
740 Optional<String> ventilationStep = deviceState.getVentilationStep();
741 Optional<Integer> ventilationStepRaw = deviceState.getVentilationStepRaw();
744 assertFalse(ventilationStep.isPresent());
745 assertFalse(ventilationStepRaw.isPresent());
749 public void testReturnValuesWhenTemperatureIndexIsOutOfRange() {
751 Status status = mock(Status.class);
752 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
754 State state = mock(State.class);
755 when(state.getTemperature()).thenReturn(new LinkedList<>());
756 when(state.getStatus()).thenReturn(Optional.of(status));
758 Device device = mock(Device.class);
759 when(device.getState()).thenReturn(Optional.of(state));
760 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
763 Optional<Integer> temperature = deviceState.getTemperature(-1);
766 assertFalse(temperature.isPresent());
770 public void testReturnValuesWhenTemperatureValueLocalizedIsEmpty() {
772 Status status = mock(Status.class);
773 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
775 Temperature temperatureMock = mock(Temperature.class);
776 when(temperatureMock.getValueLocalized()).thenReturn(Optional.empty());
778 State state = mock(State.class);
779 when(state.getTemperature()).thenReturn(Arrays.asList(temperatureMock));
780 when(state.getStatus()).thenReturn(Optional.of(status));
782 Device device = mock(Device.class);
783 when(device.getState()).thenReturn(Optional.of(state));
784 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
787 Optional<Integer> temperature = deviceState.getTemperature(0);
790 assertFalse(temperature.isPresent());
794 public void testReturnValuesWhenTemperatureValueLocalizedIsValid() {
796 Temperature temperatureMock = mock(Temperature.class);
797 when(temperatureMock.getValueLocalized()).thenReturn(Optional.of(10));
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);
809 Integer temperature = deviceState.getTemperature(0).get();
812 assertEquals(Integer.valueOf(10), temperature);
816 public void testReturnValuesWhenPlatStepIndexIsOutOfRange() {
818 Status status = mock(Status.class);
819 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
821 State state = mock(State.class);
822 when(state.getPlateStep()).thenReturn(Collections.emptyList());
823 when(state.getStatus()).thenReturn(Optional.of(status));
825 Device device = mock(Device.class);
826 when(device.getState()).thenReturn(Optional.of(state));
827 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
830 int plateStepCount = deviceState.getPlateStepCount().get();
831 Optional<String> plateStep = deviceState.getPlateStep(0);
832 Optional<Integer> plateStepRaw = deviceState.getPlateStepRaw(0);
835 assertEquals(0, plateStepCount);
836 assertFalse(plateStep.isPresent());
837 assertFalse(plateStepRaw.isPresent());
841 public void testReturnValuesWhenPlateStepValueIsEmpty() {
843 Status status = mock(Status.class);
844 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
846 PlateStep plateStepMock = mock(PlateStep.class);
847 when(plateStepMock.getValueRaw()).thenReturn(Optional.empty());
848 when(plateStepMock.getValueLocalized()).thenReturn(Optional.empty());
850 State state = mock(State.class);
851 when(state.getPlateStep()).thenReturn(Collections.singletonList(plateStepMock));
852 when(state.getStatus()).thenReturn(Optional.of(status));
854 Device device = mock(Device.class);
855 when(device.getState()).thenReturn(Optional.of(state));
856 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
859 int plateStepCount = deviceState.getPlateStepCount().get();
860 Optional<String> plateStep = deviceState.getPlateStep(0);
861 Optional<Integer> plateStepRaw = deviceState.getPlateStepRaw(0);
864 assertEquals(1, plateStepCount);
865 assertFalse(plateStep.isPresent());
866 assertFalse(plateStepRaw.isPresent());
870 public void testReturnValuesWhenPlateStepValueIsValid() {
872 PlateStep plateStepMock = mock(PlateStep.class);
873 when(plateStepMock.getValueRaw()).thenReturn(Optional.of(2));
874 when(plateStepMock.getValueLocalized()).thenReturn(Optional.of("1."));
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);
886 int plateStepCount = deviceState.getPlateStepCount().get();
887 String plateStep = deviceState.getPlateStep(0).get();
888 int plateStepRaw = deviceState.getPlateStepRaw(0).get();
891 assertEquals(1, plateStepCount);
892 assertEquals("1.", plateStep);
893 assertEquals(2, plateStepRaw);
897 public void testReturnValuesWhenRemainingTimeIsEmpty() {
899 State state = mock(State.class);
900 when(state.getRemainingTime()).thenReturn(Optional.empty());
901 when(state.getElapsedTime()).thenReturn(Optional.of(Arrays.asList(0, 0)));
903 Device device = mock(Device.class);
904 when(device.getState()).thenReturn(Optional.of(state));
905 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
908 Optional<Integer> progress = deviceState.getProgress();
911 assertFalse(progress.isPresent());
915 public void testReturnValuesWhenRemainingTimeSizeIsNotTwo() {
917 Status status = mock(Status.class);
918 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
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));
925 Device device = mock(Device.class);
926 when(device.getState()).thenReturn(Optional.of(state));
927 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
930 Optional<Integer> progress = deviceState.getProgress();
933 assertFalse(progress.isPresent());
937 public void testReturnValuesWhenRemoteEnableIsEmpty() {
939 State state = mock(State.class);
940 when(state.getRemoteEnable()).thenReturn(Optional.empty());
942 Device device = mock(Device.class);
943 when(device.getState()).thenReturn(Optional.of(state));
944 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
947 Optional<Boolean> remoteControlEnabled = deviceState.isRemoteControlEnabled();
950 assertFalse(remoteControlEnabled.isPresent());
954 public void testReturnValuesWhenFullRemoteControlIsEmpty() {
956 RemoteEnable remoteEnable = mock(RemoteEnable.class);
957 when(remoteEnable.getFullRemoteControl()).thenReturn(Optional.empty());
959 State state = mock(State.class);
960 when(state.getRemoteEnable()).thenReturn(Optional.of(remoteEnable));
962 Device device = mock(Device.class);
963 when(device.getState()).thenReturn(Optional.of(state));
964 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
967 Optional<Boolean> remoteControlEnabled = deviceState.isRemoteControlEnabled();
970 assertFalse(remoteControlEnabled.isPresent());
974 public void testReturnValuesWhenFullRemoteControlIsNotNull() {
976 RemoteEnable remoteEnable = mock(RemoteEnable.class);
977 when(remoteEnable.getFullRemoteControl()).thenReturn(Optional.of(true));
979 State state = mock(State.class);
980 when(state.getRemoteEnable()).thenReturn(Optional.of(remoteEnable));
982 Device device = mock(Device.class);
983 when(device.getState()).thenReturn(Optional.of(state));
984 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
987 Boolean remoteControlEnabled = deviceState.isRemoteControlEnabled().get();
990 assertTrue(remoteControlEnabled);
994 public void testReturnValuesWhenElapsedTimeIsEmpty() {
996 Status status = mock(Status.class);
997 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
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));
1004 Device device = mock(Device.class);
1005 when(device.getState()).thenReturn(Optional.of(state));
1006 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1009 Optional<Integer> progress = deviceState.getProgress();
1012 assertFalse(progress.isPresent());
1016 public void testReturnValuesWhenElapsedTimeSizeIsNotTwo() {
1018 Status status = mock(Status.class);
1019 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
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));
1026 Device device = mock(Device.class);
1027 when(device.getState()).thenReturn(Optional.of(state));
1028 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1031 Optional<Integer> progress = deviceState.getProgress();
1034 assertFalse(progress.isPresent());
1038 public void testReturnValuesWhenElapsedTimeAndRemainingTimeIsZero() {
1040 Status status = mock(Status.class);
1041 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
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));
1048 Device device = mock(Device.class);
1049 when(device.getState()).thenReturn(Optional.of(state));
1050 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1053 Optional<Integer> progress = deviceState.getProgress();
1056 assertFalse(progress.isPresent());
1060 public void whenElapsedTimeIsNotPresentThenEmptyIsReturned() {
1062 Status status = mock(Status.class);
1063 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1065 State state = mock(State.class);
1066 when(state.getStatus()).thenReturn(Optional.of(status));
1067 when(state.getElapsedTime()).thenReturn(Optional.empty());
1069 Device device = mock(Device.class);
1070 when(device.getState()).thenReturn(Optional.of(state));
1072 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1075 Optional<Integer> elapsedTime = deviceState.getElapsedTime();
1078 assertFalse(elapsedTime.isPresent());
1082 public void whenElapsedTimeIsAnEmptyListThenEmptyIsReturned() {
1084 Status status = mock(Status.class);
1085 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1087 State state = mock(State.class);
1088 when(state.getStatus()).thenReturn(Optional.of(status));
1089 when(state.getElapsedTime()).thenReturn(Optional.of(Collections.emptyList()));
1091 Device device = mock(Device.class);
1092 when(device.getState()).thenReturn(Optional.of(state));
1094 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1097 Optional<Integer> elapsedTime = deviceState.getElapsedTime();
1100 assertFalse(elapsedTime.isPresent());
1104 public void whenElapsedTimeHasOnlyOneElementThenEmptyIsReturned() {
1106 Status status = mock(Status.class);
1107 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1109 State state = mock(State.class);
1110 when(state.getStatus()).thenReturn(Optional.of(status));
1111 when(state.getElapsedTime()).thenReturn(Optional.of(Collections.singletonList(2)));
1113 Device device = mock(Device.class);
1114 when(device.getState()).thenReturn(Optional.of(state));
1116 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1119 Optional<Integer> elapsedTime = deviceState.getElapsedTime();
1122 assertFalse(elapsedTime.isPresent());
1126 public void whenElapsedTimeHasThreeElementsThenEmptyIsReturned() {
1128 Status status = mock(Status.class);
1129 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
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)));
1135 Device device = mock(Device.class);
1136 when(device.getState()).thenReturn(Optional.of(state));
1138 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1141 Optional<Integer> elapsedTime = deviceState.getElapsedTime();
1144 assertFalse(elapsedTime.isPresent());
1148 public void whenElapsedTimeHasTwoElementsThenTheTotalNumberOfSecondsIsReturned() {
1150 Status status = mock(Status.class);
1151 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
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)));
1157 Device device = mock(Device.class);
1158 when(device.getState()).thenReturn(Optional.of(state));
1160 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1163 Optional<Integer> elapsedTime = deviceState.getElapsedTime();
1166 assertTrue(elapsedTime.isPresent());
1167 assertEquals(Integer.valueOf((60 + 2) * 60), elapsedTime.get());
1171 public void whenDeviceIsInOffStateThenElapsedTimeIsEmpty() {
1173 Status status = mock(Status.class);
1174 when(status.getValueRaw()).thenReturn(Optional.of(StateType.OFF.getCode()));
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)));
1180 Device device = mock(Device.class);
1181 when(device.getState()).thenReturn(Optional.of(state));
1183 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1186 Optional<Integer> elapsedTime = deviceState.getElapsedTime();
1189 assertFalse(elapsedTime.isPresent());
1193 public void testReturnValuesWhenProgressIs50Percent() {
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)));
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);
1207 Integer progress = deviceState.getProgress().get();
1210 assertEquals(Integer.valueOf(50), progress);
1214 public void testReturnValuesWhenProgressIs25Percent() {
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)));
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);
1228 Integer progress = deviceState.getProgress().get();
1231 assertEquals(Integer.valueOf(25), progress);
1235 public void testReturnValuesWhenProgressIs0Percent() {
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)));
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);
1249 Integer progress = deviceState.getProgress().get();
1252 assertEquals(Integer.valueOf(0), progress);
1256 public void testReturnValuesWhenSignalDoorIsEmpty() {
1258 State state = mock(State.class);
1259 when(state.getSignalDoor()).thenReturn(Optional.empty());
1261 Status status = mock(Status.class);
1262 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1263 when(state.getStatus()).thenReturn(Optional.of(status));
1265 Device device = mock(Device.class);
1266 when(device.getState()).thenReturn(Optional.of(state));
1268 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1271 Optional<Boolean> doorState = deviceState.getDoorState();
1272 Optional<Boolean> doorAlarm = deviceState.getDoorAlarm();
1275 assertFalse(doorState.isPresent());
1276 assertFalse(doorAlarm.isPresent());
1280 public void testReturnValuesWhenSignalDoorIsTrue() {
1282 State state = mock(State.class);
1283 when(state.getSignalDoor()).thenReturn(Optional.of(true));
1285 Status status = mock(Status.class);
1286 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1287 when(state.getStatus()).thenReturn(Optional.of(status));
1289 Device device = mock(Device.class);
1290 when(device.getState()).thenReturn(Optional.of(state));
1292 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1295 Optional<Boolean> doorState = deviceState.getDoorState();
1298 assertTrue(doorState.get());
1302 public void testReturnValuesWhenSignalDoorIsFalse() {
1304 State state = mock(State.class);
1305 when(state.getSignalDoor()).thenReturn(Optional.of(false));
1307 Status status = mock(Status.class);
1308 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1309 when(state.getStatus()).thenReturn(Optional.of(status));
1311 Device device = mock(Device.class);
1312 when(device.getState()).thenReturn(Optional.of(state));
1314 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1317 Optional<Boolean> doorState = deviceState.getDoorState();
1320 assertFalse(doorState.get());
1324 public void testReturnValuesWhenSignalFailureIsEmpty() {
1326 State state = mock(State.class);
1327 when(state.getSignalDoor()).thenReturn(Optional.of(true));
1328 when(state.getSignalFailure()).thenReturn(Optional.empty());
1330 Status status = mock(Status.class);
1331 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1332 when(state.getStatus()).thenReturn(Optional.of(status));
1334 Device device = mock(Device.class);
1335 when(device.getState()).thenReturn(Optional.of(state));
1337 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1340 Optional<Boolean> doorAlarm = deviceState.getDoorAlarm();
1343 assertFalse(doorAlarm.isPresent());
1347 public void testReturnValuesWhenDoorAlarmIsActive() {
1349 State state = mock(State.class);
1350 when(state.getSignalDoor()).thenReturn(Optional.of(true));
1351 when(state.getSignalFailure()).thenReturn(Optional.of(true));
1353 Status status = mock(Status.class);
1354 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1355 when(state.getStatus()).thenReturn(Optional.of(status));
1357 Device device = mock(Device.class);
1358 when(device.getState()).thenReturn(Optional.of(state));
1360 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1363 Optional<Boolean> doorAlarm = deviceState.getDoorAlarm();
1366 assertTrue(doorAlarm.get());
1370 public void testReturnValuesWhenDoorAlarmIsNotActiveBecauseOfNoDoorSignal() {
1372 State state = mock(State.class);
1373 when(state.getSignalDoor()).thenReturn(Optional.of(false));
1374 when(state.getSignalFailure()).thenReturn(Optional.of(true));
1376 Status status = mock(Status.class);
1377 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1378 when(state.getStatus()).thenReturn(Optional.of(status));
1380 Device device = mock(Device.class);
1381 when(device.getState()).thenReturn(Optional.of(state));
1383 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1386 Optional<Boolean> doorAlarm = deviceState.getDoorAlarm();
1389 assertFalse(doorAlarm.get());
1393 public void testReturnValuesWhenDoorAlarmIsNotActiveBecauseOfNoFailureSignal() {
1395 State state = mock(State.class);
1396 when(state.getSignalDoor()).thenReturn(Optional.of(true));
1397 when(state.getSignalFailure()).thenReturn(Optional.of(false));
1399 Status status = mock(Status.class);
1400 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1401 when(state.getStatus()).thenReturn(Optional.of(status));
1403 Device device = mock(Device.class);
1404 when(device.getState()).thenReturn(Optional.of(state));
1406 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1409 Optional<Boolean> doorAlarm = deviceState.getDoorAlarm();
1412 assertFalse(doorAlarm.get());
1416 public void testReturnValuesWhenIdentIsEmpty() {
1418 Device device = mock(Device.class);
1419 when(device.getIdent()).thenReturn(Optional.empty());
1420 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
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();
1430 assertFalse(type.isPresent());
1431 assertEquals(DeviceType.UNKNOWN, rawType);
1432 assertFalse(deviceName.isPresent());
1433 assertFalse(fabNumber.isPresent());
1434 assertFalse(techType.isPresent());
1438 public void testReturnValuesWhenTypeIsEmpty() {
1440 Ident ident = mock(Ident.class);
1441 when(ident.getType()).thenReturn(Optional.empty());
1443 Device device = mock(Device.class);
1444 when(device.getIdent()).thenReturn(Optional.of(ident));
1445 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1448 Optional<String> type = deviceState.getType();
1449 DeviceType rawType = deviceState.getRawType();
1452 assertFalse(type.isPresent());
1453 assertEquals(DeviceType.UNKNOWN, rawType);
1457 public void testReturnValuesWhenTypeValueLocalizedIsEmpty() {
1459 Type typeMock = mock(Type.class);
1460 when(typeMock.getValueLocalized()).thenReturn(Optional.empty());
1462 Ident ident = mock(Ident.class);
1463 when(ident.getType()).thenReturn(Optional.of(typeMock));
1465 Device device = mock(Device.class);
1466 when(device.getIdent()).thenReturn(Optional.of(ident));
1467 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1470 Optional<String> type = deviceState.getType();
1473 assertFalse(type.isPresent());
1477 public void testReturnValuesWhenTypeValueLocalizedIsNotNull() {
1479 Type typeMock = mock(Type.class);
1480 when(typeMock.getValueLocalized()).thenReturn(Optional.of("Hood"));
1482 Ident ident = mock(Ident.class);
1483 when(ident.getType()).thenReturn(Optional.of(typeMock));
1485 Device device = mock(Device.class);
1486 when(device.getIdent()).thenReturn(Optional.of(ident));
1487 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1490 String type = deviceState.getType().get();
1493 assertEquals("Hood", type);
1497 public void testReturnValuesWhenTypeValueRawIsNotNull() {
1499 Type typeMock = mock(Type.class);
1500 when(typeMock.getValueRaw()).thenReturn(DeviceType.COFFEE_SYSTEM);
1502 Ident ident = mock(Ident.class);
1503 when(ident.getType()).thenReturn(Optional.of(typeMock));
1505 Device device = mock(Device.class);
1506 when(device.getIdent()).thenReturn(Optional.of(ident));
1507 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1510 DeviceType rawType = deviceState.getRawType();
1513 assertEquals(DeviceType.COFFEE_SYSTEM, rawType);
1517 public void testReturnValuesWhenDeviceNameIsEmpty() {
1519 Ident ident = mock(Ident.class);
1520 when(ident.getDeviceName()).thenReturn(Optional.empty());
1522 Device device = mock(Device.class);
1523 when(device.getIdent()).thenReturn(Optional.of(ident));
1524 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1527 Optional<String> deviceName = deviceState.getDeviceName();
1530 assertFalse(deviceName.isPresent());
1534 public void testReturnValuesWhenDeviceNameIsEmptyString() {
1536 Ident ident = mock(Ident.class);
1537 when(ident.getDeviceName()).thenReturn(Optional.of(""));
1539 Device device = mock(Device.class);
1540 when(device.getIdent()).thenReturn(Optional.of(ident));
1541 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1544 Optional<String> deviceName = deviceState.getDeviceName();
1547 assertFalse(deviceName.isPresent());
1551 public void testReturnValuesWhenDeviceNameIsValid() {
1553 Ident ident = mock(Ident.class);
1554 when(ident.getDeviceName()).thenReturn(Optional.of("MyWashingMachine"));
1556 Device device = mock(Device.class);
1557 when(device.getIdent()).thenReturn(Optional.of(ident));
1558 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1561 Optional<String> deviceName = deviceState.getDeviceName();
1564 assertEquals(Optional.of("MyWashingMachine"), deviceName);
1568 public void testReturnValuesWhenFabNumberIsNotNull() {
1570 DeviceIdentLabel deviceIdentLabel = mock(DeviceIdentLabel.class);
1571 when(deviceIdentLabel.getFabNumber()).thenReturn(Optional.of("000061431659"));
1573 Ident ident = mock(Ident.class);
1574 when(ident.getDeviceIdentLabel()).thenReturn(Optional.of(deviceIdentLabel));
1576 Device device = mock(Device.class);
1577 when(device.getIdent()).thenReturn(Optional.of(ident));
1578 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1581 String fabNumber = deviceState.getFabNumber().get();
1584 assertEquals("000061431659", fabNumber);
1588 public void testReturnValuesWhenTechTypeIsNotNull() {
1590 DeviceIdentLabel deviceIdentLabel = mock(DeviceIdentLabel.class);
1591 when(deviceIdentLabel.getTechType()).thenReturn(Optional.of("XKM3100WEC"));
1593 Ident ident = mock(Ident.class);
1594 when(ident.getDeviceIdentLabel()).thenReturn(Optional.of(deviceIdentLabel));
1596 Device device = mock(Device.class);
1597 when(device.getIdent()).thenReturn(Optional.of(ident));
1598 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1601 String techType = deviceState.getTechType().get();
1604 assertEquals("XKM3100WEC", techType);
1608 public void whenDeviceIsInFailureStateThenItHasAnError() {
1610 Status status = mock(Status.class);
1611 when(status.getValueRaw()).thenReturn(Optional.of(StateType.FAILURE.getCode()));
1613 State state = mock(State.class);
1614 when(state.getStatus()).thenReturn(Optional.of(status));
1616 Device device = mock(Device.class);
1617 when(device.getState()).thenReturn(Optional.of(state));
1618 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1621 boolean hasError = deviceState.hasError();
1624 assertTrue(hasError);
1628 public void whenDeviceIsInRunningStateAndDoesNotSignalAFailureThenItHasNoError() {
1630 Status status = mock(Status.class);
1631 when(status.getValueRaw()).thenReturn(Optional.of(StateType.RUNNING.getCode()));
1633 State state = mock(State.class);
1634 when(state.getStatus()).thenReturn(Optional.of(status));
1636 Device device = mock(Device.class);
1637 when(device.getState()).thenReturn(Optional.of(state));
1638 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1641 boolean hasError = deviceState.hasError();
1644 assertFalse(hasError);
1648 public void whenDeviceSignalsAFailureThenItHasAnError() {
1650 Status status = mock(Status.class);
1651 when(status.getValueRaw()).thenReturn(Optional.of(StateType.RUNNING.getCode()));
1653 State state = mock(State.class);
1654 when(state.getStatus()).thenReturn(Optional.of(status));
1655 when(state.getSignalFailure()).thenReturn(Optional.of(true));
1657 Device device = mock(Device.class);
1658 when(device.getState()).thenReturn(Optional.of(state));
1659 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1662 boolean hasError = deviceState.hasError();
1665 assertTrue(hasError);
1669 public void testReturnValuesForHasInfoWhenSignalInfoIsEmpty() {
1671 State state = mock(State.class);
1672 when(state.getSignalInfo()).thenReturn(Optional.empty());
1674 Status status = mock(Status.class);
1675 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1676 when(state.getStatus()).thenReturn(Optional.of(status));
1678 Device device = mock(Device.class);
1679 when(device.getState()).thenReturn(Optional.of(state));
1680 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1683 boolean hasInfo = deviceState.hasInfo();
1686 assertFalse(hasInfo);
1690 public void whenDeviceSignalsAnInfoThenItHasAnInfo() {
1692 State state = mock(State.class);
1693 when(state.getSignalInfo()).thenReturn(Optional.of(true));
1695 Status status = mock(Status.class);
1696 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1697 when(state.getStatus()).thenReturn(Optional.of(status));
1699 Device device = mock(Device.class);
1700 when(device.getState()).thenReturn(Optional.of(state));
1701 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1704 boolean hasInfo = deviceState.hasInfo();
1707 assertTrue(hasInfo);
1711 public void whenDeviceSignalsNoInfoThenItHasNoInfo() {
1713 State state = mock(State.class);
1714 when(state.getSignalInfo()).thenReturn(Optional.of(false));
1716 Status status = mock(Status.class);
1717 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1718 when(state.getStatus()).thenReturn(Optional.of(status));
1720 Device device = mock(Device.class);
1721 when(device.getState()).thenReturn(Optional.of(state));
1722 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1725 boolean hasInfo = deviceState.hasInfo();
1728 assertFalse(hasInfo);
1732 public void testReturnValuesForVentilationStep() {
1734 VentilationStep ventilationStepMock = mock(VentilationStep.class);
1735 when(ventilationStepMock.getValueLocalized()).thenReturn(Optional.of("Step 1"));
1736 when(ventilationStepMock.getValueRaw()).thenReturn(Optional.of(1));
1738 Status status = mock(Status.class);
1739 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1741 State state = mock(State.class);
1742 when(state.getVentilationStep()).thenReturn(Optional.of(ventilationStepMock));
1743 when(state.getStatus()).thenReturn(Optional.of(status));
1745 Device device = mock(Device.class);
1746 when(device.getState()).thenReturn(Optional.of(state));
1748 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1751 String ventilationStep = deviceState.getVentilationStep().get();
1752 int ventilationStepRaw = deviceState.getVentilationStepRaw().get();
1755 assertEquals("Step 1", ventilationStep);
1756 assertEquals(1, ventilationStepRaw);
1760 public void testProgramPhaseWhenDeviceIsInOffState() {
1762 ProgramPhase programPhase = mock(ProgramPhase.class);
1763 when(programPhase.getValueLocalized()).thenReturn(Optional.of("Washing"));
1764 when(programPhase.getValueRaw()).thenReturn(Optional.of(3));
1766 Status status = mock(Status.class);
1767 when(status.getValueRaw()).thenReturn(Optional.of(StateType.OFF.getCode()));
1769 State state = mock(State.class);
1770 when(state.getProgramPhase()).thenReturn(Optional.of(programPhase));
1771 when(state.getStatus()).thenReturn(Optional.of(status));
1773 Device device = mock(Device.class);
1774 when(device.getState()).thenReturn(Optional.of(state));
1776 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1779 Optional<String> phase = deviceState.getProgramPhase();
1780 Optional<Integer> phaseRaw = deviceState.getProgramPhaseRaw();
1783 assertFalse(phase.isPresent());
1784 assertFalse(phaseRaw.isPresent());
1788 public void testDryingTargetWhenDeviceIsInOffState() {
1790 DryingStep dryingStep = mock(DryingStep.class);
1791 when(dryingStep.getValueLocalized()).thenReturn(Optional.of("Schranktrocken"));
1792 when(dryingStep.getValueRaw()).thenReturn(Optional.of(3));
1794 Status status = mock(Status.class);
1795 when(status.getValueRaw()).thenReturn(Optional.of(StateType.OFF.getCode()));
1797 State state = mock(State.class);
1798 when(state.getDryingStep()).thenReturn(Optional.of(dryingStep));
1799 when(state.getStatus()).thenReturn(Optional.of(status));
1801 Device device = mock(Device.class);
1802 when(device.getState()).thenReturn(Optional.of(state));
1804 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1807 Optional<String> dryingTarget = deviceState.getDryingTarget();
1808 Optional<Integer> dryingTargetRaw = deviceState.getDryingTargetRaw();
1811 assertFalse(dryingTarget.isPresent());
1812 assertFalse(dryingTargetRaw.isPresent());
1816 public void testVentilationStepWhenDeviceIsInOffState() {
1818 VentilationStep ventilationStep = mock(VentilationStep.class);
1819 when(ventilationStep.getValueLocalized()).thenReturn(Optional.of("Stufe 1"));
1820 when(ventilationStep.getValueRaw()).thenReturn(Optional.of(1));
1822 Status status = mock(Status.class);
1823 when(status.getValueRaw()).thenReturn(Optional.of(StateType.OFF.getCode()));
1825 State state = mock(State.class);
1826 when(state.getVentilationStep()).thenReturn(Optional.of(ventilationStep));
1827 when(state.getStatus()).thenReturn(Optional.of(status));
1829 Device device = mock(Device.class);
1830 when(device.getState()).thenReturn(Optional.of(state));
1832 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1835 Optional<String> step = deviceState.getVentilationStep();
1836 Optional<Integer> stepRaw = deviceState.getVentilationStepRaw();
1839 assertFalse(step.isPresent());
1840 assertFalse(stepRaw.isPresent());
1844 public void testReturnValuesWhenDeviceIsInOffState() {
1846 Device device = mock(Device.class);
1847 State state = mock(State.class);
1848 Status status = mock(Status.class);
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);
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"));
1860 Optional<String> selectedProgram = deviceState.getSelectedProgram();
1862 assertFalse(selectedProgram.isPresent());
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));
1869 Optional<Integer> targetTemperature = deviceState.getTargetTemperature(0);
1871 assertFalse(targetTemperature.isPresent());
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));
1878 Optional<Integer> t = deviceState.getTemperature(0);
1880 assertFalse(t.isPresent());
1883 when(state.getElapsedTime()).thenReturn(Optional.of(Arrays.asList(0, 5)));
1884 when(state.getRemainingTime()).thenReturn(Optional.of(Arrays.asList(1, 5)));
1886 Optional<Integer> progress = deviceState.getProgress();
1888 assertFalse(progress.isPresent());
1892 public void testWhenDeviceIsInOffStateThenGetSpinningSpeedReturnsNull() {
1894 Status status = mock(Status.class);
1895 when(status.getValueRaw()).thenReturn(Optional.of(StateType.OFF.getCode()));
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"));
1902 State state = mock(State.class);
1903 when(state.getStatus()).thenReturn(Optional.of(status));
1904 when(state.getSpinningSpeed()).thenReturn(Optional.of(spinningSpeed));
1906 Device device = mock(Device.class);
1907 when(device.getState()).thenReturn(Optional.of(state));
1909 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1912 Optional<String> speed = deviceState.getSpinningSpeed();
1913 Optional<Integer> speedRaw = deviceState.getSpinningSpeedRaw();
1916 assertFalse(speed.isPresent());
1917 assertFalse(speedRaw.isPresent());
1921 public void testGetSpinningSpeedReturnsNullWhenSpinningSpeedIsEmpty() {
1923 Status status = mock(Status.class);
1924 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1926 State state = mock(State.class);
1927 when(state.getStatus()).thenReturn(Optional.of(status));
1928 when(state.getSpinningSpeed()).thenReturn(Optional.empty());
1930 Device device = mock(Device.class);
1931 when(device.getState()).thenReturn(Optional.of(state));
1933 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1936 Optional<String> spinningSpeed = deviceState.getSpinningSpeed();
1937 Optional<Integer> spinningSpeedRaw = deviceState.getSpinningSpeedRaw();
1940 assertFalse(spinningSpeed.isPresent());
1941 assertFalse(spinningSpeedRaw.isPresent());
1945 public void testGetSpinningSpeedReturnsNullWhenSpinningSpeedRawValueIsEmpty() {
1947 Status status = mock(Status.class);
1948 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1950 SpinningSpeed spinningSpeedMock = mock(SpinningSpeed.class);
1951 when(spinningSpeedMock.getValueRaw()).thenReturn(Optional.empty());
1952 when(spinningSpeedMock.getValueLocalized()).thenReturn(Optional.of("1200"));
1954 State state = mock(State.class);
1955 when(state.getStatus()).thenReturn(Optional.of(status));
1956 when(state.getSpinningSpeed()).thenReturn(Optional.of(spinningSpeedMock));
1958 Device device = mock(Device.class);
1959 when(device.getState()).thenReturn(Optional.of(state));
1961 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1964 Optional<String> spinningSpeed = deviceState.getSpinningSpeed();
1965 Optional<Integer> spinningSpeedRaw = deviceState.getSpinningSpeedRaw();
1968 assertFalse(spinningSpeed.isPresent());
1969 assertFalse(spinningSpeedRaw.isPresent());
1973 public void testGetSpinningSpeedReturnsValidValueWhenSpinningSpeedRawValueIsNotNull() {
1975 Status status = mock(Status.class);
1976 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1978 SpinningSpeed spinningSpeedMock = mock(SpinningSpeed.class);
1979 when(spinningSpeedMock.getValueRaw()).thenReturn(Optional.of(1200));
1980 when(spinningSpeedMock.getValueLocalized()).thenReturn(Optional.of("1200"));
1982 State state = mock(State.class);
1983 when(state.getStatus()).thenReturn(Optional.of(status));
1984 when(state.getSpinningSpeed()).thenReturn(Optional.of(spinningSpeedMock));
1986 Device device = mock(Device.class);
1987 when(device.getState()).thenReturn(Optional.of(state));
1989 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1992 String spinningSpeed = deviceState.getSpinningSpeed().get();
1993 int spinningSpeedRaw = deviceState.getSpinningSpeedRaw().get();
1996 assertEquals("1200", spinningSpeed);
1997 assertEquals(1200, spinningSpeedRaw);
2001 public void testGetLightStateWhenDeviceIsOff() {
2003 Status status = mock(Status.class);
2004 when(status.getValueRaw()).thenReturn(Optional.of(StateType.OFF.getCode()));
2006 State state = mock(State.class);
2007 when(state.getStatus()).thenReturn(Optional.of(status));
2009 Device device = mock(Device.class);
2010 when(device.getState()).thenReturn(Optional.of(state));
2012 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2015 Optional<Boolean> lightState = deviceState.getLightState();
2018 assertFalse(lightState.isPresent());
2022 public void testGetLightStateWhenLightIsUnknown() {
2024 Status status = mock(Status.class);
2025 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
2027 State state = mock(State.class);
2028 when(state.getStatus()).thenReturn(Optional.of(status));
2029 when(state.getLight()).thenReturn(Light.UNKNOWN);
2031 Device device = mock(Device.class);
2032 when(device.getState()).thenReturn(Optional.of(state));
2034 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2037 Optional<Boolean> lightState = deviceState.getLightState();
2040 assertFalse(lightState.isPresent());
2044 public void testGetLightStateWhenLightIsEnabled() {
2046 Status status = mock(Status.class);
2047 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
2049 State state = mock(State.class);
2050 when(state.getStatus()).thenReturn(Optional.of(status));
2051 when(state.getLight()).thenReturn(Light.ENABLE);
2053 Device device = mock(Device.class);
2054 when(device.getState()).thenReturn(Optional.of(state));
2056 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2059 Boolean lightState = deviceState.getLightState().get();
2062 assertEquals(Boolean.valueOf(true), lightState);
2066 public void testGetLightStateWhenLightIsDisabled() {
2068 Status status = mock(Status.class);
2069 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
2071 State state = mock(State.class);
2072 when(state.getStatus()).thenReturn(Optional.of(status));
2073 when(state.getLight()).thenReturn(Light.DISABLE);
2075 Device device = mock(Device.class);
2076 when(device.getState()).thenReturn(Optional.of(state));
2078 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2081 Boolean lightState = deviceState.getLightState().get();
2084 assertEquals(Boolean.valueOf(false), lightState);
2088 public void testGetLightStateWhenLightIsNotSupported() {
2090 Status status = mock(Status.class);
2091 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
2093 State state = mock(State.class);
2094 when(state.getStatus()).thenReturn(Optional.of(status));
2095 when(state.getLight()).thenReturn(Light.NOT_SUPPORTED);
2097 Device device = mock(Device.class);
2098 when(device.getState()).thenReturn(Optional.of(state));
2100 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2103 Optional<Boolean> lightState = deviceState.getLightState();
2106 assertFalse(lightState.isPresent());
2110 public void testGetBatteryLevel() {
2112 Status status = mock(Status.class);
2113 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
2115 State state = mock(State.class);
2116 when(state.getStatus()).thenReturn(Optional.of(status));
2117 when(state.getBatteryLevel()).thenReturn(Optional.of(4));
2119 Device device = mock(Device.class);
2120 when(device.getState()).thenReturn(Optional.of(state));
2122 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2125 Integer batteryLevel = deviceState.getBatteryLevel().get();
2128 assertEquals(Integer.valueOf(4), batteryLevel);