]> git.basschouten.com Git - openhab-addons.git/blob
5ac919c8581dbf5f2849d5f462aa5f5acd77ab05
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.services.intrusion;
14
15 import static org.junit.jupiter.api.Assertions.assertSame;
16 import static org.mockito.ArgumentMatchers.any;
17 import static org.mockito.ArgumentMatchers.anyString;
18 import static org.mockito.Mockito.verify;
19 import static org.mockito.Mockito.when;
20
21 import java.util.concurrent.ExecutionException;
22 import java.util.concurrent.TimeoutException;
23 import java.util.function.Consumer;
24
25 import org.junit.jupiter.api.BeforeEach;
26 import org.junit.jupiter.api.Test;
27 import org.junit.jupiter.api.extension.ExtendWith;
28 import org.mockito.Mock;
29 import org.mockito.junit.jupiter.MockitoExtension;
30 import org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants;
31 import org.openhab.binding.boschshc.internal.devices.bridge.BridgeHandler;
32 import org.openhab.binding.boschshc.internal.exceptions.BoschSHCException;
33 import org.openhab.binding.boschshc.internal.services.intrusion.dto.IntrusionDetectionSystemState;
34
35 /**
36  * Unit tests for {@link IntrusionDetectionSystemStateService}.
37  * 
38  * @author David Pace - Initial contribution
39  *
40  */
41 @ExtendWith(MockitoExtension.class)
42 class IntrusionDetectionSystemStateServiceTest {
43
44     private IntrusionDetectionSystemStateService fixture;
45
46     @Mock
47     private BridgeHandler bridgeHandler;
48
49     @Mock
50     private Consumer<IntrusionDetectionSystemState> consumer;
51
52     @Mock
53     private IntrusionDetectionSystemState testState;
54
55     @BeforeEach
56     void beforeEach() {
57         fixture = new IntrusionDetectionSystemStateService();
58         fixture.initialize(bridgeHandler, BoschSHCBindingConstants.SERVICE_INTRUSION_DETECTION, consumer);
59     }
60
61     @Test
62     void getState() throws InterruptedException, TimeoutException, ExecutionException, BoschSHCException {
63         when(bridgeHandler.getState(anyString(), any())).thenReturn(testState);
64         IntrusionDetectionSystemState state = fixture.getState();
65         verify(bridgeHandler).getState("intrusion/states/system", IntrusionDetectionSystemState.class);
66         assertSame(testState, state);
67     }
68 }