2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.rfxcom.internal.config;
15 import static org.junit.jupiter.api.Assertions.*;
17 import java.util.stream.Collectors;
18 import java.util.stream.IntStream;
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;
27 * Configuration class for Raw devices.
29 * @author James Hewitt-Thomas - Initial contribution
31 @ExtendWith(MockitoExtension.class)
32 public class RFXComRawDeviceConfigurationTest {
34 private RFXComRawDeviceConfiguration config;
37 public void before() {
38 config = new RFXComRawDeviceConfiguration();
39 config.deviceId = "RAW";
40 config.subType = "RAW_PACKET1";
44 public void testConfigWithoutPulses() {
45 assertDoesNotThrow(() -> config.parseAndValidate());
49 public void testConfigWithUnevenPulses() {
50 config.onPulses = "100 200 300";
51 assertThrows(RFXComInvalidParameterException.class, () -> config.parseAndValidate());
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());
62 public void testConfigWithTooLargePulse() {
63 config.openPulses = "100000 200000";
64 assertThrows(RFXComInvalidParameterException.class, () -> config.parseAndValidate());
68 public void testConfigWithNaN() {
69 config.closedPulses = "abc def";
70 assertThrows(RFXComInvalidParameterException.class, () -> config.parseAndValidate());
74 public void testConfigWithValidPulses() {
75 config.onPulses = "100 200 300 400";
76 config.offPulses = "500 600 700 800";
77 assertDoesNotThrow(() -> config.parseAndValidate());