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.boschshc.internal.devices;
15 import static org.mockito.ArgumentMatchers.*;
16 import static org.mockito.Mockito.*;
18 import org.junit.jupiter.api.BeforeEach;
19 import org.junit.jupiter.api.Test;
20 import org.junit.jupiter.api.extension.ExtendWith;
21 import org.mockito.Mock;
22 import org.mockito.junit.jupiter.MockitoExtension;
23 import org.openhab.binding.boschshc.internal.devices.bridge.BridgeHandler;
24 import org.openhab.core.config.core.Configuration;
25 import org.openhab.core.thing.Bridge;
26 import org.openhab.core.thing.Thing;
27 import org.openhab.core.thing.ThingStatus;
28 import org.openhab.core.thing.ThingStatusDetail;
29 import org.openhab.core.thing.ThingStatusInfo;
30 import org.openhab.core.thing.ThingTypeUID;
31 import org.openhab.core.thing.ThingUID;
32 import org.openhab.core.thing.binding.ThingHandlerCallback;
35 * Abstract unit test implementation for all types of handlers.
37 * @author David Pace - Initial contribution
39 * @param <T> type of the handler to be tested
41 @ExtendWith(MockitoExtension.class)
42 public abstract class AbstractSHCHandlerTest<T extends BoschSHCHandler> {
50 private Bridge bridge;
53 private BridgeHandler bridgeHandler;
56 private ThingHandlerCallback callback;
59 public void beforeEach() {
60 fixture = createFixture();
61 lenient().when(thing.getUID()).thenReturn(getThingUID());
62 when(thing.getBridgeUID()).thenReturn(new ThingUID("boschshc", "shc", "myBridgeUID"));
63 when(callback.getBridge(any())).thenReturn(bridge);
64 fixture.setCallback(callback);
65 when(bridge.getHandler()).thenReturn(bridgeHandler);
66 when(thing.getConfiguration()).thenReturn(getConfiguration());
71 protected abstract T createFixture();
73 protected T getFixture() {
77 protected ThingUID getThingUID() {
78 return new ThingUID(getThingTypeUID(), "abcdef");
81 protected abstract ThingTypeUID getThingTypeUID();
83 protected Configuration getConfiguration() {
84 return new Configuration();
87 protected Thing getThing() {
91 public BridgeHandler getBridgeHandler() {
95 public ThingHandlerCallback getCallback() {
100 public void testInitialize() {
101 ThingStatusInfo expectedStatusInfo = new ThingStatusInfo(ThingStatus.ONLINE, ThingStatusDetail.NONE, null);
102 verify(callback).statusUpdated(same(thing), eq(expectedStatusInfo));