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 java.util.BitSet;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.junit.jupiter.api.BeforeEach;
23 import org.junit.jupiter.api.Test;
24 import org.mockito.InOrder;
25 import org.mockito.Mockito;
26 import org.openhab.binding.onewire.internal.OwException;
27 import org.openhab.binding.onewire.internal.device.DS2405;
28 import org.openhab.core.library.types.OnOffType;
31 * Tests cases for {@link DS2405}.
33 * @author Jan N. Klug - Initial contribution
36 public class DS2405Test extends DeviceTestParent<DS2405> {
39 public void setupMocks() {
40 setupMocks(THING_TYPE_BASIC, DS2405.class);
42 addChannel(channelName(0), "Switch");
46 public void digitalChannel() throws OwException {
47 digitalChannelTest(OnOffType.ON, 0);
48 digitalChannelTest(OnOffType.OFF, 0);
51 private void digitalChannelTest(OnOffType state, int channelNo) throws OwException {
52 final DS2405 testDevice = instantiateDevice();
53 final InOrder inOrder = Mockito.inOrder(mockThingHandler, mockBridgeHandler);
55 BitSet returnValue = new BitSet(8);
56 if (state == OnOffType.ON) {
57 returnValue.flip(0, 7);
60 Mockito.when(mockBridgeHandler.checkPresence(testSensorId)).thenReturn(OnOffType.ON);
61 Mockito.when(mockBridgeHandler.readBitSet(eq(testSensorId), any())).thenReturn(returnValue);
63 testDevice.configureChannels();
64 testDevice.refresh(mockBridgeHandler, true);
66 inOrder.verify(mockBridgeHandler, times(2)).readBitSet(eq(testSensorId), any());
67 inOrder.verify(mockThingHandler).postUpdate(eq(channelName(channelNo)), eq(state));
70 private String channelName(int channelNo) {
71 return CHANNEL_DIGITAL + channelNo;