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.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.*;
20 import java.util.ArrayList;
21 import java.util.List;
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;
35 * Tests cases for {@link DS2423}.
37 * @author Jan N. Klug - Initial contribution
40 public class DS2423Test extends DeviceTestParent<DS2423> {
43 public void setupMocks() {
44 setupMocks(THING_TYPE_BASIC, DS2423.class);
46 for (int i = 0; i < 2; i++) {
47 addChannel(channelName(i), "Number");
52 public void counterChannelTest() {
53 List<State> returnValue = new ArrayList<>();
54 returnValue.add(new DecimalType(1408));
55 returnValue.add(new DecimalType(3105));
57 final DS2423 testDevice = instantiateDevice();
58 final InOrder inOrder = Mockito.inOrder(mockThingHandler, mockBridgeHandler);
61 Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
62 Mockito.when(mockBridgeHandler.readDecimalTypeArray(eq(testSensorId), any())).thenReturn(returnValue);
64 testDevice.configureChannels();
65 testDevice.refresh(mockBridgeHandler, true);
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");
75 private String channelName(int channelNo) {
76 return CHANNEL_COUNTER + channelNo;