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.EcoFeedback;
30 import org.openhab.binding.mielecloud.internal.webservice.api.json.EnergyConsumption;
31 import org.openhab.binding.mielecloud.internal.webservice.api.json.Ident;
32 import org.openhab.binding.mielecloud.internal.webservice.api.json.Light;
33 import org.openhab.binding.mielecloud.internal.webservice.api.json.PlateStep;
34 import org.openhab.binding.mielecloud.internal.webservice.api.json.ProgramId;
35 import org.openhab.binding.mielecloud.internal.webservice.api.json.ProgramPhase;
36 import org.openhab.binding.mielecloud.internal.webservice.api.json.ProgramType;
37 import org.openhab.binding.mielecloud.internal.webservice.api.json.RemoteEnable;
38 import org.openhab.binding.mielecloud.internal.webservice.api.json.SpinningSpeed;
39 import org.openhab.binding.mielecloud.internal.webservice.api.json.State;
40 import org.openhab.binding.mielecloud.internal.webservice.api.json.StateType;
41 import org.openhab.binding.mielecloud.internal.webservice.api.json.Status;
42 import org.openhab.binding.mielecloud.internal.webservice.api.json.Temperature;
43 import org.openhab.binding.mielecloud.internal.webservice.api.json.Type;
44 import org.openhab.binding.mielecloud.internal.webservice.api.json.VentilationStep;
45 import org.openhab.binding.mielecloud.internal.webservice.api.json.WaterConsumption;
48 * @author Björn Lange - Initial contribution
49 * @author Benjamin Bolte - Add pre-heat finished, plate step, door state, door alarm and info state channels and map
50 * signal flags from API
51 * @author Björn Lange - Add elapsed time channel, robotic vacuum cleaner, eco feedback
54 public class DeviceStateTest {
55 private static final String DEVICE_IDENTIFIER = "mac-f83001f37d45ffff";
58 public void testGetDeviceIdentifierReturnsDeviceIdentifier() {
60 Device device = mock(Device.class);
61 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
64 String deviceId = deviceState.getDeviceIdentifier();
67 assertEquals(DEVICE_IDENTIFIER, deviceId);
71 public void testReturnValuesWhenDeviceIsNull() {
73 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, null);
76 Optional<String> status = deviceState.getStatus();
77 Optional<Integer> statusRaw = deviceState.getStatusRaw();
78 Optional<StateType> stateType = deviceState.getStateType();
79 Optional<String> selectedProgram = deviceState.getSelectedProgram();
80 Optional<Long> selectedProgramId = deviceState.getSelectedProgramId();
81 Optional<String> programPhase = deviceState.getProgramPhase();
82 Optional<Integer> programPhaseRaw = deviceState.getProgramPhaseRaw();
83 Optional<String> dryingTarget = deviceState.getDryingTarget();
84 Optional<Integer> dryingTargetRaw = deviceState.getDryingTargetRaw();
85 Optional<Boolean> hasPreHeatFinished = deviceState.hasPreHeatFinished();
86 Optional<Integer> targetTemperature = deviceState.getTargetTemperature(0);
87 Optional<Integer> temperature = deviceState.getTemperature(0);
88 Optional<Boolean> remoteControlEnabled = deviceState.isRemoteControlEnabled();
89 Optional<String> ventilationStep = deviceState.getVentilationStep();
90 Optional<Integer> ventilationStepRaw = deviceState.getVentilationStepRaw();
91 Optional<Integer> plateStepCount = deviceState.getPlateStepCount();
92 Optional<String> plateStep = deviceState.getPlateStep(0);
93 Optional<Integer> plateStepRaw = deviceState.getPlateStepRaw(0);
94 boolean hasError = deviceState.hasError();
95 boolean hasInfo = deviceState.hasInfo();
96 Optional<Boolean> doorState = deviceState.getDoorState();
97 Optional<Boolean> doorAlarm = deviceState.getDoorAlarm();
98 Optional<String> type = deviceState.getType();
99 DeviceType rawType = deviceState.getRawType();
100 Optional<Integer> batteryLevel = deviceState.getBatteryLevel();
102 Optional<String> deviceName = deviceState.getDeviceName();
103 Optional<String> fabNumber = deviceState.getFabNumber();
104 Optional<String> techType = deviceState.getTechType();
105 Optional<Integer> progress = deviceState.getProgress();
108 assertFalse(status.isPresent());
109 assertFalse(statusRaw.isPresent());
110 assertFalse(stateType.isPresent());
111 assertFalse(selectedProgram.isPresent());
112 assertFalse(selectedProgramId.isPresent());
113 assertFalse(programPhase.isPresent());
114 assertFalse(programPhaseRaw.isPresent());
115 assertFalse(dryingTarget.isPresent());
116 assertFalse(dryingTargetRaw.isPresent());
117 assertFalse(hasPreHeatFinished.isPresent());
118 assertFalse(targetTemperature.isPresent());
119 assertFalse(temperature.isPresent());
120 assertFalse(remoteControlEnabled.isPresent());
121 assertFalse(ventilationStep.isPresent());
122 assertFalse(ventilationStepRaw.isPresent());
123 assertFalse(plateStepCount.isPresent());
124 assertFalse(plateStep.isPresent());
125 assertFalse(plateStepRaw.isPresent());
126 assertFalse(hasError);
127 assertFalse(hasInfo);
128 assertFalse(doorState.isPresent());
129 assertFalse(doorAlarm.isPresent());
130 assertFalse(type.isPresent());
131 assertEquals(DeviceType.UNKNOWN, rawType);
132 assertFalse(deviceName.isPresent());
133 assertFalse(fabNumber.isPresent());
134 assertFalse(techType.isPresent());
135 assertFalse(progress.isPresent());
136 assertFalse(batteryLevel.isPresent());
140 public void testReturnValuesWhenStateIsNull() {
142 Device device = mock(Device.class);
143 when(device.getState()).thenReturn(Optional.empty());
144 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
147 Optional<String> status = deviceState.getStatus();
148 Optional<Integer> statusRaw = deviceState.getStatusRaw();
149 Optional<StateType> stateType = deviceState.getStateType();
150 Optional<String> selectedProgram = deviceState.getSelectedProgram();
151 Optional<Long> selectedProgramId = deviceState.getSelectedProgramId();
152 Optional<String> programPhase = deviceState.getProgramPhase();
153 Optional<Integer> programPhaseRaw = deviceState.getProgramPhaseRaw();
154 Optional<String> dryingTarget = deviceState.getDryingTarget();
155 Optional<Integer> dryingTargetRaw = deviceState.getDryingTargetRaw();
156 Optional<Boolean> hasPreHeatFinished = deviceState.hasPreHeatFinished();
157 Optional<Integer> targetTemperature = deviceState.getTargetTemperature(0);
158 Optional<Integer> temperature = deviceState.getTemperature(0);
159 Optional<Boolean> remoteControlEnabled = deviceState.isRemoteControlEnabled();
160 Optional<Integer> progress = deviceState.getProgress();
161 Optional<String> ventilationStep = deviceState.getVentilationStep();
162 Optional<Integer> ventilationStepRaw = deviceState.getVentilationStepRaw();
163 Optional<Integer> plateStepCount = deviceState.getPlateStepCount();
164 Optional<String> plateStep = deviceState.getPlateStep(0);
165 Optional<Integer> plateStepRaw = deviceState.getPlateStepRaw(0);
166 Boolean hasError = deviceState.hasError();
167 Optional<Boolean> doorState = deviceState.getDoorState();
168 Optional<Boolean> doorAlarm = deviceState.getDoorAlarm();
169 Optional<Integer> batteryLevel = deviceState.getBatteryLevel();
172 assertFalse(status.isPresent());
173 assertFalse(statusRaw.isPresent());
174 assertFalse(stateType.isPresent());
175 assertFalse(selectedProgram.isPresent());
176 assertFalse(selectedProgramId.isPresent());
177 assertFalse(programPhase.isPresent());
178 assertFalse(programPhaseRaw.isPresent());
179 assertFalse(dryingTarget.isPresent());
180 assertFalse(dryingTargetRaw.isPresent());
181 assertFalse(hasPreHeatFinished.isPresent());
182 assertFalse(targetTemperature.isPresent());
183 assertFalse(temperature.isPresent());
184 assertFalse(remoteControlEnabled.isPresent());
185 assertFalse(progress.isPresent());
186 assertFalse(ventilationStep.isPresent());
187 assertFalse(ventilationStepRaw.isPresent());
188 assertFalse(plateStepCount.isPresent());
189 assertFalse(plateStep.isPresent());
190 assertFalse(plateStepRaw.isPresent());
191 assertFalse(hasError);
192 assertFalse(doorState.isPresent());
193 assertFalse(doorAlarm.isPresent());
194 assertFalse(batteryLevel.isPresent());
198 public void testReturnValuesWhenStatusIsEmpty() {
200 State state = mock(State.class);
201 when(state.getStatus()).thenReturn(Optional.empty());
203 Device device = mock(Device.class);
204 when(device.getState()).thenReturn(Optional.of(state));
205 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
208 Optional<String> status = deviceState.getStatus();
209 Optional<Integer> statusRaw = deviceState.getStatusRaw();
210 Optional<StateType> stateType = deviceState.getStateType();
213 assertFalse(status.isPresent());
214 assertFalse(statusRaw.isPresent());
215 assertFalse(stateType.isPresent());
219 public void testReturnValuesWhenStatusValuesAreEmpty() {
221 Status statusMock = mock(Status.class);
222 when(statusMock.getValueLocalized()).thenReturn(Optional.empty());
223 when(statusMock.getValueRaw()).thenReturn(Optional.empty());
225 State state = mock(State.class);
226 when(state.getStatus()).thenReturn(Optional.of(statusMock));
228 Device device = mock(Device.class);
229 when(device.getState()).thenReturn(Optional.of(state));
230 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
233 Optional<String> status = deviceState.getStatus();
234 Optional<Integer> statusRaw = deviceState.getStatusRaw();
235 Optional<StateType> stateType = deviceState.getStateType();
238 assertFalse(status.isPresent());
239 assertFalse(statusRaw.isPresent());
240 assertFalse(stateType.isPresent());
244 public void testReturnValuesWhenStatusValueLocalizedIsNotNull() {
246 Status statusMock = mock(Status.class);
247 when(statusMock.getValueLocalized()).thenReturn(Optional.of("Not connected"));
248 when(statusMock.getValueRaw()).thenReturn(Optional.of(StateType.NOT_CONNECTED.getCode()));
250 State state = mock(State.class);
251 when(state.getStatus()).thenReturn(Optional.of(statusMock));
253 Device device = mock(Device.class);
254 when(device.getState()).thenReturn(Optional.of(state));
255 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
258 String status = deviceState.getStatus().get();
259 int statusRaw = deviceState.getStatusRaw().get();
260 StateType stateType = deviceState.getStateType().get();
263 assertEquals("Not connected", status);
264 assertEquals(StateType.NOT_CONNECTED.getCode(), statusRaw);
265 assertEquals(StateType.NOT_CONNECTED, stateType);
269 public void testReturnValuesWhenStatusValueRawIsNotNull() {
271 Status statusMock = mock(Status.class);
272 when(statusMock.getValueRaw()).thenReturn(Optional.of(StateType.END_PROGRAMMED.getCode()));
274 State state = mock(State.class);
275 when(state.getStatus()).thenReturn(Optional.of(statusMock));
277 Device device = mock(Device.class);
278 when(device.getState()).thenReturn(Optional.of(state));
279 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
282 StateType stateType = deviceState.getStateType().get();
285 assertEquals(StateType.END_PROGRAMMED, stateType);
289 public void testReturnValuesWhenProgramTypeIsEmpty() {
291 State state = mock(State.class);
292 when(state.getProgramType()).thenReturn(Optional.empty());
294 Device device = mock(Device.class);
295 when(device.getState()).thenReturn(Optional.of(state));
296 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
299 Optional<String> selectedProgram = deviceState.getSelectedProgram();
300 Optional<Long> selectedProgramId = deviceState.getSelectedProgramId();
303 assertFalse(selectedProgram.isPresent());
304 assertFalse(selectedProgramId.isPresent());
308 public void testReturnValuesWhenProgramTypeValueLocalizedIsEmpty() {
310 ProgramType programType = mock(ProgramType.class);
311 when(programType.getValueLocalized()).thenReturn(Optional.empty());
313 State state = mock(State.class);
314 when(state.getProgramType()).thenReturn(Optional.of(programType));
316 Device device = mock(Device.class);
317 when(device.getState()).thenReturn(Optional.of(state));
318 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
321 Optional<String> selectedProgram = deviceState.getSelectedProgram();
322 Optional<Long> selectedProgramId = deviceState.getSelectedProgramId();
325 assertFalse(selectedProgram.isPresent());
326 assertFalse(selectedProgramId.isPresent());
330 public void testReturnValuesWhenProgramTypeValueLocalizedIsNotNull() {
332 ProgramId programId = mock(ProgramId.class);
333 when(programId.getValueRaw()).thenReturn(Optional.of(3L));
334 when(programId.getValueLocalized()).thenReturn(Optional.of("Washing"));
336 State state = mock(State.class);
337 Status status = mock(Status.class);
338 Device device = mock(Device.class);
339 when(state.getStatus()).thenReturn(Optional.of(status));
340 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
341 when(state.getProgramId()).thenReturn(Optional.of(programId));
342 when(device.getState()).thenReturn(Optional.of(state));
343 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
346 String selectedProgram = deviceState.getSelectedProgram().get();
347 long selectedProgramId = deviceState.getSelectedProgramId().get();
350 assertEquals("Washing", selectedProgram);
351 assertEquals(3L, selectedProgramId);
355 public void testReturnValuesWhenProgramPhaseIsEmpty() {
357 State state = mock(State.class);
358 when(state.getProgramPhase()).thenReturn(Optional.empty());
360 Device device = mock(Device.class);
361 when(device.getState()).thenReturn(Optional.of(state));
362 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
365 Optional<String> programPhase = deviceState.getProgramPhase();
366 Optional<Integer> programPhaseRaw = deviceState.getProgramPhaseRaw();
369 assertFalse(programPhase.isPresent());
370 assertFalse(programPhaseRaw.isPresent());
374 public void testReturnValuesWhenProgramPhaseValueLocalizedIsEmpty() {
376 ProgramPhase programPhaseMock = mock(ProgramPhase.class);
377 when(programPhaseMock.getValueLocalized()).thenReturn(Optional.empty());
379 State state = mock(State.class);
380 when(state.getProgramPhase()).thenReturn(Optional.of(programPhaseMock));
382 Device device = mock(Device.class);
383 when(device.getState()).thenReturn(Optional.of(state));
384 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
387 Optional<String> programPhase = deviceState.getProgramPhase();
388 Optional<Integer> programPhaseRaw = deviceState.getProgramPhaseRaw();
391 assertFalse(programPhase.isPresent());
392 assertFalse(programPhaseRaw.isPresent());
396 public void testReturnValuesWhenProgramPhaseValueLocalizedIsNotNull() {
398 ProgramPhase programPhaseMock = mock(ProgramPhase.class);
399 when(programPhaseMock.getValueLocalized()).thenReturn(Optional.of("Spülen"));
400 when(programPhaseMock.getValueRaw()).thenReturn(Optional.of(4));
402 State state = mock(State.class);
403 Status status = mock(Status.class);
404 Device device = mock(Device.class);
405 when(state.getStatus()).thenReturn(Optional.of(status));
406 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
407 when(state.getProgramPhase()).thenReturn(Optional.of(programPhaseMock));
408 when(device.getState()).thenReturn(Optional.of(state));
409 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
412 String programPhase = deviceState.getProgramPhase().get();
413 int programPhaseRaw = deviceState.getProgramPhaseRaw().get();
416 assertEquals("Spülen", programPhase);
417 assertEquals(4, programPhaseRaw);
421 public void testReturnValuesWhenDryingStepIsEmpty() {
423 State state = mock(State.class);
424 when(state.getDryingStep()).thenReturn(Optional.empty());
426 Device device = mock(Device.class);
427 when(device.getState()).thenReturn(Optional.of(state));
428 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
431 Optional<String> dryingTarget = deviceState.getDryingTarget();
432 Optional<Integer> dryingTargetRaw = deviceState.getDryingTargetRaw();
435 assertFalse(dryingTarget.isPresent());
436 assertFalse(dryingTargetRaw.isPresent());
440 public void testReturnValuesWhenDryingStepValueLocalizedIsEmpty() {
442 DryingStep dryingStep = mock(DryingStep.class);
443 when(dryingStep.getValueLocalized()).thenReturn(Optional.empty());
444 when(dryingStep.getValueRaw()).thenReturn(Optional.empty());
446 State state = mock(State.class);
447 when(state.getDryingStep()).thenReturn(Optional.of(dryingStep));
449 Device device = mock(Device.class);
450 when(device.getState()).thenReturn(Optional.of(state));
451 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
454 Optional<String> dryingTarget = deviceState.getDryingTarget();
455 Optional<Integer> dryingTargetRaw = deviceState.getDryingTargetRaw();
458 assertFalse(dryingTarget.isPresent());
459 assertFalse(dryingTargetRaw.isPresent());
463 public void testReturnValuesWhenDryingStepValueLocalizedIsNotNull() {
465 DryingStep dryingStep = mock(DryingStep.class);
466 when(dryingStep.getValueLocalized()).thenReturn(Optional.of("Hot"));
467 when(dryingStep.getValueRaw()).thenReturn(Optional.of(5));
469 State state = mock(State.class);
470 Device device = mock(Device.class);
471 Status status = mock(Status.class);
472 when(state.getDryingStep()).thenReturn(Optional.of(dryingStep));
473 when(state.getStatus()).thenReturn(Optional.of(status));
474 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
475 when(device.getState()).thenReturn(Optional.of(state));
476 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
479 String dryingTarget = deviceState.getDryingTarget().get();
480 int dryingTargetRaw = deviceState.getDryingTargetRaw().get();
483 assertEquals("Hot", dryingTarget);
484 assertEquals(5, dryingTargetRaw);
488 public void testReturnValuesPreHeatFinishedWhenStateIsNotRunning() {
490 Temperature targetTemperature = mock(Temperature.class);
491 when(targetTemperature.getValueLocalized()).thenReturn(Optional.of(0));
492 Temperature currentTemperature = mock(Temperature.class);
493 when(currentTemperature.getValueLocalized()).thenReturn(Optional.of(0));
495 Status status = mock(Status.class);
496 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
498 State state = mock(State.class);
499 when(state.getTargetTemperature()).thenReturn(Arrays.asList(targetTemperature));
500 when(state.getTemperature()).thenReturn(Arrays.asList(currentTemperature));
501 when(state.getStatus()).thenReturn(Optional.of(status));
503 Device device = mock(Device.class);
504 when(device.getState()).thenReturn(Optional.of(state));
506 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
509 Optional<Boolean> hasPreHeatFinished = deviceState.hasPreHeatFinished();
512 assertFalse(hasPreHeatFinished.get());
516 public void testReturnValuesPreHeatFinishedWhenTargetTemperatureIsEmpty() {
518 Temperature targetTemperature = mock(Temperature.class);
519 when(targetTemperature.getValueLocalized()).thenReturn(Optional.empty());
520 Temperature currentTemperature = mock(Temperature.class);
521 when(currentTemperature.getValueLocalized()).thenReturn(Optional.of(180));
523 Status status = mock(Status.class);
524 when(status.getValueRaw()).thenReturn(Optional.of(StateType.RUNNING.getCode()));
526 State state = mock(State.class);
527 when(state.getTargetTemperature()).thenReturn(Arrays.asList(targetTemperature));
528 when(state.getTemperature()).thenReturn(Arrays.asList(currentTemperature));
529 when(state.getStatus()).thenReturn(Optional.of(status));
531 Device device = mock(Device.class);
532 when(device.getState()).thenReturn(Optional.of(state));
534 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
537 Optional<Boolean> hasPreHeatFinished = deviceState.hasPreHeatFinished();
540 assertFalse(hasPreHeatFinished.isPresent());
544 public void testReturnValuesPreHeatFinishedWhenCurrentTemperatureIsEmpty() {
546 Temperature targetTemperature = mock(Temperature.class);
547 when(targetTemperature.getValueLocalized()).thenReturn(Optional.of(180));
548 Temperature currentTemperature = mock(Temperature.class);
549 when(currentTemperature.getValueLocalized()).thenReturn(Optional.empty());
551 Status status = mock(Status.class);
552 when(status.getValueRaw()).thenReturn(Optional.of(StateType.RUNNING.getCode()));
554 State state = mock(State.class);
555 when(state.getTargetTemperature()).thenReturn(Arrays.asList(targetTemperature));
556 when(state.getTemperature()).thenReturn(Arrays.asList(currentTemperature));
557 when(state.getStatus()).thenReturn(Optional.of(status));
559 Device device = mock(Device.class);
560 when(device.getState()).thenReturn(Optional.of(state));
562 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
565 Optional<Boolean> hasPreHeatFinished = deviceState.hasPreHeatFinished();
568 assertFalse(hasPreHeatFinished.isPresent());
572 public void testReturnValuesPreHeatFinishedWhenPreHeatingHasFinished() {
574 Temperature targetTemperature = mock(Temperature.class);
575 when(targetTemperature.getValueLocalized()).thenReturn(Optional.of(180));
576 Temperature currentTemperature = mock(Temperature.class);
577 when(currentTemperature.getValueLocalized()).thenReturn(Optional.of(180));
579 Status status = mock(Status.class);
580 when(status.getValueRaw()).thenReturn(Optional.of(StateType.RUNNING.getCode()));
582 State state = mock(State.class);
583 when(state.getTargetTemperature()).thenReturn(Arrays.asList(targetTemperature));
584 when(state.getTemperature()).thenReturn(Arrays.asList(currentTemperature));
585 when(state.getStatus()).thenReturn(Optional.of(status));
587 Device device = mock(Device.class);
588 when(device.getState()).thenReturn(Optional.of(state));
590 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
593 Optional<Boolean> hasPreHeatFinished = deviceState.hasPreHeatFinished();
596 assertTrue(hasPreHeatFinished.get());
600 public void testReturnValuesPreHeatFinishedWhenPreHeatingHasNotFinished() {
602 Temperature targetTemperature = mock(Temperature.class);
603 when(targetTemperature.getValueLocalized()).thenReturn(Optional.of(180));
604 Temperature currentTemperature = mock(Temperature.class);
605 when(currentTemperature.getValueLocalized()).thenReturn(Optional.of(179));
607 Status status = mock(Status.class);
608 when(status.getValueRaw()).thenReturn(Optional.of(StateType.RUNNING.getCode()));
610 State state = mock(State.class);
611 when(state.getTargetTemperature()).thenReturn(Arrays.asList(targetTemperature));
612 when(state.getTemperature()).thenReturn(Arrays.asList(currentTemperature));
613 when(state.getStatus()).thenReturn(Optional.of(status));
615 Device device = mock(Device.class);
616 when(device.getState()).thenReturn(Optional.of(state));
618 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
621 Optional<Boolean> hasPreHeatFinished = deviceState.hasPreHeatFinished();
624 assertFalse(hasPreHeatFinished.get());
628 public void testReturnValuesWhenTargetTemperatureIsEmpty() {
630 State state = mock(State.class);
631 when(state.getTargetTemperature()).thenReturn(Collections.emptyList());
633 Device device = mock(Device.class);
634 when(device.getState()).thenReturn(Optional.of(state));
635 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
638 Optional<Integer> targetTemperature = deviceState.getTargetTemperature(0);
641 assertFalse(targetTemperature.isPresent());
645 public void testReturnValuesWhenTargetTemperatureIndexIsOutOfRange() {
647 Status status = mock(Status.class);
648 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
650 State state = mock(State.class);
651 when(state.getTargetTemperature()).thenReturn(new LinkedList<>());
652 when(state.getStatus()).thenReturn(Optional.of(status));
654 Device device = mock(Device.class);
655 when(device.getState()).thenReturn(Optional.of(state));
656 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
659 Optional<Integer> targetTemperature = deviceState.getTargetTemperature(0);
662 assertFalse(targetTemperature.isPresent());
666 public void testReturnValuesWhenTargetTemperatureValueLocalizedIsEmpty() {
668 Status status = mock(Status.class);
669 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
671 Temperature temperature = mock(Temperature.class);
672 when(temperature.getValueLocalized()).thenReturn(Optional.empty());
674 State state = mock(State.class);
675 when(state.getTargetTemperature()).thenReturn(Arrays.asList(temperature));
676 when(state.getStatus()).thenReturn(Optional.of(status));
678 Device device = mock(Device.class);
679 when(device.getState()).thenReturn(Optional.of(state));
680 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
683 Optional<Integer> targetTemperature = deviceState.getTargetTemperature(0);
686 assertFalse(targetTemperature.isPresent());
690 public void testReturnValuesWhenTargetTemperatureValueLocalizedIsValid() {
692 Temperature temperature = mock(Temperature.class);
693 when(temperature.getValueLocalized()).thenReturn(Optional.of(20));
695 State state = mock(State.class);
696 Status status = mock(Status.class);
697 Device device = mock(Device.class);
698 when(state.getStatus()).thenReturn(Optional.of(status));
699 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
700 when(state.getTargetTemperature()).thenReturn(Arrays.asList(temperature));
701 when(device.getState()).thenReturn(Optional.of(state));
702 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
705 Integer targetTemperature = deviceState.getTargetTemperature(0).get();
708 assertEquals(Integer.valueOf(20), targetTemperature);
712 public void testReturnValuesWhenTemperatureIsEmpty() {
714 Status status = mock(Status.class);
715 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
717 State state = mock(State.class);
718 when(state.getTemperature()).thenReturn(Collections.emptyList());
719 when(state.getStatus()).thenReturn(Optional.of(status));
721 Device device = mock(Device.class);
722 when(device.getState()).thenReturn(Optional.of(state));
723 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
726 Optional<Integer> temperature = deviceState.getTemperature(0);
729 assertFalse(temperature.isPresent());
733 public void testReturnValuesWhenVentilationStepIsEmpty() {
735 State state = mock(State.class);
736 when(state.getVentilationStep()).thenReturn(Optional.empty());
738 Device device = mock(Device.class);
739 when(device.getState()).thenReturn(Optional.of(state));
740 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
743 Optional<String> ventilationStep = deviceState.getVentilationStep();
744 Optional<Integer> ventilationStepRaw = deviceState.getVentilationStepRaw();
747 assertFalse(ventilationStep.isPresent());
748 assertFalse(ventilationStepRaw.isPresent());
752 public void testReturnValuesWhenTemperatureIndexIsOutOfRange() {
754 Status status = mock(Status.class);
755 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
757 State state = mock(State.class);
758 when(state.getTemperature()).thenReturn(new LinkedList<>());
759 when(state.getStatus()).thenReturn(Optional.of(status));
761 Device device = mock(Device.class);
762 when(device.getState()).thenReturn(Optional.of(state));
763 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
766 Optional<Integer> temperature = deviceState.getTemperature(-1);
769 assertFalse(temperature.isPresent());
773 public void testReturnValuesWhenTemperatureValueLocalizedIsEmpty() {
775 Status status = mock(Status.class);
776 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
778 Temperature temperatureMock = mock(Temperature.class);
779 when(temperatureMock.getValueLocalized()).thenReturn(Optional.empty());
781 State state = mock(State.class);
782 when(state.getTemperature()).thenReturn(Arrays.asList(temperatureMock));
783 when(state.getStatus()).thenReturn(Optional.of(status));
785 Device device = mock(Device.class);
786 when(device.getState()).thenReturn(Optional.of(state));
787 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
790 Optional<Integer> temperature = deviceState.getTemperature(0);
793 assertFalse(temperature.isPresent());
797 public void testReturnValuesWhenTemperatureValueLocalizedIsValid() {
799 Temperature temperatureMock = mock(Temperature.class);
800 when(temperatureMock.getValueLocalized()).thenReturn(Optional.of(10));
802 State state = mock(State.class);
803 Device device = mock(Device.class);
804 Status status = mock(Status.class);
805 when(state.getTemperature()).thenReturn(Arrays.asList(temperatureMock));
806 when(state.getStatus()).thenReturn(Optional.of(status));
807 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
808 when(device.getState()).thenReturn(Optional.of(state));
809 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
812 Integer temperature = deviceState.getTemperature(0).get();
815 assertEquals(Integer.valueOf(10), temperature);
819 public void testReturnValuesWhenPlatStepIndexIsOutOfRange() {
821 Status status = mock(Status.class);
822 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
824 State state = mock(State.class);
825 when(state.getPlateStep()).thenReturn(Collections.emptyList());
826 when(state.getStatus()).thenReturn(Optional.of(status));
828 Device device = mock(Device.class);
829 when(device.getState()).thenReturn(Optional.of(state));
830 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
833 int plateStepCount = deviceState.getPlateStepCount().get();
834 Optional<String> plateStep = deviceState.getPlateStep(0);
835 Optional<Integer> plateStepRaw = deviceState.getPlateStepRaw(0);
838 assertEquals(0, plateStepCount);
839 assertFalse(plateStep.isPresent());
840 assertFalse(plateStepRaw.isPresent());
844 public void testReturnValuesWhenPlateStepValueIsEmpty() {
846 Status status = mock(Status.class);
847 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
849 PlateStep plateStepMock = mock(PlateStep.class);
850 when(plateStepMock.getValueRaw()).thenReturn(Optional.empty());
851 when(plateStepMock.getValueLocalized()).thenReturn(Optional.empty());
853 State state = mock(State.class);
854 when(state.getPlateStep()).thenReturn(Collections.singletonList(plateStepMock));
855 when(state.getStatus()).thenReturn(Optional.of(status));
857 Device device = mock(Device.class);
858 when(device.getState()).thenReturn(Optional.of(state));
859 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
862 int plateStepCount = deviceState.getPlateStepCount().get();
863 Optional<String> plateStep = deviceState.getPlateStep(0);
864 Optional<Integer> plateStepRaw = deviceState.getPlateStepRaw(0);
867 assertEquals(1, plateStepCount);
868 assertFalse(plateStep.isPresent());
869 assertFalse(plateStepRaw.isPresent());
873 public void testReturnValuesWhenPlateStepValueIsValid() {
875 PlateStep plateStepMock = mock(PlateStep.class);
876 when(plateStepMock.getValueRaw()).thenReturn(Optional.of(2));
877 when(plateStepMock.getValueLocalized()).thenReturn(Optional.of("1."));
879 State state = mock(State.class);
880 Status status = mock(Status.class);
881 Device device = mock(Device.class);
882 when(state.getStatus()).thenReturn(Optional.of(status));
883 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
884 when(state.getPlateStep()).thenReturn(Arrays.asList(plateStepMock));
885 when(device.getState()).thenReturn(Optional.of(state));
886 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
889 int plateStepCount = deviceState.getPlateStepCount().get();
890 String plateStep = deviceState.getPlateStep(0).get();
891 int plateStepRaw = deviceState.getPlateStepRaw(0).get();
894 assertEquals(1, plateStepCount);
895 assertEquals("1.", plateStep);
896 assertEquals(2, plateStepRaw);
900 public void testReturnValuesWhenRemainingTimeIsEmpty() {
902 State state = mock(State.class);
903 when(state.getRemainingTime()).thenReturn(Optional.empty());
904 when(state.getElapsedTime()).thenReturn(Optional.of(Arrays.asList(0, 0)));
906 Device device = mock(Device.class);
907 when(device.getState()).thenReturn(Optional.of(state));
908 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
911 Optional<Integer> progress = deviceState.getProgress();
914 assertFalse(progress.isPresent());
918 public void testReturnValuesWhenRemainingTimeSizeIsNotTwo() {
920 Status status = mock(Status.class);
921 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
923 State state = mock(State.class);
924 when(state.getRemainingTime()).thenReturn(Optional.of(Arrays.asList(2)));
925 when(state.getElapsedTime()).thenReturn(Optional.of(Arrays.asList(0, 0)));
926 when(state.getStatus()).thenReturn(Optional.of(status));
928 Device device = mock(Device.class);
929 when(device.getState()).thenReturn(Optional.of(state));
930 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
933 Optional<Integer> progress = deviceState.getProgress();
936 assertFalse(progress.isPresent());
940 public void testReturnValuesWhenRemoteEnableIsEmpty() {
942 State state = mock(State.class);
943 when(state.getRemoteEnable()).thenReturn(Optional.empty());
945 Device device = mock(Device.class);
946 when(device.getState()).thenReturn(Optional.of(state));
947 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
950 Optional<Boolean> remoteControlEnabled = deviceState.isRemoteControlEnabled();
953 assertFalse(remoteControlEnabled.isPresent());
957 public void testReturnValuesWhenFullRemoteControlIsEmpty() {
959 RemoteEnable remoteEnable = mock(RemoteEnable.class);
960 when(remoteEnable.getFullRemoteControl()).thenReturn(Optional.empty());
962 State state = mock(State.class);
963 when(state.getRemoteEnable()).thenReturn(Optional.of(remoteEnable));
965 Device device = mock(Device.class);
966 when(device.getState()).thenReturn(Optional.of(state));
967 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
970 Optional<Boolean> remoteControlEnabled = deviceState.isRemoteControlEnabled();
973 assertFalse(remoteControlEnabled.isPresent());
977 public void testReturnValuesWhenFullRemoteControlIsNotNull() {
979 RemoteEnable remoteEnable = mock(RemoteEnable.class);
980 when(remoteEnable.getFullRemoteControl()).thenReturn(Optional.of(true));
982 State state = mock(State.class);
983 when(state.getRemoteEnable()).thenReturn(Optional.of(remoteEnable));
985 Device device = mock(Device.class);
986 when(device.getState()).thenReturn(Optional.of(state));
987 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
990 Boolean remoteControlEnabled = deviceState.isRemoteControlEnabled().get();
993 assertTrue(remoteControlEnabled);
997 public void testReturnValuesWhenElapsedTimeIsEmpty() {
999 Status status = mock(Status.class);
1000 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1002 State state = mock(State.class);
1003 when(state.getElapsedTime()).thenReturn(Optional.empty());
1004 when(state.getRemainingTime()).thenReturn(Optional.of(Arrays.asList(0, 0)));
1005 when(state.getStatus()).thenReturn(Optional.of(status));
1007 Device device = mock(Device.class);
1008 when(device.getState()).thenReturn(Optional.of(state));
1009 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1012 Optional<Integer> progress = deviceState.getProgress();
1015 assertFalse(progress.isPresent());
1019 public void testReturnValuesWhenElapsedTimeSizeIsNotTwo() {
1021 Status status = mock(Status.class);
1022 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1024 State state = mock(State.class);
1025 when(state.getElapsedTime()).thenReturn(Optional.of(Arrays.asList(0)));
1026 when(state.getRemainingTime()).thenReturn(Optional.of(Arrays.asList(0, 0)));
1027 when(state.getStatus()).thenReturn(Optional.of(status));
1029 Device device = mock(Device.class);
1030 when(device.getState()).thenReturn(Optional.of(state));
1031 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1034 Optional<Integer> progress = deviceState.getProgress();
1037 assertFalse(progress.isPresent());
1041 public void testReturnValuesWhenElapsedTimeAndRemainingTimeIsZero() {
1043 Status status = mock(Status.class);
1044 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1046 State state = mock(State.class);
1047 when(state.getElapsedTime()).thenReturn(Optional.of(Arrays.asList(0, 0)));
1048 when(state.getRemainingTime()).thenReturn(Optional.of(Arrays.asList(0, 0)));
1049 when(state.getStatus()).thenReturn(Optional.of(status));
1051 Device device = mock(Device.class);
1052 when(device.getState()).thenReturn(Optional.of(state));
1053 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1056 Optional<Integer> progress = deviceState.getProgress();
1059 assertFalse(progress.isPresent());
1063 public void whenElapsedTimeIsNotPresentThenEmptyIsReturned() {
1065 Status status = mock(Status.class);
1066 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1068 State state = mock(State.class);
1069 when(state.getStatus()).thenReturn(Optional.of(status));
1070 when(state.getElapsedTime()).thenReturn(Optional.empty());
1072 Device device = mock(Device.class);
1073 when(device.getState()).thenReturn(Optional.of(state));
1075 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1078 Optional<Integer> elapsedTime = deviceState.getElapsedTime();
1081 assertFalse(elapsedTime.isPresent());
1085 public void whenElapsedTimeIsAnEmptyListThenEmptyIsReturned() {
1087 Status status = mock(Status.class);
1088 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1090 State state = mock(State.class);
1091 when(state.getStatus()).thenReturn(Optional.of(status));
1092 when(state.getElapsedTime()).thenReturn(Optional.of(Collections.emptyList()));
1094 Device device = mock(Device.class);
1095 when(device.getState()).thenReturn(Optional.of(state));
1097 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1100 Optional<Integer> elapsedTime = deviceState.getElapsedTime();
1103 assertFalse(elapsedTime.isPresent());
1107 public void whenElapsedTimeHasOnlyOneElementThenEmptyIsReturned() {
1109 Status status = mock(Status.class);
1110 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1112 State state = mock(State.class);
1113 when(state.getStatus()).thenReturn(Optional.of(status));
1114 when(state.getElapsedTime()).thenReturn(Optional.of(Collections.singletonList(2)));
1116 Device device = mock(Device.class);
1117 when(device.getState()).thenReturn(Optional.of(state));
1119 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1122 Optional<Integer> elapsedTime = deviceState.getElapsedTime();
1125 assertFalse(elapsedTime.isPresent());
1129 public void whenElapsedTimeHasThreeElementsThenEmptyIsReturned() {
1131 Status status = mock(Status.class);
1132 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1134 State state = mock(State.class);
1135 when(state.getStatus()).thenReturn(Optional.of(status));
1136 when(state.getElapsedTime()).thenReturn(Optional.of(Arrays.asList(1, 2, 3)));
1138 Device device = mock(Device.class);
1139 when(device.getState()).thenReturn(Optional.of(state));
1141 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1144 Optional<Integer> elapsedTime = deviceState.getElapsedTime();
1147 assertFalse(elapsedTime.isPresent());
1151 public void whenElapsedTimeHasTwoElementsThenTheTotalNumberOfSecondsIsReturned() {
1153 Status status = mock(Status.class);
1154 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1156 State state = mock(State.class);
1157 when(state.getStatus()).thenReturn(Optional.of(status));
1158 when(state.getElapsedTime()).thenReturn(Optional.of(Arrays.asList(1, 2)));
1160 Device device = mock(Device.class);
1161 when(device.getState()).thenReturn(Optional.of(state));
1163 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1166 Optional<Integer> elapsedTime = deviceState.getElapsedTime();
1169 assertTrue(elapsedTime.isPresent());
1170 assertEquals(Integer.valueOf((60 + 2) * 60), elapsedTime.get());
1174 public void whenDeviceIsInOffStateThenElapsedTimeIsEmpty() {
1176 Status status = mock(Status.class);
1177 when(status.getValueRaw()).thenReturn(Optional.of(StateType.OFF.getCode()));
1179 State state = mock(State.class);
1180 when(state.getStatus()).thenReturn(Optional.of(status));
1181 when(state.getElapsedTime()).thenReturn(Optional.of(Arrays.asList(1, 2)));
1183 Device device = mock(Device.class);
1184 when(device.getState()).thenReturn(Optional.of(state));
1186 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1189 Optional<Integer> elapsedTime = deviceState.getElapsedTime();
1192 assertFalse(elapsedTime.isPresent());
1196 public void testReturnValuesWhenProgressIs50Percent() {
1198 State state = mock(State.class);
1199 when(state.getElapsedTime()).thenReturn(Optional.of(Arrays.asList(0, 45)));
1200 when(state.getRemainingTime()).thenReturn(Optional.of(Arrays.asList(0, 45)));
1202 Device device = mock(Device.class);
1203 Status status = mock(Status.class);
1204 when(state.getStatus()).thenReturn(Optional.of(status));
1205 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1206 when(device.getState()).thenReturn(Optional.of(state));
1207 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1210 Integer progress = deviceState.getProgress().get();
1213 assertEquals(Integer.valueOf(50), progress);
1217 public void testReturnValuesWhenProgressIs25Percent() {
1219 State state = mock(State.class);
1220 when(state.getElapsedTime()).thenReturn(Optional.of(Arrays.asList(0, 15)));
1221 when(state.getRemainingTime()).thenReturn(Optional.of(Arrays.asList(0, 45)));
1223 Device device = mock(Device.class);
1224 Status status = mock(Status.class);
1225 when(state.getStatus()).thenReturn(Optional.of(status));
1226 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1227 when(device.getState()).thenReturn(Optional.of(state));
1228 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1231 Integer progress = deviceState.getProgress().get();
1234 assertEquals(Integer.valueOf(25), progress);
1238 public void testReturnValuesWhenProgressIs0Percent() {
1240 State state = mock(State.class);
1241 when(state.getElapsedTime()).thenReturn(Optional.of(Arrays.asList(0, 0)));
1242 when(state.getRemainingTime()).thenReturn(Optional.of(Arrays.asList(0, 45)));
1244 Device device = mock(Device.class);
1245 Status status = mock(Status.class);
1246 when(state.getStatus()).thenReturn(Optional.of(status));
1247 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1248 when(device.getState()).thenReturn(Optional.of(state));
1249 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1252 Integer progress = deviceState.getProgress().get();
1255 assertEquals(Integer.valueOf(0), progress);
1259 public void testReturnValuesWhenSignalDoorIsEmpty() {
1261 State state = mock(State.class);
1262 when(state.getSignalDoor()).thenReturn(Optional.empty());
1264 Status status = mock(Status.class);
1265 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1266 when(state.getStatus()).thenReturn(Optional.of(status));
1268 Device device = mock(Device.class);
1269 when(device.getState()).thenReturn(Optional.of(state));
1271 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1274 Optional<Boolean> doorState = deviceState.getDoorState();
1275 Optional<Boolean> doorAlarm = deviceState.getDoorAlarm();
1278 assertFalse(doorState.isPresent());
1279 assertFalse(doorAlarm.isPresent());
1283 public void testReturnValuesWhenSignalDoorIsTrue() {
1285 State state = mock(State.class);
1286 when(state.getSignalDoor()).thenReturn(Optional.of(true));
1288 Status status = mock(Status.class);
1289 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1290 when(state.getStatus()).thenReturn(Optional.of(status));
1292 Device device = mock(Device.class);
1293 when(device.getState()).thenReturn(Optional.of(state));
1295 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1298 Optional<Boolean> doorState = deviceState.getDoorState();
1301 assertTrue(doorState.get());
1305 public void testReturnValuesWhenSignalDoorIsFalse() {
1307 State state = mock(State.class);
1308 when(state.getSignalDoor()).thenReturn(Optional.of(false));
1310 Status status = mock(Status.class);
1311 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1312 when(state.getStatus()).thenReturn(Optional.of(status));
1314 Device device = mock(Device.class);
1315 when(device.getState()).thenReturn(Optional.of(state));
1317 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1320 Optional<Boolean> doorState = deviceState.getDoorState();
1323 assertFalse(doorState.get());
1327 public void testReturnValuesWhenSignalFailureIsEmpty() {
1329 State state = mock(State.class);
1330 when(state.getSignalDoor()).thenReturn(Optional.of(true));
1331 when(state.getSignalFailure()).thenReturn(Optional.empty());
1333 Status status = mock(Status.class);
1334 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1335 when(state.getStatus()).thenReturn(Optional.of(status));
1337 Device device = mock(Device.class);
1338 when(device.getState()).thenReturn(Optional.of(state));
1340 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1343 Optional<Boolean> doorAlarm = deviceState.getDoorAlarm();
1346 assertFalse(doorAlarm.isPresent());
1350 public void testReturnValuesWhenDoorAlarmIsActive() {
1352 State state = mock(State.class);
1353 when(state.getSignalDoor()).thenReturn(Optional.of(true));
1354 when(state.getSignalFailure()).thenReturn(Optional.of(true));
1356 Status status = mock(Status.class);
1357 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1358 when(state.getStatus()).thenReturn(Optional.of(status));
1360 Device device = mock(Device.class);
1361 when(device.getState()).thenReturn(Optional.of(state));
1363 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1366 Optional<Boolean> doorAlarm = deviceState.getDoorAlarm();
1369 assertTrue(doorAlarm.get());
1373 public void testReturnValuesWhenDoorAlarmIsNotActiveBecauseOfNoDoorSignal() {
1375 State state = mock(State.class);
1376 when(state.getSignalDoor()).thenReturn(Optional.of(false));
1377 when(state.getSignalFailure()).thenReturn(Optional.of(true));
1379 Status status = mock(Status.class);
1380 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1381 when(state.getStatus()).thenReturn(Optional.of(status));
1383 Device device = mock(Device.class);
1384 when(device.getState()).thenReturn(Optional.of(state));
1386 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1389 Optional<Boolean> doorAlarm = deviceState.getDoorAlarm();
1392 assertFalse(doorAlarm.get());
1396 public void testReturnValuesWhenDoorAlarmIsNotActiveBecauseOfNoFailureSignal() {
1398 State state = mock(State.class);
1399 when(state.getSignalDoor()).thenReturn(Optional.of(true));
1400 when(state.getSignalFailure()).thenReturn(Optional.of(false));
1402 Status status = mock(Status.class);
1403 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1404 when(state.getStatus()).thenReturn(Optional.of(status));
1406 Device device = mock(Device.class);
1407 when(device.getState()).thenReturn(Optional.of(state));
1409 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1412 Optional<Boolean> doorAlarm = deviceState.getDoorAlarm();
1415 assertFalse(doorAlarm.get());
1419 public void testReturnValuesWhenIdentIsEmpty() {
1421 Device device = mock(Device.class);
1422 when(device.getIdent()).thenReturn(Optional.empty());
1423 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1426 Optional<String> type = deviceState.getType();
1427 DeviceType rawType = deviceState.getRawType();
1428 Optional<String> deviceName = deviceState.getDeviceName();
1429 Optional<String> fabNumber = deviceState.getFabNumber();
1430 Optional<String> techType = deviceState.getTechType();
1433 assertFalse(type.isPresent());
1434 assertEquals(DeviceType.UNKNOWN, rawType);
1435 assertFalse(deviceName.isPresent());
1436 assertFalse(fabNumber.isPresent());
1437 assertFalse(techType.isPresent());
1441 public void testReturnValuesWhenTypeIsEmpty() {
1443 Ident ident = mock(Ident.class);
1444 when(ident.getType()).thenReturn(Optional.empty());
1446 Device device = mock(Device.class);
1447 when(device.getIdent()).thenReturn(Optional.of(ident));
1448 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1451 Optional<String> type = deviceState.getType();
1452 DeviceType rawType = deviceState.getRawType();
1455 assertFalse(type.isPresent());
1456 assertEquals(DeviceType.UNKNOWN, rawType);
1460 public void testReturnValuesWhenTypeValueLocalizedIsEmpty() {
1462 Type typeMock = mock(Type.class);
1463 when(typeMock.getValueLocalized()).thenReturn(Optional.empty());
1465 Ident ident = mock(Ident.class);
1466 when(ident.getType()).thenReturn(Optional.of(typeMock));
1468 Device device = mock(Device.class);
1469 when(device.getIdent()).thenReturn(Optional.of(ident));
1470 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1473 Optional<String> type = deviceState.getType();
1476 assertFalse(type.isPresent());
1480 public void testReturnValuesWhenTypeValueLocalizedIsNotNull() {
1482 Type typeMock = mock(Type.class);
1483 when(typeMock.getValueLocalized()).thenReturn(Optional.of("Hood"));
1485 Ident ident = mock(Ident.class);
1486 when(ident.getType()).thenReturn(Optional.of(typeMock));
1488 Device device = mock(Device.class);
1489 when(device.getIdent()).thenReturn(Optional.of(ident));
1490 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1493 String type = deviceState.getType().get();
1496 assertEquals("Hood", type);
1500 public void testReturnValuesWhenTypeValueRawIsNotNull() {
1502 Type typeMock = mock(Type.class);
1503 when(typeMock.getValueRaw()).thenReturn(DeviceType.COFFEE_SYSTEM);
1505 Ident ident = mock(Ident.class);
1506 when(ident.getType()).thenReturn(Optional.of(typeMock));
1508 Device device = mock(Device.class);
1509 when(device.getIdent()).thenReturn(Optional.of(ident));
1510 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1513 DeviceType rawType = deviceState.getRawType();
1516 assertEquals(DeviceType.COFFEE_SYSTEM, rawType);
1520 public void testReturnValuesWhenDeviceNameIsEmpty() {
1522 Ident ident = mock(Ident.class);
1523 when(ident.getDeviceName()).thenReturn(Optional.empty());
1525 Device device = mock(Device.class);
1526 when(device.getIdent()).thenReturn(Optional.of(ident));
1527 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1530 Optional<String> deviceName = deviceState.getDeviceName();
1533 assertFalse(deviceName.isPresent());
1537 public void testReturnValuesWhenDeviceNameIsEmptyString() {
1539 Ident ident = mock(Ident.class);
1540 when(ident.getDeviceName()).thenReturn(Optional.of(""));
1542 Device device = mock(Device.class);
1543 when(device.getIdent()).thenReturn(Optional.of(ident));
1544 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1547 Optional<String> deviceName = deviceState.getDeviceName();
1550 assertFalse(deviceName.isPresent());
1554 public void testReturnValuesWhenDeviceNameIsValid() {
1556 Ident ident = mock(Ident.class);
1557 when(ident.getDeviceName()).thenReturn(Optional.of("MyWashingMachine"));
1559 Device device = mock(Device.class);
1560 when(device.getIdent()).thenReturn(Optional.of(ident));
1561 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1564 Optional<String> deviceName = deviceState.getDeviceName();
1567 assertEquals(Optional.of("MyWashingMachine"), deviceName);
1571 public void testReturnValuesWhenFabNumberIsNotNull() {
1573 DeviceIdentLabel deviceIdentLabel = mock(DeviceIdentLabel.class);
1574 when(deviceIdentLabel.getFabNumber()).thenReturn(Optional.of("000061431659"));
1576 Ident ident = mock(Ident.class);
1577 when(ident.getDeviceIdentLabel()).thenReturn(Optional.of(deviceIdentLabel));
1579 Device device = mock(Device.class);
1580 when(device.getIdent()).thenReturn(Optional.of(ident));
1581 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1584 String fabNumber = deviceState.getFabNumber().get();
1587 assertEquals("000061431659", fabNumber);
1591 public void testReturnValuesWhenTechTypeIsNotNull() {
1593 DeviceIdentLabel deviceIdentLabel = mock(DeviceIdentLabel.class);
1594 when(deviceIdentLabel.getTechType()).thenReturn(Optional.of("XKM3100WEC"));
1596 Ident ident = mock(Ident.class);
1597 when(ident.getDeviceIdentLabel()).thenReturn(Optional.of(deviceIdentLabel));
1599 Device device = mock(Device.class);
1600 when(device.getIdent()).thenReturn(Optional.of(ident));
1601 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1604 String techType = deviceState.getTechType().get();
1607 assertEquals("XKM3100WEC", techType);
1611 public void whenDeviceIsInFailureStateThenItHasAnError() {
1613 Status status = mock(Status.class);
1614 when(status.getValueRaw()).thenReturn(Optional.of(StateType.FAILURE.getCode()));
1616 State state = mock(State.class);
1617 when(state.getStatus()).thenReturn(Optional.of(status));
1619 Device device = mock(Device.class);
1620 when(device.getState()).thenReturn(Optional.of(state));
1621 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1624 boolean hasError = deviceState.hasError();
1627 assertTrue(hasError);
1631 public void whenDeviceIsInRunningStateAndDoesNotSignalAFailureThenItHasNoError() {
1633 Status status = mock(Status.class);
1634 when(status.getValueRaw()).thenReturn(Optional.of(StateType.RUNNING.getCode()));
1636 State state = mock(State.class);
1637 when(state.getStatus()).thenReturn(Optional.of(status));
1639 Device device = mock(Device.class);
1640 when(device.getState()).thenReturn(Optional.of(state));
1641 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1644 boolean hasError = deviceState.hasError();
1647 assertFalse(hasError);
1651 public void whenDeviceSignalsAFailureThenItHasAnError() {
1653 Status status = mock(Status.class);
1654 when(status.getValueRaw()).thenReturn(Optional.of(StateType.RUNNING.getCode()));
1656 State state = mock(State.class);
1657 when(state.getStatus()).thenReturn(Optional.of(status));
1658 when(state.getSignalFailure()).thenReturn(Optional.of(true));
1660 Device device = mock(Device.class);
1661 when(device.getState()).thenReturn(Optional.of(state));
1662 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1665 boolean hasError = deviceState.hasError();
1668 assertTrue(hasError);
1672 public void testReturnValuesForHasInfoWhenSignalInfoIsEmpty() {
1674 State state = mock(State.class);
1675 when(state.getSignalInfo()).thenReturn(Optional.empty());
1677 Status status = mock(Status.class);
1678 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1679 when(state.getStatus()).thenReturn(Optional.of(status));
1681 Device device = mock(Device.class);
1682 when(device.getState()).thenReturn(Optional.of(state));
1683 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1686 boolean hasInfo = deviceState.hasInfo();
1689 assertFalse(hasInfo);
1693 public void whenDeviceSignalsAnInfoThenItHasAnInfo() {
1695 State state = mock(State.class);
1696 when(state.getSignalInfo()).thenReturn(Optional.of(true));
1698 Status status = mock(Status.class);
1699 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1700 when(state.getStatus()).thenReturn(Optional.of(status));
1702 Device device = mock(Device.class);
1703 when(device.getState()).thenReturn(Optional.of(state));
1704 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1707 boolean hasInfo = deviceState.hasInfo();
1710 assertTrue(hasInfo);
1714 public void whenDeviceSignalsNoInfoThenItHasNoInfo() {
1716 State state = mock(State.class);
1717 when(state.getSignalInfo()).thenReturn(Optional.of(false));
1719 Status status = mock(Status.class);
1720 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1721 when(state.getStatus()).thenReturn(Optional.of(status));
1723 Device device = mock(Device.class);
1724 when(device.getState()).thenReturn(Optional.of(state));
1725 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1728 boolean hasInfo = deviceState.hasInfo();
1731 assertFalse(hasInfo);
1735 public void testReturnValuesForVentilationStep() {
1737 VentilationStep ventilationStepMock = mock(VentilationStep.class);
1738 when(ventilationStepMock.getValueLocalized()).thenReturn(Optional.of("Step 1"));
1739 when(ventilationStepMock.getValueRaw()).thenReturn(Optional.of(1));
1741 Status status = mock(Status.class);
1742 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1744 State state = mock(State.class);
1745 when(state.getVentilationStep()).thenReturn(Optional.of(ventilationStepMock));
1746 when(state.getStatus()).thenReturn(Optional.of(status));
1748 Device device = mock(Device.class);
1749 when(device.getState()).thenReturn(Optional.of(state));
1751 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1754 String ventilationStep = deviceState.getVentilationStep().get();
1755 int ventilationStepRaw = deviceState.getVentilationStepRaw().get();
1758 assertEquals("Step 1", ventilationStep);
1759 assertEquals(1, ventilationStepRaw);
1763 public void testProgramPhaseWhenDeviceIsInOffState() {
1765 ProgramPhase programPhase = mock(ProgramPhase.class);
1766 when(programPhase.getValueLocalized()).thenReturn(Optional.of("Washing"));
1767 when(programPhase.getValueRaw()).thenReturn(Optional.of(3));
1769 Status status = mock(Status.class);
1770 when(status.getValueRaw()).thenReturn(Optional.of(StateType.OFF.getCode()));
1772 State state = mock(State.class);
1773 when(state.getProgramPhase()).thenReturn(Optional.of(programPhase));
1774 when(state.getStatus()).thenReturn(Optional.of(status));
1776 Device device = mock(Device.class);
1777 when(device.getState()).thenReturn(Optional.of(state));
1779 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1782 Optional<String> phase = deviceState.getProgramPhase();
1783 Optional<Integer> phaseRaw = deviceState.getProgramPhaseRaw();
1786 assertFalse(phase.isPresent());
1787 assertFalse(phaseRaw.isPresent());
1791 public void testDryingTargetWhenDeviceIsInOffState() {
1793 DryingStep dryingStep = mock(DryingStep.class);
1794 when(dryingStep.getValueLocalized()).thenReturn(Optional.of("Schranktrocken"));
1795 when(dryingStep.getValueRaw()).thenReturn(Optional.of(3));
1797 Status status = mock(Status.class);
1798 when(status.getValueRaw()).thenReturn(Optional.of(StateType.OFF.getCode()));
1800 State state = mock(State.class);
1801 when(state.getDryingStep()).thenReturn(Optional.of(dryingStep));
1802 when(state.getStatus()).thenReturn(Optional.of(status));
1804 Device device = mock(Device.class);
1805 when(device.getState()).thenReturn(Optional.of(state));
1807 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1810 Optional<String> dryingTarget = deviceState.getDryingTarget();
1811 Optional<Integer> dryingTargetRaw = deviceState.getDryingTargetRaw();
1814 assertFalse(dryingTarget.isPresent());
1815 assertFalse(dryingTargetRaw.isPresent());
1819 public void testVentilationStepWhenDeviceIsInOffState() {
1821 VentilationStep ventilationStep = mock(VentilationStep.class);
1822 when(ventilationStep.getValueLocalized()).thenReturn(Optional.of("Stufe 1"));
1823 when(ventilationStep.getValueRaw()).thenReturn(Optional.of(1));
1825 Status status = mock(Status.class);
1826 when(status.getValueRaw()).thenReturn(Optional.of(StateType.OFF.getCode()));
1828 State state = mock(State.class);
1829 when(state.getVentilationStep()).thenReturn(Optional.of(ventilationStep));
1830 when(state.getStatus()).thenReturn(Optional.of(status));
1832 Device device = mock(Device.class);
1833 when(device.getState()).thenReturn(Optional.of(state));
1835 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1838 Optional<String> step = deviceState.getVentilationStep();
1839 Optional<Integer> stepRaw = deviceState.getVentilationStepRaw();
1842 assertFalse(step.isPresent());
1843 assertFalse(stepRaw.isPresent());
1847 public void testReturnValuesWhenDeviceIsInOffState() {
1849 Device device = mock(Device.class);
1850 State state = mock(State.class);
1851 Status status = mock(Status.class);
1853 when(device.getState()).thenReturn(Optional.of(state));
1854 when(state.getStatus()).thenReturn(Optional.of(status));
1855 when(status.getValueRaw()).thenReturn(Optional.of(StateType.OFF.getCode()));
1856 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1858 // Test SelectedProgram:
1859 ProgramId programId = mock(ProgramId.class);
1860 when(state.getProgramId()).thenReturn(Optional.of(programId));
1861 when(programId.getValueLocalized()).thenReturn(Optional.of("Washing"));
1863 Optional<String> selectedProgram = deviceState.getSelectedProgram();
1865 assertFalse(selectedProgram.isPresent());
1867 // Test TargetTemperature:
1868 Temperature targetTemperatureMock = mock(Temperature.class);
1869 when(state.getTargetTemperature()).thenReturn(Collections.singletonList(targetTemperatureMock));
1870 when(targetTemperatureMock.getValueLocalized()).thenReturn(Optional.of(200));
1872 Optional<Integer> targetTemperature = deviceState.getTargetTemperature(0);
1874 assertFalse(targetTemperature.isPresent());
1876 // Test Temperature:
1877 Temperature temperature = mock(Temperature.class);
1878 when(state.getTemperature()).thenReturn(Collections.singletonList(temperature));
1879 when(temperature.getValueLocalized()).thenReturn(Optional.of(200));
1881 Optional<Integer> t = deviceState.getTemperature(0);
1883 assertFalse(t.isPresent());
1886 when(state.getElapsedTime()).thenReturn(Optional.of(Arrays.asList(0, 5)));
1887 when(state.getRemainingTime()).thenReturn(Optional.of(Arrays.asList(1, 5)));
1889 Optional<Integer> progress = deviceState.getProgress();
1891 assertFalse(progress.isPresent());
1895 public void testWhenDeviceIsInOffStateThenGetSpinningSpeedReturnsNull() {
1897 Status status = mock(Status.class);
1898 when(status.getValueRaw()).thenReturn(Optional.of(StateType.OFF.getCode()));
1900 SpinningSpeed spinningSpeed = mock(SpinningSpeed.class);
1901 when(spinningSpeed.getValueRaw()).thenReturn(Optional.of(800));
1902 when(spinningSpeed.getValueLocalized()).thenReturn(Optional.of("800"));
1903 when(spinningSpeed.getUnit()).thenReturn(Optional.of("rpm"));
1905 State state = mock(State.class);
1906 when(state.getStatus()).thenReturn(Optional.of(status));
1907 when(state.getSpinningSpeed()).thenReturn(Optional.of(spinningSpeed));
1909 Device device = mock(Device.class);
1910 when(device.getState()).thenReturn(Optional.of(state));
1912 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1915 Optional<String> speed = deviceState.getSpinningSpeed();
1916 Optional<Integer> speedRaw = deviceState.getSpinningSpeedRaw();
1919 assertFalse(speed.isPresent());
1920 assertFalse(speedRaw.isPresent());
1924 public void testGetSpinningSpeedReturnsNullWhenSpinningSpeedIsEmpty() {
1926 Status status = mock(Status.class);
1927 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1929 State state = mock(State.class);
1930 when(state.getStatus()).thenReturn(Optional.of(status));
1931 when(state.getSpinningSpeed()).thenReturn(Optional.empty());
1933 Device device = mock(Device.class);
1934 when(device.getState()).thenReturn(Optional.of(state));
1936 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1939 Optional<String> spinningSpeed = deviceState.getSpinningSpeed();
1940 Optional<Integer> spinningSpeedRaw = deviceState.getSpinningSpeedRaw();
1943 assertFalse(spinningSpeed.isPresent());
1944 assertFalse(spinningSpeedRaw.isPresent());
1948 public void testGetSpinningSpeedReturnsNullWhenSpinningSpeedRawValueIsEmpty() {
1950 Status status = mock(Status.class);
1951 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1953 SpinningSpeed spinningSpeedMock = mock(SpinningSpeed.class);
1954 when(spinningSpeedMock.getValueRaw()).thenReturn(Optional.empty());
1955 when(spinningSpeedMock.getValueLocalized()).thenReturn(Optional.of("1200"));
1957 State state = mock(State.class);
1958 when(state.getStatus()).thenReturn(Optional.of(status));
1959 when(state.getSpinningSpeed()).thenReturn(Optional.of(spinningSpeedMock));
1961 Device device = mock(Device.class);
1962 when(device.getState()).thenReturn(Optional.of(state));
1964 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1967 Optional<String> spinningSpeed = deviceState.getSpinningSpeed();
1968 Optional<Integer> spinningSpeedRaw = deviceState.getSpinningSpeedRaw();
1971 assertFalse(spinningSpeed.isPresent());
1972 assertFalse(spinningSpeedRaw.isPresent());
1976 public void testGetSpinningSpeedReturnsValidValueWhenSpinningSpeedRawValueIsNotNull() {
1978 Status status = mock(Status.class);
1979 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
1981 SpinningSpeed spinningSpeedMock = mock(SpinningSpeed.class);
1982 when(spinningSpeedMock.getValueRaw()).thenReturn(Optional.of(1200));
1983 when(spinningSpeedMock.getValueLocalized()).thenReturn(Optional.of("1200"));
1985 State state = mock(State.class);
1986 when(state.getStatus()).thenReturn(Optional.of(status));
1987 when(state.getSpinningSpeed()).thenReturn(Optional.of(spinningSpeedMock));
1989 Device device = mock(Device.class);
1990 when(device.getState()).thenReturn(Optional.of(state));
1992 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
1995 String spinningSpeed = deviceState.getSpinningSpeed().get();
1996 int spinningSpeedRaw = deviceState.getSpinningSpeedRaw().get();
1999 assertEquals("1200", spinningSpeed);
2000 assertEquals(1200, spinningSpeedRaw);
2004 public void testGetLightStateWhenDeviceIsOff() {
2006 Status status = mock(Status.class);
2007 when(status.getValueRaw()).thenReturn(Optional.of(StateType.OFF.getCode()));
2009 State state = mock(State.class);
2010 when(state.getStatus()).thenReturn(Optional.of(status));
2012 Device device = mock(Device.class);
2013 when(device.getState()).thenReturn(Optional.of(state));
2015 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2018 Optional<Boolean> lightState = deviceState.getLightState();
2021 assertFalse(lightState.isPresent());
2025 public void testGetLightStateWhenLightIsUnknown() {
2027 Status status = mock(Status.class);
2028 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
2030 State state = mock(State.class);
2031 when(state.getStatus()).thenReturn(Optional.of(status));
2032 when(state.getLight()).thenReturn(Light.UNKNOWN);
2034 Device device = mock(Device.class);
2035 when(device.getState()).thenReturn(Optional.of(state));
2037 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2040 Optional<Boolean> lightState = deviceState.getLightState();
2043 assertFalse(lightState.isPresent());
2047 public void testGetLightStateWhenLightIsEnabled() {
2049 Status status = mock(Status.class);
2050 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
2052 State state = mock(State.class);
2053 when(state.getStatus()).thenReturn(Optional.of(status));
2054 when(state.getLight()).thenReturn(Light.ENABLE);
2056 Device device = mock(Device.class);
2057 when(device.getState()).thenReturn(Optional.of(state));
2059 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2062 Boolean lightState = deviceState.getLightState().get();
2065 assertEquals(Boolean.valueOf(true), lightState);
2069 public void testGetLightStateWhenLightIsDisabled() {
2071 Status status = mock(Status.class);
2072 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
2074 State state = mock(State.class);
2075 when(state.getStatus()).thenReturn(Optional.of(status));
2076 when(state.getLight()).thenReturn(Light.DISABLE);
2078 Device device = mock(Device.class);
2079 when(device.getState()).thenReturn(Optional.of(state));
2081 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2084 Boolean lightState = deviceState.getLightState().get();
2087 assertEquals(Boolean.valueOf(false), lightState);
2091 public void testGetLightStateWhenLightIsNotSupported() {
2093 Status status = mock(Status.class);
2094 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
2096 State state = mock(State.class);
2097 when(state.getStatus()).thenReturn(Optional.of(status));
2098 when(state.getLight()).thenReturn(Light.NOT_SUPPORTED);
2100 Device device = mock(Device.class);
2101 when(device.getState()).thenReturn(Optional.of(state));
2103 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2106 Optional<Boolean> lightState = deviceState.getLightState();
2109 assertFalse(lightState.isPresent());
2113 public void testGetCurrentWaterConsumptionWhenEcoFeedbackIsNotPresent() {
2115 Status status = mock(Status.class);
2116 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
2118 State state = mock(State.class);
2119 when(state.getStatus()).thenReturn(Optional.of(status));
2120 when(state.getEcoFeedback()).thenReturn(Optional.empty());
2122 Device device = mock(Device.class);
2123 when(device.getState()).thenReturn(Optional.of(state));
2125 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2128 Optional<Quantity> waterConsumption = deviceState.getCurrentWaterConsumption();
2131 assertFalse(waterConsumption.isPresent());
2135 public void testGetCurrentWaterConsumptionWhenCurrentWaterConsumptionIsNotPresent() {
2137 Status status = mock(Status.class);
2138 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
2140 EcoFeedback ecoFeedback = mock(EcoFeedback.class);
2141 when(ecoFeedback.getCurrentWaterConsumption()).thenReturn(Optional.empty());
2143 State state = mock(State.class);
2144 when(state.getStatus()).thenReturn(Optional.of(status));
2145 when(state.getEcoFeedback()).thenReturn(Optional.of(ecoFeedback));
2147 Device device = mock(Device.class);
2148 when(device.getState()).thenReturn(Optional.of(state));
2150 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2153 Optional<Quantity> waterConsumption = deviceState.getCurrentWaterConsumption();
2156 assertFalse(waterConsumption.isPresent());
2160 public void testGetCurrentWaterConsumptionWhenCurrentWaterConsumptionIsEmpty() {
2162 Status status = mock(Status.class);
2163 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
2165 WaterConsumption currentWaterConsumption = mock(WaterConsumption.class);
2166 when(currentWaterConsumption.getUnit()).thenReturn(Optional.empty());
2167 when(currentWaterConsumption.getValue()).thenReturn(Optional.empty());
2169 EcoFeedback ecoFeedback = mock(EcoFeedback.class);
2170 when(ecoFeedback.getCurrentWaterConsumption()).thenReturn(Optional.of(currentWaterConsumption));
2172 State state = mock(State.class);
2173 when(state.getStatus()).thenReturn(Optional.of(status));
2174 when(state.getEcoFeedback()).thenReturn(Optional.of(ecoFeedback));
2176 Device device = mock(Device.class);
2177 when(device.getState()).thenReturn(Optional.of(state));
2179 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2182 Optional<Quantity> waterConsumption = deviceState.getCurrentWaterConsumption();
2185 assertFalse(waterConsumption.isPresent());
2189 public void testGetCurrentWaterConsumptionWhenValueIsNotPresent() {
2191 Status status = mock(Status.class);
2192 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
2194 WaterConsumption currentWaterConsumption = mock(WaterConsumption.class);
2195 when(currentWaterConsumption.getUnit()).thenReturn(Optional.of("l"));
2196 when(currentWaterConsumption.getValue()).thenReturn(Optional.empty());
2198 EcoFeedback ecoFeedback = mock(EcoFeedback.class);
2199 when(ecoFeedback.getCurrentWaterConsumption()).thenReturn(Optional.of(currentWaterConsumption));
2201 State state = mock(State.class);
2202 when(state.getStatus()).thenReturn(Optional.of(status));
2203 when(state.getEcoFeedback()).thenReturn(Optional.of(ecoFeedback));
2205 Device device = mock(Device.class);
2206 when(device.getState()).thenReturn(Optional.of(state));
2208 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2211 Optional<Quantity> waterConsumption = deviceState.getCurrentWaterConsumption();
2214 assertFalse(waterConsumption.isPresent());
2218 public void testGetCurrentWaterConsumptionWhenUnitIsNotPresent() {
2220 Status status = mock(Status.class);
2221 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
2223 WaterConsumption currentWaterConsumption = mock(WaterConsumption.class);
2224 when(currentWaterConsumption.getUnit()).thenReturn(Optional.empty());
2225 when(currentWaterConsumption.getValue()).thenReturn(Optional.of(0.5));
2227 EcoFeedback ecoFeedback = mock(EcoFeedback.class);
2228 when(ecoFeedback.getCurrentWaterConsumption()).thenReturn(Optional.of(currentWaterConsumption));
2230 State state = mock(State.class);
2231 when(state.getStatus()).thenReturn(Optional.of(status));
2232 when(state.getEcoFeedback()).thenReturn(Optional.of(ecoFeedback));
2234 Device device = mock(Device.class);
2235 when(device.getState()).thenReturn(Optional.of(state));
2237 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2240 Quantity waterConsumption = deviceState.getCurrentWaterConsumption().get();
2243 assertEquals(0.5, waterConsumption.getValue());
2244 assertFalse(waterConsumption.getUnit().isPresent());
2248 public void testGetCurrentWaterConsumption() {
2250 Status status = mock(Status.class);
2251 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
2253 WaterConsumption currentWaterConsumption = mock(WaterConsumption.class);
2254 when(currentWaterConsumption.getUnit()).thenReturn(Optional.of("l"));
2255 when(currentWaterConsumption.getValue()).thenReturn(Optional.of(0.5));
2257 EcoFeedback ecoFeedback = mock(EcoFeedback.class);
2258 when(ecoFeedback.getCurrentWaterConsumption()).thenReturn(Optional.of(currentWaterConsumption));
2260 State state = mock(State.class);
2261 when(state.getStatus()).thenReturn(Optional.of(status));
2262 when(state.getEcoFeedback()).thenReturn(Optional.of(ecoFeedback));
2264 Device device = mock(Device.class);
2265 when(device.getState()).thenReturn(Optional.of(state));
2267 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2270 Quantity waterConsumption = deviceState.getCurrentWaterConsumption().get();
2273 assertEquals(0.5, waterConsumption.getValue());
2274 assertEquals(Optional.of("l"), waterConsumption.getUnit());
2278 public void testGetCurrentEnergyConsumptionWhenEcoFeedbackIsNotPresent() {
2280 Status status = mock(Status.class);
2281 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
2283 State state = mock(State.class);
2284 when(state.getStatus()).thenReturn(Optional.of(status));
2285 when(state.getEcoFeedback()).thenReturn(Optional.empty());
2287 Device device = mock(Device.class);
2288 when(device.getState()).thenReturn(Optional.of(state));
2290 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2293 Optional<Quantity> energyConsumption = deviceState.getCurrentEnergyConsumption();
2296 assertFalse(energyConsumption.isPresent());
2300 public void testGetCurrentEnergyConsumptionWhenCurrentEnergyConsumptionIsNotPresent() {
2302 Status status = mock(Status.class);
2303 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
2305 EcoFeedback ecoFeedback = mock(EcoFeedback.class);
2306 when(ecoFeedback.getCurrentEnergyConsumption()).thenReturn(Optional.empty());
2308 State state = mock(State.class);
2309 when(state.getStatus()).thenReturn(Optional.of(status));
2310 when(state.getEcoFeedback()).thenReturn(Optional.of(ecoFeedback));
2312 Device device = mock(Device.class);
2313 when(device.getState()).thenReturn(Optional.of(state));
2315 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2318 Optional<Quantity> energyConsumption = deviceState.getCurrentEnergyConsumption();
2321 assertFalse(energyConsumption.isPresent());
2325 public void testGetCurrentEnergyConsumptionWhenCurrentEnergyConsumptionIsEmpty() {
2327 Status status = mock(Status.class);
2328 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
2330 EnergyConsumption currentEnergyConsumption = mock(EnergyConsumption.class);
2331 when(currentEnergyConsumption.getUnit()).thenReturn(Optional.empty());
2332 when(currentEnergyConsumption.getValue()).thenReturn(Optional.empty());
2334 EcoFeedback ecoFeedback = mock(EcoFeedback.class);
2335 when(ecoFeedback.getCurrentEnergyConsumption()).thenReturn(Optional.of(currentEnergyConsumption));
2337 State state = mock(State.class);
2338 when(state.getStatus()).thenReturn(Optional.of(status));
2339 when(state.getEcoFeedback()).thenReturn(Optional.of(ecoFeedback));
2341 Device device = mock(Device.class);
2342 when(device.getState()).thenReturn(Optional.of(state));
2344 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2347 Optional<Quantity> energyConsumption = deviceState.getCurrentEnergyConsumption();
2350 assertFalse(energyConsumption.isPresent());
2354 public void testGetCurrentEnergyConsumptionWhenValueIsNotPresent() {
2356 Status status = mock(Status.class);
2357 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
2359 EnergyConsumption currentEnergyConsumption = mock(EnergyConsumption.class);
2360 when(currentEnergyConsumption.getUnit()).thenReturn(Optional.of("kWh"));
2361 when(currentEnergyConsumption.getValue()).thenReturn(Optional.empty());
2363 EcoFeedback ecoFeedback = mock(EcoFeedback.class);
2364 when(ecoFeedback.getCurrentEnergyConsumption()).thenReturn(Optional.of(currentEnergyConsumption));
2366 State state = mock(State.class);
2367 when(state.getStatus()).thenReturn(Optional.of(status));
2368 when(state.getEcoFeedback()).thenReturn(Optional.of(ecoFeedback));
2370 Device device = mock(Device.class);
2371 when(device.getState()).thenReturn(Optional.of(state));
2373 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2376 Optional<Quantity> energyConsumption = deviceState.getCurrentEnergyConsumption();
2379 assertFalse(energyConsumption.isPresent());
2383 public void testGetCurrentEnergyConsumptionWhenUnitIsNotPresent() {
2385 Status status = mock(Status.class);
2386 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
2388 EnergyConsumption currentEnergyConsumption = mock(EnergyConsumption.class);
2389 when(currentEnergyConsumption.getUnit()).thenReturn(Optional.empty());
2390 when(currentEnergyConsumption.getValue()).thenReturn(Optional.of(0.5));
2392 EcoFeedback ecoFeedback = mock(EcoFeedback.class);
2393 when(ecoFeedback.getCurrentEnergyConsumption()).thenReturn(Optional.of(currentEnergyConsumption));
2395 State state = mock(State.class);
2396 when(state.getStatus()).thenReturn(Optional.of(status));
2397 when(state.getEcoFeedback()).thenReturn(Optional.of(ecoFeedback));
2399 Device device = mock(Device.class);
2400 when(device.getState()).thenReturn(Optional.of(state));
2402 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2405 Quantity energyConsumption = deviceState.getCurrentEnergyConsumption().get();
2408 assertEquals(0.5, energyConsumption.getValue());
2409 assertFalse(energyConsumption.getUnit().isPresent());
2413 public void testGetCurrentEnergyConsumption() {
2415 Status status = mock(Status.class);
2416 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
2418 EnergyConsumption currentEnergyConsumption = mock(EnergyConsumption.class);
2419 when(currentEnergyConsumption.getUnit()).thenReturn(Optional.of("kWh"));
2420 when(currentEnergyConsumption.getValue()).thenReturn(Optional.of(0.5));
2422 EcoFeedback ecoFeedback = mock(EcoFeedback.class);
2423 when(ecoFeedback.getCurrentEnergyConsumption()).thenReturn(Optional.of(currentEnergyConsumption));
2425 State state = mock(State.class);
2426 when(state.getStatus()).thenReturn(Optional.of(status));
2427 when(state.getEcoFeedback()).thenReturn(Optional.of(ecoFeedback));
2429 Device device = mock(Device.class);
2430 when(device.getState()).thenReturn(Optional.of(state));
2432 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2435 Quantity energyConsumption = deviceState.getCurrentEnergyConsumption().get();
2438 assertEquals(0.5, energyConsumption.getValue());
2439 assertEquals(Optional.of("kWh"), energyConsumption.getUnit());
2443 public void testGetBatteryLevel() {
2445 Status status = mock(Status.class);
2446 when(status.getValueRaw()).thenReturn(Optional.of(StateType.ON.getCode()));
2448 State state = mock(State.class);
2449 when(state.getStatus()).thenReturn(Optional.of(status));
2450 when(state.getBatteryLevel()).thenReturn(Optional.of(4));
2452 Device device = mock(Device.class);
2453 when(device.getState()).thenReturn(Optional.of(state));
2455 DeviceState deviceState = new DeviceState(DEVICE_IDENTIFIER, device);
2458 Integer batteryLevel = deviceState.getBatteryLevel().get();
2461 assertEquals(Integer.valueOf(4), batteryLevel);