2 * Copyright (c) 2010-2024 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.boschshc.internal.devices;
15 import static org.mockito.ArgumentMatchers.*;
16 import static org.mockito.Mockito.*;
18 import java.util.concurrent.ExecutionException;
19 import java.util.concurrent.TimeoutException;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.junit.jupiter.api.BeforeEach;
23 import org.junit.jupiter.api.Test;
24 import org.junit.jupiter.api.extension.ExtendWith;
25 import org.mockito.Mock;
26 import org.mockito.junit.jupiter.MockitoExtension;
27 import org.openhab.binding.boschshc.internal.devices.bridge.BridgeHandler;
28 import org.openhab.binding.boschshc.internal.exceptions.BoschSHCException;
29 import org.openhab.core.config.core.Configuration;
30 import org.openhab.core.thing.Bridge;
31 import org.openhab.core.thing.ChannelUID;
32 import org.openhab.core.thing.Thing;
33 import org.openhab.core.thing.ThingStatus;
34 import org.openhab.core.thing.ThingStatusDetail;
35 import org.openhab.core.thing.ThingStatusInfo;
36 import org.openhab.core.thing.ThingTypeUID;
37 import org.openhab.core.thing.ThingUID;
38 import org.openhab.core.thing.binding.ThingHandlerCallback;
41 * Abstract unit test implementation for all types of handlers.
43 * @author David Pace - Initial contribution
45 * @param <T> type of the handler to be tested
48 @ExtendWith(MockitoExtension.class)
49 public abstract class AbstractBoschSHCHandlerTest<T extends BoschSHCHandler> {
53 private @Mock @NonNullByDefault({}) Thing thing;
55 private @Mock @NonNullByDefault({}) Bridge bridge;
57 protected @Mock @NonNullByDefault({}) BridgeHandler bridgeHandler;
59 private @Mock @NonNullByDefault({}) ThingHandlerCallback callback;
61 protected AbstractBoschSHCHandlerTest() {
62 this.fixture = createFixture();
66 void beforeEach() throws InterruptedException, TimeoutException, ExecutionException, BoschSHCException {
67 fixture = createFixture();
68 lenient().when(thing.getUID()).thenReturn(getThingUID());
69 when(thing.getBridgeUID()).thenReturn(new ThingUID("boschshc", "shc", "myBridgeUID"));
70 when(callback.getBridge(any())).thenReturn(bridge);
71 fixture.setCallback(callback);
72 when(bridge.getHandler()).thenReturn(bridgeHandler);
73 lenient().when(thing.getConfiguration()).thenReturn(getConfiguration());
78 protected abstract T createFixture();
80 protected T getFixture() {
84 protected ThingUID getThingUID() {
85 return new ThingUID(getThingTypeUID(), "abcdef");
88 protected abstract ThingTypeUID getThingTypeUID();
90 protected ChannelUID getChannelUID(String channelID) {
91 return new ChannelUID(getThingUID(), channelID);
94 protected Configuration getConfiguration() {
95 return new Configuration();
98 protected Thing getThing() {
102 protected BridgeHandler getBridgeHandler() {
103 return bridgeHandler;
106 protected ThingHandlerCallback getCallback() {
111 public void testInitialize() {
112 ThingStatusInfo expectedStatusInfo = new ThingStatusInfo(ThingStatus.ONLINE, ThingStatusDetail.NONE, null);
113 verify(callback).statusUpdated(same(thing), eq(expectedStatusInfo));