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.onewire.device;
15 import static org.mockito.ArgumentMatchers.*;
16 import static org.mockito.Mockito.times;
17 import static org.openhab.binding.onewire.internal.OwBindingConstants.*;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.junit.jupiter.api.BeforeEach;
21 import org.junit.jupiter.api.Test;
22 import org.mockito.InOrder;
23 import org.mockito.Mockito;
24 import org.openhab.binding.onewire.internal.OwException;
25 import org.openhab.binding.onewire.internal.device.DS1923;
26 import org.openhab.core.library.types.DecimalType;
27 import org.openhab.core.library.types.OnOffType;
28 import org.openhab.core.library.types.QuantityType;
31 * Tests cases for {@link DS1923}.
33 * @author Jan N. Klug - Initial contribution
34 * @author Michał Wójcik - Adapted to DS1923
37 public class DS1923Test extends DeviceTestParent<DS1923> {
39 public void setupMocks() {
40 setupMocks(THING_TYPE_MS_TX, DS1923.class);
42 addChannel(CHANNEL_TEMPERATURE, "Number:Temperature");
43 addChannel(CHANNEL_HUMIDITY, "Number:Dimensionless");
44 addChannel(CHANNEL_ABSOLUTE_HUMIDITY, "Number:Density");
45 addChannel(CHANNEL_DEWPOINT, "Number:Temperature");
49 public void temperatureChannel() throws OwException {
50 final DS1923 testDevice = instantiateDevice();
51 final InOrder inOrder = Mockito.inOrder(mockThingHandler, mockBridgeHandler);
53 Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
54 Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), any())).thenReturn(new DecimalType(10.0));
56 testDevice.enableChannel(CHANNEL_TEMPERATURE);
57 testDevice.configureChannels();
58 testDevice.refresh(mockBridgeHandler, true);
60 inOrder.verify(mockBridgeHandler).readDecimalType(eq(testSensorId), any());
61 inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_TEMPERATURE), eq(new QuantityType<>("10.0 °C")));
63 inOrder.verifyNoMoreInteractions();
67 public void humidityChannel() throws OwException {
68 final DS1923 testDevice = instantiateDevice();
69 final InOrder inOrder = Mockito.inOrder(mockThingHandler, mockBridgeHandler);
71 Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
72 Mockito.when(mockBridgeHandler.readDecimalType(eq(testSensorId), any())).thenReturn(new DecimalType(10.0));
74 testDevice.enableChannel(CHANNEL_HUMIDITY);
75 testDevice.enableChannel(CHANNEL_ABSOLUTE_HUMIDITY);
76 testDevice.enableChannel(CHANNEL_DEWPOINT);
77 testDevice.configureChannels();
78 testDevice.refresh(mockBridgeHandler, true);
80 inOrder.verify(mockBridgeHandler, times(2)).readDecimalType(eq(testSensorId), any());
81 inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_HUMIDITY), eq(new QuantityType<>("10.0 %")));
82 inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_ABSOLUTE_HUMIDITY),
83 eq(new QuantityType<>("0.9381970824113001000 g/m³")));
84 inOrder.verify(mockThingHandler).postUpdate(eq(CHANNEL_DEWPOINT),
85 eq(new QuantityType<>("-20.31395053870025 °C")));
87 inOrder.verifyNoMoreInteractions();