]> git.basschouten.com Git - openhab-addons.git/blob
fb2005580ac226d2020a1abe0c4e8485500a39ec
[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.lcn.internal.subhandler;
14
15 import static org.junit.jupiter.api.Assertions.assertThrows;
16 import static org.mockito.Mockito.verify;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.junit.jupiter.api.BeforeEach;
20 import org.junit.jupiter.api.Test;
21 import org.openhab.binding.lcn.internal.common.LcnChannelGroup;
22 import org.openhab.binding.lcn.internal.common.LcnException;
23 import org.openhab.binding.lcn.internal.common.PckGenerator;
24 import org.openhab.core.library.types.PercentType;
25
26 /**
27  * Test class.
28  *
29  * @author Fabian Wolter - Initial contribution
30  */
31 @NonNullByDefault
32 public class LcnModuleRollershutterRelayPositionSubHandlerTest extends AbstractTestLcnModuleSubHandler {
33     private @NonNullByDefault({}) AbstractLcnModuleRollershutterRelaySubHandler l;
34
35     @Override
36     @BeforeEach
37     public void setUp() {
38         super.setUp();
39
40         l = new LcnModuleRollershutterRelayPositionSubHandler(handler, info);
41     }
42
43     @Test
44     public void testMotor1percent0() throws LcnException {
45         l.handleCommandPercent(PercentType.ZERO, LcnChannelGroup.ROLLERSHUTTERRELAY, 0);
46         verify(handler).sendPck("JH000001");
47     }
48
49     @Test
50     public void testMotor1percent100() throws LcnException {
51         l.handleCommandPercent(PercentType.HUNDRED, LcnChannelGroup.ROLLERSHUTTERRELAY, 0);
52         verify(handler).sendPck("JH100001");
53     }
54
55     @Test
56     public void testMotor1percent50() throws LcnException {
57         l.handleCommandPercent(new PercentType(50), LcnChannelGroup.ROLLERSHUTTERRELAY, 0);
58         verify(handler).sendPck("JH050001");
59     }
60
61     @Test
62     public void testMotor4percent50() throws LcnException {
63         l.handleCommandPercent(new PercentType(50), LcnChannelGroup.ROLLERSHUTTERRELAY, 3);
64         verify(handler).sendPck("JH050008");
65     }
66
67     @Test
68     public void testInvalidMotor() throws LcnException {
69         assertThrows(LcnException.class, () -> {
70             l.handleCommandPercent(new PercentType(50), LcnChannelGroup.ROLLERSHUTTERRELAY, 4);
71         });
72     }
73
74     @Test
75     public void testInvalidPercent() throws LcnException {
76         assertThrows(LcnException.class, () -> {
77             PckGenerator.controlShutterPosition(0, 101);
78         });
79     }
80 }