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.junit.jupiter.api.Test;
23 * Tests cases for BaseChannel
25 * @author Jan N. Klug - Initial contribution
27 public class BaseChannelTest {
30 public void creatingBaseChannelFromIntegers() {
32 BaseDmxChannel channel = new BaseDmxChannel(0, 600);
33 assertThat(channel.getChannelId(), is(BaseDmxChannel.MAX_CHANNEL_ID));
36 channel = new BaseDmxChannel(0, -1);
37 assertThat(channel.getChannelId(), is(BaseDmxChannel.MIN_CHANNEL_ID));
40 channel = new BaseDmxChannel(5, 100);
41 assertThat(channel.getChannelId(), is(100));
42 assertThat(channel.getUniverseId(), is(5));
45 channel.setUniverseId(1);
46 assertThat(channel.getUniverseId(), is(1));
50 public void creatingBaseChannelfromBaseChannel() {
51 BaseDmxChannel baseChannel = new BaseDmxChannel(5, 100);
52 BaseDmxChannel copyChannel = new BaseDmxChannel(baseChannel);
54 assertThat(copyChannel.getChannelId(), is(100));
55 assertThat(copyChannel.getUniverseId(), is(5));
59 public void comparingChannels() {
60 BaseDmxChannel channel1 = new BaseDmxChannel(5, 100);
61 BaseDmxChannel channel2 = new BaseDmxChannel(7, 140);
63 assertThat(channel1.compareTo(channel2), is(-1));
64 assertThat(channel2.compareTo(channel1), is(1));
65 assertThat(channel1.compareTo(channel1), is(0));
69 public void stringConversion() {
71 BaseDmxChannel baseChannel = new BaseDmxChannel(5, 100);
72 assertThat(baseChannel.toString(), is(equalTo("5:100")));
74 // single channel from string with universe
75 String parseString = new String("2:100");
76 List<BaseDmxChannel> channelList = BaseDmxChannel.fromString(parseString, 0);
77 assertThat(channelList.size(), is(1));
78 assertThat(channelList.get(0).toString(), is(equalTo("2:100")));
80 // single channel from string without universe
81 parseString = new String("100");
82 channelList = BaseDmxChannel.fromString(parseString, 2);
83 assertThat(channelList.size(), is(1));
84 assertThat(channelList.get(0).toString(), is(equalTo("2:100")));
86 // two channels with channel width
87 parseString = new String("100/2");
88 channelList = BaseDmxChannel.fromString(parseString, 2);
89 assertThat(channelList.size(), is(2));
90 assertThat(channelList.get(0).toString(), is(equalTo("2:100")));
91 assertThat(channelList.get(1).toString(), is(equalTo("2:101")));
93 // to channels with comma
94 parseString = new String("100,102");
95 channelList = BaseDmxChannel.fromString(parseString, 2);
96 assertThat(channelList.size(), is(2));
97 assertThat(channelList.get(0).toString(), is(equalTo("2:100")));
98 assertThat(channelList.get(1).toString(), is(equalTo("2:102")));
101 parseString = new String("257,100/3,426");
102 channelList = BaseDmxChannel.fromString(parseString, 2);
103 assertThat(channelList.size(), is(5));
104 assertThat(channelList.get(0).toString(), is(equalTo("2:257")));
105 assertThat(channelList.get(1).toString(), is(equalTo("2:100")));
106 assertThat(channelList.get(2).toString(), is(equalTo("2:101")));
107 assertThat(channelList.get(3).toString(), is(equalTo("2:102")));
108 assertThat(channelList.get(4).toString(), is(equalTo("2:426")));