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.WSResourceValue;
20 import org.openhab.binding.ihc.internal.ws.resourcevalues.WSTimerValue;
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 DecimalTypeWSTimerValueConverterTest {
32 public void testConversion() throws ConversionException {
33 WSTimerValue val = new WSTimerValue(12345, 0);
35 val = convertFromOHType(val, new DecimalType(123456), new ConverterAdditionalInfo(null, false, null));
36 assertEquals(12345, val.resourceID);
37 assertEquals(123456, val.milliseconds);
39 DecimalType type = convertFromResourceValue(val, new ConverterAdditionalInfo(null, false, null));
40 assertEquals(new DecimalType(123456), type);
43 private WSTimerValue convertFromOHType(WSTimerValue IHCvalue, Type OHval,
44 ConverterAdditionalInfo converterAdditionalInfo) throws ConversionException {
45 Converter<WSResourceValue, Type> converter = ConverterFactory.getInstance().getConverter(IHCvalue.getClass(),
47 return (WSTimerValue) converter.convertFromOHType(OHval, IHCvalue, converterAdditionalInfo);
50 private DecimalType convertFromResourceValue(WSTimerValue IHCvalue, ConverterAdditionalInfo converterAdditionalInfo)
51 throws ConversionException {
52 Converter<WSResourceValue, Type> converter = ConverterFactory.getInstance().getConverter(IHCvalue.getClass(),
54 return (DecimalType) converter.convertFromResourceValue(IHCvalue, converterAdditionalInfo);