2 * Copyright (c) 2010-2022 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.ThingUID;
31 import org.openhab.core.thing.binding.ThingHandlerCallback;
34 * Abstract unit test implementation for all types of handlers.
36 * @author David Pace - Initial contribution
38 * @param <T> type of the handler to be tested
40 @ExtendWith(MockitoExtension.class)
41 public abstract class AbstractSHCHandlerTest<T extends BoschSHCHandler> {
49 private Bridge bridge;
52 private BridgeHandler bridgeHandler;
55 private ThingHandlerCallback callback;
58 public void beforeEach() {
59 fixture = createFixture();
60 when(thing.getBridgeUID()).thenReturn(new ThingUID("boschshc", "shc", "myBridgeUID"));
61 when(callback.getBridge(any())).thenReturn(bridge);
62 fixture.setCallback(callback);
63 when(bridge.getHandler()).thenReturn(bridgeHandler);
64 when(thing.getConfiguration()).thenReturn(getConfiguration());
69 protected abstract T createFixture();
71 protected T getFixture() {
75 protected Configuration getConfiguration() {
76 return new Configuration();
79 protected Thing getThing() {
83 public BridgeHandler getBridgeHandler() {
87 public ThingHandlerCallback getCallback() {
92 public void testInitialize() {
93 ThingStatusInfo expectedStatusInfo = new ThingStatusInfo(ThingStatus.ONLINE, ThingStatusDetail.NONE, null);
94 verify(callback).statusUpdated(same(thing), eq(expectedStatusInfo));