]> git.basschouten.com Git - openhab-addons.git/blob
71558c76db7e4bfc6d7b29419fcdee40cdb590d5
[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.ThingTypeUID;
31 import org.openhab.core.thing.ThingUID;
32 import org.openhab.core.thing.binding.ThingHandlerCallback;
33
34 /**
35  * Abstract unit test implementation for all types of handlers.
36  *
37  * @author David Pace - Initial contribution
38  *
39  * @param <T> type of the handler to be tested
40  */
41 @ExtendWith(MockitoExtension.class)
42 public abstract class AbstractSHCHandlerTest<T extends BoschSHCHandler> {
43
44     private T fixture;
45
46     @Mock
47     private Thing thing;
48
49     @Mock
50     private Bridge bridge;
51
52     @Mock
53     private BridgeHandler bridgeHandler;
54
55     @Mock
56     private ThingHandlerCallback callback;
57
58     @BeforeEach
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());
67
68         fixture.initialize();
69     }
70
71     protected abstract T createFixture();
72
73     protected T getFixture() {
74         return fixture;
75     }
76
77     protected ThingUID getThingUID() {
78         return new ThingUID(getThingTypeUID(), "abcdef");
79     }
80
81     protected abstract ThingTypeUID getThingTypeUID();
82
83     protected Configuration getConfiguration() {
84         return new Configuration();
85     }
86
87     protected Thing getThing() {
88         return thing;
89     }
90
91     public BridgeHandler getBridgeHandler() {
92         return bridgeHandler;
93     }
94
95     public ThingHandlerCallback getCallback() {
96         return callback;
97     }
98
99     @Test
100     public void testInitialize() {
101         ThingStatusInfo expectedStatusInfo = new ThingStatusInfo(ThingStatus.ONLINE, ThingStatusDetail.NONE, null);
102         verify(callback).statusUpdated(same(thing), eq(expectedStatusInfo));
103     }
104 }