]> git.basschouten.com Git - openhab-addons.git/blob
00a9bc284ff8ce1f416b3c1bfab892b523849e9a
[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.rfxcom.internal.config;
14
15 import static org.junit.jupiter.api.Assertions.*;
16
17 import java.util.stream.Collectors;
18 import java.util.stream.IntStream;
19
20 import org.junit.jupiter.api.BeforeEach;
21 import org.junit.jupiter.api.Test;
22 import org.junit.jupiter.api.extension.ExtendWith;
23 import org.mockito.junit.jupiter.MockitoExtension;
24 import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidParameterException;
25
26 /**
27  * Configuration class for Raw devices.
28  *
29  * @author James Hewitt-Thomas - Initial contribution
30  */
31 @ExtendWith(MockitoExtension.class)
32 public class RFXComRawDeviceConfigurationTest {
33
34     private RFXComRawDeviceConfiguration config;
35
36     @BeforeEach
37     public void before() {
38         config = new RFXComRawDeviceConfiguration();
39         config.deviceId = "RAW";
40         config.subType = "RAW_PACKET1";
41     }
42
43     @Test
44     public void testConfigWithoutPulses() {
45         assertDoesNotThrow(() -> config.parseAndValidate());
46     }
47
48     @Test
49     public void testConfigWithUnevenPulses() {
50         config.onPulses = "100 200 300";
51         assertThrows(RFXComInvalidParameterException.class, () -> config.parseAndValidate());
52     }
53
54     @Test
55     public void testConfigWithTooManyPulses() {
56         String pulses = IntStream.range(1, 126).mapToObj(Integer::toString).collect(Collectors.joining(" "));
57         config.offPulses = pulses;
58         assertThrows(RFXComInvalidParameterException.class, () -> config.parseAndValidate());
59     }
60
61     @Test
62     public void testConfigWithTooLargePulse() {
63         config.openPulses = "100000 200000";
64         assertThrows(RFXComInvalidParameterException.class, () -> config.parseAndValidate());
65     }
66
67     @Test
68     public void testConfigWithNaN() {
69         config.closedPulses = "abc def";
70         assertThrows(RFXComInvalidParameterException.class, () -> config.parseAndValidate());
71     }
72
73     @Test
74     public void testConfigWithValidPulses() {
75         config.onPulses = "100 200 300 400";
76         config.offPulses = "500 600 700 800";
77         assertDoesNotThrow(() -> config.parseAndValidate());
78     }
79 }