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.WSIntegerValue;
20 import org.openhab.binding.ihc.internal.ws.resourcevalues.WSResourceValue;
21 import org.openhab.core.library.types.PercentType;
22 import org.openhab.core.types.Type;
25 * Test for IHC / ELKO binding
27 * @author Pauli Anttila - Initial contribution
29 public class PercentTypeWSIntegerValueConverterTest {
32 public void test() throws ConversionException {
33 WSIntegerValue val = new WSIntegerValue(12345, 0, -100, 100);
35 val = convertFromOHType(val, new PercentType(2), new ConverterAdditionalInfo(null, false, null));
36 assertEquals(12345, val.resourceID);
37 assertEquals(-100, val.minimumValue);
38 assertEquals(100, val.maximumValue);
39 assertEquals(2, val.value);
41 PercentType type = convertFromResourceValue(val, new ConverterAdditionalInfo(null, false, null));
42 assertEquals(new PercentType(2), type);
45 private WSIntegerValue convertFromOHType(WSIntegerValue IHCvalue, Type OHval,
46 ConverterAdditionalInfo converterAdditionalInfo) throws ConversionException {
47 Converter<WSResourceValue, Type> converter = ConverterFactory.getInstance().getConverter(IHCvalue.getClass(),
49 return (WSIntegerValue) converter.convertFromOHType(OHval, IHCvalue, converterAdditionalInfo);
52 private PercentType convertFromResourceValue(WSIntegerValue IHCvalue,
53 ConverterAdditionalInfo converterAdditionalInfo) throws ConversionException {
54 Converter<WSResourceValue, Type> converter = ConverterFactory.getInstance().getConverter(IHCvalue.getClass(),
56 return (PercentType) converter.convertFromResourceValue(IHCvalue, converterAdditionalInfo);