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.ihc.internal.converters;
15 import static org.junit.jupiter.api.Assertions.*;
17 import org.junit.jupiter.api.Test;
18 import org.openhab.binding.ihc.internal.ws.exeptions.ConversionException;
19 import org.openhab.binding.ihc.internal.ws.resourcevalues.WSBooleanValue;
20 import org.openhab.binding.ihc.internal.ws.resourcevalues.WSResourceValue;
21 import org.openhab.core.library.types.DecimalType;
22 import org.openhab.core.types.Type;
25 * Test for IHC / ELKO binding
27 * @author Pauli Anttila - Initial contribution
29 public class DecimalTypeWSBooleanValueConverterTest {
32 public void testOn() throws ConversionException {
33 final boolean inverted = false;
34 WSBooleanValue val = new WSBooleanValue(12345, false);
36 val = convertFromOHType(val, new DecimalType(1), new ConverterAdditionalInfo(null, inverted, null));
37 assertEquals(12345, val.resourceID);
38 assertEquals(true, val.value);
40 DecimalType type = convertFromResourceValue(val, new ConverterAdditionalInfo(null, inverted, null));
41 assertEquals(new DecimalType(1), type);
45 public void testOff() throws ConversionException {
46 final boolean inverted = false;
48 WSBooleanValue val = new WSBooleanValue(12345, true);
49 val = convertFromOHType(val, new DecimalType(0), new ConverterAdditionalInfo(null, inverted, null));
50 assertEquals(12345, val.resourceID);
51 assertEquals(false, val.value);
53 DecimalType type = convertFromResourceValue(val, new ConverterAdditionalInfo(null, inverted, null));
54 assertEquals(new DecimalType(0), type);
57 private WSBooleanValue convertFromOHType(WSBooleanValue IHCvalue, Type OHval,
58 ConverterAdditionalInfo converterAdditionalInfo) throws ConversionException {
59 Converter<WSResourceValue, Type> converter = ConverterFactory.getInstance().getConverter(IHCvalue.getClass(),
61 return (WSBooleanValue) converter.convertFromOHType(OHval, IHCvalue, converterAdditionalInfo);
64 private DecimalType convertFromResourceValue(WSBooleanValue IHCvalue,
65 ConverterAdditionalInfo converterAdditionalInfo) throws ConversionException {
66 Converter<WSResourceValue, Type> converter = ConverterFactory.getInstance().getConverter(IHCvalue.getClass(),
68 return (DecimalType) converter.convertFromResourceValue(IHCvalue, converterAdditionalInfo);