]> git.basschouten.com Git - openhab-addons.git/blob
5e5f6e3ecf2c6d3922d5557c7588cb2656079da2
[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.binding.smartmeter;
14
15 import org.junit.Assert;
16 import org.junit.Test;
17 import org.openhab.binding.smartmeter.internal.MeterValue;
18 import org.openhab.binding.smartmeter.internal.conformity.negate.NegateBitModel;
19 import org.openhab.binding.smartmeter.internal.conformity.negate.NegateBitParser;
20 import org.openhab.binding.smartmeter.internal.conformity.negate.NegateHandler;
21
22 /**
23  *
24  * @author Matthias Steigenberger - Initial contribution
25  *
26  */
27 public class TestNegateBit {
28
29     @Test
30     public void testNegateBitParsing() {
31         String negateProperty = "1-0_1-8-0:5:1";
32         NegateBitModel parseNegateProperty = NegateBitParser.parseNegateProperty(negateProperty);
33         Assert.assertEquals("1-0_1-8-0", parseNegateProperty.getNegateChannelId());
34         Assert.assertEquals(5, parseNegateProperty.getNegatePosition());
35         Assert.assertEquals(true, parseNegateProperty.isNegateBit());
36     }
37
38     @Test
39     public void testNegateHandlingTrue() {
40         String negateProperty = "1-0_1-8-0:5:1";
41
42         boolean negateState = NegateHandler.shouldNegateState(negateProperty, obis -> {
43             return new MeterValue<>(obis, "65954", null);
44         });
45
46         Assert.assertTrue(negateState);
47     }
48
49     @Test
50     public void testNegateHandlingFalse() {
51         String negateProperty = "1-0_1-8-0:5:1";
52
53         boolean negateState = NegateHandler.shouldNegateState(negateProperty, obis -> {
54             return new MeterValue<>(obis, "0", null, "65922");
55         });
56
57         Assert.assertFalse(negateState);
58     }
59 }