This repository has been archived by the owner on May 7, 2020. It is now read-only.
/
ChannelTest.java
89 lines (71 loc) · 2.62 KB
/
ChannelTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**
* Copyright (c) 2014-2017 by the respective copyright holders.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.smarthome.binding.dmx.multiverse;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import org.eclipse.smarthome.binding.dmx.internal.action.BaseAction;
import org.eclipse.smarthome.binding.dmx.internal.action.FadeAction;
import org.eclipse.smarthome.binding.dmx.internal.multiverse.DmxChannel;
import org.junit.Test;
/**
* Tests cases for Channel
*
* @author Jan N. Klug - Initial contribution
*/
public class ChannelTest {
@Test
public void setAndGetValues() {
DmxChannel channel = new DmxChannel(0, 1);
// value is set
channel.setValue(100);
assertThat(channel.getValue(), is(100));
// limits are observed
channel.setValue(300);
assertThat(channel.getValue(), is(DmxChannel.MAX_VALUE));
channel.setValue(-1);
assertThat(channel.getValue(), is(DmxChannel.MIN_VALUE));
}
@Test
public void setAndClearAction() {
DmxChannel channel = new DmxChannel(0, 1);
BaseAction action = new FadeAction(0, 100, -1);
// has action
channel.setChannelAction(action);
assertThat(channel.hasRunningActions(), is(true));
// clear action
channel.clearAction();
assertThat(channel.hasRunningActions(), is(false));
}
@Test
public void suspendAndResumeAction() {
DmxChannel channel = new DmxChannel(0, 1);
BaseAction action = new FadeAction(0, 100, -1);
// has action
channel.setChannelAction(action);
channel.setValue(100);
assertThat(channel.getValue(), is(100));
assertThat(channel.hasRunningActions(), is(true));
// suspend with action
channel.suspendAction();
channel.clearAction();
assertThat(channel.isSuspended(), is(true));
assertThat(channel.hasRunningActions(), is(false));
// resume
channel.resumeAction();
assertThat(channel.isSuspended(), is(false));
assertThat(channel.hasRunningActions(), is(true));
// suspend without action
channel.clearAction();
channel.suspendAction();
channel.setValue(200);
assertThat(channel.getValue(), is(200));
// resume without action
channel.resumeAction();
assertThat(channel.getValue(), is(100));
}
}