2 * Copyright (c) 2010-2020 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.smartmeter;
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;
24 * @author Matthias Steigenberger - Initial contribution
27 public class TestNegateBit {
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());
39 public void testNegateHandlingTrue() {
40 String negateProperty = "1-0_1-8-0:5:1";
42 boolean negateState = NegateHandler.shouldNegateState(negateProperty, obis -> {
43 return new MeterValue<>(obis, "65954", null);
46 Assert.assertTrue(negateState);
50 public void testNegateHandlingFalse() {
51 String negateProperty = "1-0_1-8-0:5:1";
53 boolean negateState = NegateHandler.shouldNegateState(negateProperty, obis -> {
54 return new MeterValue<>(obis, "0", null, "65922");
57 Assert.assertFalse(negateState);