]> git.basschouten.com Git - openhab-addons.git/blob
f85dc7ade604fb3a2f29972bcbbd27b7afa059a7
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.onewire.device;
14
15 import static org.junit.jupiter.api.Assertions.fail;
16 import static org.mockito.ArgumentMatchers.*;
17 import static org.mockito.Mockito.times;
18 import static org.openhab.binding.onewire.internal.OwBindingConstants.*;
19
20 import java.util.ArrayList;
21 import java.util.List;
22
23 import org.eclipse.jdt.annotation.NonNullByDefault;
24 import org.junit.jupiter.api.BeforeEach;
25 import org.junit.jupiter.api.Test;
26 import org.mockito.InOrder;
27 import org.mockito.Mockito;
28 import org.openhab.binding.onewire.internal.OwException;
29 import org.openhab.binding.onewire.internal.device.DS2423;
30 import org.openhab.core.library.types.DecimalType;
31 import org.openhab.core.library.types.OnOffType;
32 import org.openhab.core.types.State;
33
34 /**
35  * Tests cases for {@link DS2423}.
36  *
37  * @author Jan N. Klug - Initial contribution
38  */
39 @NonNullByDefault
40 public class DS2423Test extends DeviceTestParent<DS2423> {
41
42     @BeforeEach
43     public void setupMocks() {
44         setupMocks(THING_TYPE_BASIC, DS2423.class);
45
46         for (int i = 0; i < 2; i++) {
47             addChannel(channelName(i), "Number");
48         }
49     }
50
51     @Test
52     public void counterChannelTest() {
53         List<State> returnValue = new ArrayList<>();
54         returnValue.add(new DecimalType(1408));
55         returnValue.add(new DecimalType(3105));
56
57         final DS2423 testDevice = instantiateDevice();
58         final InOrder inOrder = Mockito.inOrder(mockThingHandler, mockBridgeHandler);
59
60         try {
61             Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
62             Mockito.when(mockBridgeHandler.readDecimalTypeArray(eq(testSensorId), any())).thenReturn(returnValue);
63
64             testDevice.configureChannels();
65             testDevice.refresh(mockBridgeHandler, true);
66
67             inOrder.verify(mockBridgeHandler, times(1)).readDecimalTypeArray(eq(testSensorId), any());
68             inOrder.verify(mockThingHandler).postUpdate(eq(channelName(0)), eq(returnValue.get(0)));
69             inOrder.verify(mockThingHandler).postUpdate(eq(channelName(1)), eq(returnValue.get(1)));
70         } catch (OwException e) {
71             fail("caught unexpected OwException");
72         }
73     }
74
75     private String channelName(int channelNo) {
76         return CHANNEL_COUNTER + channelNo;
77     }
78 }