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