]> git.basschouten.com Git - openhab-addons.git/blob
872ca5336b8e45623ac8bdb9aeaae7e26199359b
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.boschshc.internal.devices;
14
15 import static org.mockito.ArgumentMatchers.*;
16 import static org.mockito.Mockito.*;
17
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;
32
33 /**
34  * Abstract unit test implementation for all types of handlers.
35  *
36  * @author David Pace - Initial contribution
37  *
38  * @param <T> type of the handler to be tested
39  */
40 @ExtendWith(MockitoExtension.class)
41 public abstract class AbstractSHCHandlerTest<T extends BoschSHCHandler> {
42
43     private T fixture;
44
45     @Mock
46     private Thing thing;
47
48     @Mock
49     private Bridge bridge;
50
51     @Mock
52     private BridgeHandler bridgeHandler;
53
54     @Mock
55     private ThingHandlerCallback callback;
56
57     @BeforeEach
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());
65
66         fixture.initialize();
67     }
68
69     protected abstract T createFixture();
70
71     protected T getFixture() {
72         return fixture;
73     }
74
75     protected Configuration getConfiguration() {
76         return new Configuration();
77     }
78
79     protected Thing getThing() {
80         return thing;
81     }
82
83     public BridgeHandler getBridgeHandler() {
84         return bridgeHandler;
85     }
86
87     public ThingHandlerCallback getCallback() {
88         return callback;
89     }
90
91     @Test
92     public void testInitialize() {
93         ThingStatusInfo expectedStatusInfo = new ThingStatusInfo(ThingStatus.ONLINE, ThingStatusDetail.NONE, null);
94         verify(callback).statusUpdated(same(thing), eq(expectedStatusInfo));
95     }
96 }