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.dmx.internal.handler;
15 import static org.junit.jupiter.api.Assertions.*;
16 import static org.mockito.ArgumentMatchers.any;
17 import static org.mockito.Mockito.*;
18 import static org.openhab.binding.dmx.internal.DmxBindingConstants.*;
20 import java.util.HashMap;
23 import org.junit.jupiter.api.AfterEach;
24 import org.junit.jupiter.api.BeforeEach;
25 import org.junit.jupiter.api.Test;
26 import org.openhab.core.config.core.Configuration;
27 import org.openhab.core.test.java.JavaTest;
28 import org.openhab.core.thing.Bridge;
29 import org.openhab.core.thing.ChannelUID;
30 import org.openhab.core.thing.Thing;
31 import org.openhab.core.thing.ThingStatus;
32 import org.openhab.core.thing.ThingUID;
33 import org.openhab.core.thing.binding.ThingHandlerCallback;
34 import org.openhab.core.thing.binding.builder.BridgeBuilder;
35 import org.openhab.core.thing.binding.builder.ChannelBuilder;
38 * Tests cases for {@link org.openhab.binding.dmx.internal.handler.Lib485BridgeHandler}.
40 * @author Jan N. Klug - Initial contribution
42 public class Lib485BridgeHandlerTest extends JavaTest {
44 private static final String TEST_ADDRESS = "localhost";
46 private final ThingUID BRIDGE_UID_LIB485 = new ThingUID(THING_TYPE_LIB485_BRIDGE, "lib485bridge");
47 private final ChannelUID CHANNEL_UID_MUTE = new ChannelUID(BRIDGE_UID_LIB485, CHANNEL_MUTE);
49 Map<String, Object> bridgeProperties;
51 private Bridge bridge;
52 private Lib485BridgeHandler bridgeHandler;
56 bridgeProperties = new HashMap<>();
57 bridgeProperties.put(CONFIG_ADDRESS, TEST_ADDRESS);
58 bridge = BridgeBuilder.create(THING_TYPE_LIB485_BRIDGE, "lib485bridge").withLabel("Lib485 Bridge")
59 .withChannel(ChannelBuilder.create(CHANNEL_UID_MUTE, "Switch").withType(MUTE_CHANNEL_TYPEUID).build())
60 .withConfiguration(new Configuration(bridgeProperties)).build();
62 ThingHandlerCallback mockCallback = mock(ThingHandlerCallback.class);
64 ((Thing) answer.getArgument(0)).setStatusInfo(answer.getArgument(1));
66 }).when(mockCallback).statusUpdated(any(), any());
68 bridgeHandler = new Lib485BridgeHandler(bridge) {
70 protected void validateConfigurationParameters(Map<String, Object> configurationParameters) {
74 bridgeHandler.getThing().setHandler(bridgeHandler);
75 bridgeHandler.setCallback(mockCallback);
76 bridgeHandler.initialize();
80 public void tearDown() {
81 bridgeHandler.dispose();
85 public void assertBridgeStatus() {
86 waitForAssert(() -> assertEquals(ThingStatus.OFFLINE, bridge.getStatusInfo().getStatus()));