]> git.basschouten.com Git - openhab-addons.git/blob
815c3b644de39960c432bf31af0a7ea37090c391
[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.avmfritz.internal.actions;
14
15 import static org.junit.jupiter.api.Assertions.assertThrows;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.junit.jupiter.api.BeforeEach;
20 import org.junit.jupiter.api.Test;
21 import org.junit.jupiter.api.extension.ExtendWith;
22 import org.mockito.Mock;
23 import org.mockito.junit.jupiter.MockitoExtension;
24 import org.openhab.binding.avmfritz.internal.handler.AVMFritzHeatingActionsHandler;
25 import org.openhab.core.thing.binding.ThingActions;
26 import org.openhab.core.thing.binding.ThingHandler;
27
28 /**
29  * Unit tests for {@link AVMFritzHeatingActions}.
30  *
31  * @author Christoph Weitkamp - Initial contribution
32  */
33 @ExtendWith(MockitoExtension.class)
34 @NonNullByDefault
35 public class AVMFritzHeatingActionsTest {
36
37     private final ThingActions thingActionsStub = new ThingActions() {
38         @Override
39         public void setThingHandler(ThingHandler handler) {
40         }
41
42         @Override
43         public @Nullable ThingHandler getThingHandler() {
44             return null;
45         }
46     };
47
48     private @Mock @NonNullByDefault({}) AVMFritzHeatingActionsHandler heatingActionsHandlerMock;
49
50     private @NonNullByDefault({}) AVMFritzHeatingActions heatingActions;
51
52     @BeforeEach
53     public void setUp() {
54         heatingActions = new AVMFritzHeatingActions();
55     }
56
57     @Test
58     public void testSetBoostModeThingActionsIsNotAVMFritzHeatingActions() {
59         assertThrows(ClassCastException.class,
60                 () -> AVMFritzHeatingActions.setBoostMode(thingActionsStub, Long.valueOf(5L)));
61     }
62
63     @Test
64     public void testSetBoostModeThingHandlerIsNull() {
65         assertThrows(IllegalArgumentException.class,
66                 () -> AVMFritzHeatingActions.setBoostMode(heatingActions, Long.valueOf(5L)));
67     }
68
69     @Test
70     public void testSetBoostModeDurationNull() {
71         heatingActions.setThingHandler(heatingActionsHandlerMock);
72         assertThrows(IllegalArgumentException.class, () -> AVMFritzHeatingActions.setBoostMode(heatingActions, null));
73     }
74
75     @Test
76     public void testSetBoostMode() {
77         heatingActions.setThingHandler(heatingActionsHandlerMock);
78         AVMFritzHeatingActions.setBoostMode(heatingActions, Long.valueOf(5L));
79     }
80
81     @Test
82     public void testSetWindowOpenModeThingActionsIsNotAVMFritzHeatingActions() {
83         assertThrows(ClassCastException.class,
84                 () -> AVMFritzHeatingActions.setWindowOpenMode(thingActionsStub, Long.valueOf(5L)));
85     }
86
87     @Test
88     public void testSetWindowOpenModeThingHandlerIsNull() {
89         assertThrows(IllegalArgumentException.class,
90                 () -> AVMFritzHeatingActions.setWindowOpenMode(heatingActions, Long.valueOf(5L)));
91     }
92
93     @Test
94     public void testSetWindowOpenModeDurationNull() {
95         heatingActions.setThingHandler(heatingActionsHandlerMock);
96         assertThrows(IllegalArgumentException.class,
97                 () -> AVMFritzHeatingActions.setWindowOpenMode(heatingActions, null));
98     }
99
100     @Test
101     public void testSetWindowOpenMode() {
102         heatingActions.setThingHandler(heatingActionsHandlerMock);
103         AVMFritzHeatingActions.setWindowOpenMode(heatingActions, Long.valueOf(5L));
104     }
105 }