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.dmx.internal.multiverse;
15 import static org.hamcrest.CoreMatchers.*;
16 import static org.hamcrest.MatcherAssert.assertThat;
18 import java.util.List;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.junit.jupiter.api.Test;
24 * Tests cases for BaseChannel
26 * @author Jan N. Klug - Initial contribution
29 public class BaseChannelTest {
32 public void creatingBaseChannelFromIntegers() {
34 BaseDmxChannel channel = new BaseDmxChannel(0, 600);
35 assertThat(channel.getChannelId(), is(BaseDmxChannel.MAX_CHANNEL_ID));
38 channel = new BaseDmxChannel(0, -1);
39 assertThat(channel.getChannelId(), is(BaseDmxChannel.MIN_CHANNEL_ID));
42 channel = new BaseDmxChannel(5, 100);
43 assertThat(channel.getChannelId(), is(100));
44 assertThat(channel.getUniverseId(), is(5));
47 channel.setUniverseId(1);
48 assertThat(channel.getUniverseId(), is(1));
52 public void creatingBaseChannelfromBaseChannel() {
53 BaseDmxChannel baseChannel = new BaseDmxChannel(5, 100);
54 BaseDmxChannel copyChannel = new BaseDmxChannel(baseChannel);
56 assertThat(copyChannel.getChannelId(), is(100));
57 assertThat(copyChannel.getUniverseId(), is(5));
61 public void comparingChannels() {
62 BaseDmxChannel channel1 = new BaseDmxChannel(5, 100);
63 BaseDmxChannel channel2 = new BaseDmxChannel(7, 140);
65 assertThat(channel1.compareTo(channel2), is(-1));
66 assertThat(channel2.compareTo(channel1), is(1));
67 assertThat(channel1.compareTo(channel1), is(0));
71 public void stringConversion() {
73 BaseDmxChannel baseChannel = new BaseDmxChannel(5, 100);
74 assertThat(baseChannel.toString(), is(equalTo("5:100")));
76 // single channel from string with universe
77 String parseString = new String("2:100");
78 List<BaseDmxChannel> channelList = BaseDmxChannel.fromString(parseString, 0);
79 assertThat(channelList.size(), is(1));
80 assertThat(channelList.get(0).toString(), is(equalTo("2:100")));
82 // single channel from string without universe
83 parseString = new String("100");
84 channelList = BaseDmxChannel.fromString(parseString, 2);
85 assertThat(channelList.size(), is(1));
86 assertThat(channelList.get(0).toString(), is(equalTo("2:100")));
88 // two channels with channel width
89 parseString = new String("100/2");
90 channelList = BaseDmxChannel.fromString(parseString, 2);
91 assertThat(channelList.size(), is(2));
92 assertThat(channelList.get(0).toString(), is(equalTo("2:100")));
93 assertThat(channelList.get(1).toString(), is(equalTo("2:101")));
95 // to channels with comma
96 parseString = new String("100,102");
97 channelList = BaseDmxChannel.fromString(parseString, 2);
98 assertThat(channelList.size(), is(2));
99 assertThat(channelList.get(0).toString(), is(equalTo("2:100")));
100 assertThat(channelList.get(1).toString(), is(equalTo("2:102")));
103 parseString = new String("257,100/3,426");
104 channelList = BaseDmxChannel.fromString(parseString, 2);
105 assertThat(channelList.size(), is(5));
106 assertThat(channelList.get(0).toString(), is(equalTo("2:257")));
107 assertThat(channelList.get(1).toString(), is(equalTo("2:100")));
108 assertThat(channelList.get(2).toString(), is(equalTo("2:101")));
109 assertThat(channelList.get(3).toString(), is(equalTo("2:102")));
110 assertThat(channelList.get(4).toString(), is(equalTo("2:426")));