]> git.basschouten.com Git - openhab-addons.git/blob
7e4f14819dce1c861ee82bc79126fe446ab4b8cb
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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.io.transport.modbus.test;
14
15 import static org.hamcrest.CoreMatchers.*;
16 import static org.junit.Assert.assertThat;
17
18 import java.util.Optional;
19
20 import org.junit.Test;
21 import org.openhab.core.library.types.DecimalType;
22 import org.openhab.core.library.types.IncreaseDecreaseType;
23 import org.openhab.core.library.types.OnOffType;
24 import org.openhab.core.library.types.OpenClosedType;
25 import org.openhab.io.transport.modbus.ModbusBitUtilities;
26
27 /**
28  * @author Sami Salonen - Initial contribution
29  */
30 public class BitUtilitiesTranslateCommand2BooleanTest {
31
32     @Test
33     public void testZero() {
34         Optional<Boolean> actual = ModbusBitUtilities.translateCommand2Boolean(DecimalType.ZERO);
35         assertThat(actual, is(equalTo(Optional.of(false))));
36     }
37
38     @Test
39     public void testNegative() {
40         Optional<Boolean> actual = ModbusBitUtilities.translateCommand2Boolean(new DecimalType(-3.4));
41         assertThat(actual, is(equalTo(Optional.of(true))));
42     }
43
44     @Test
45     public void testPositive() {
46         Optional<Boolean> actual = ModbusBitUtilities.translateCommand2Boolean(new DecimalType(3.4));
47         assertThat(actual, is(equalTo(Optional.of(true))));
48     }
49
50     @Test
51     public void testOn() {
52         Optional<Boolean> actual = ModbusBitUtilities.translateCommand2Boolean(OnOffType.ON);
53         assertThat(actual, is(equalTo(Optional.of(true))));
54     }
55
56     @Test
57     public void testOpen() {
58         Optional<Boolean> actual = ModbusBitUtilities.translateCommand2Boolean(OpenClosedType.OPEN);
59         assertThat(actual, is(equalTo(Optional.of(true))));
60     }
61
62     @Test
63     public void testOff() {
64         Optional<Boolean> actual = ModbusBitUtilities.translateCommand2Boolean(OnOffType.OFF);
65         assertThat(actual, is(equalTo(Optional.of(false))));
66     }
67
68     @Test
69     public void testClosed() {
70         Optional<Boolean> actual = ModbusBitUtilities.translateCommand2Boolean(OpenClosedType.CLOSED);
71         assertThat(actual, is(equalTo(Optional.of(false))));
72     }
73
74     @Test
75     public void testUnknown() {
76         Optional<Boolean> actual = ModbusBitUtilities.translateCommand2Boolean(IncreaseDecreaseType.INCREASE);
77         assertThat(actual, is(equalTo(Optional.empty())));
78     }
79 }