]> git.basschouten.com Git - openhab-addons.git/blob
c7637593b02ff5737312e206b3fabe208f555963
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.ihc.internal.converters;
14
15 import static org.junit.jupiter.api.Assertions.*;
16
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.WSWeekdayValue;
21 import org.openhab.core.library.types.DecimalType;
22 import org.openhab.core.types.Type;
23
24 /**
25  * Test for IHC / ELKO binding
26  *
27  * @author Pauli Anttila - Initial contribution
28  */
29 public class DecimalTypeWSWeekdayValueConverterTest {
30
31     @Test
32     public void testConversion() throws ConversionException {
33         WSWeekdayValue val = new WSWeekdayValue(12345, 0);
34
35         val = convertFromOHType(val, new DecimalType(6), new ConverterAdditionalInfo(null, false, null));
36         assertEquals(12345, val.resourceID);
37         assertEquals(6, val.weekdayNumber);
38
39         DecimalType type = convertFromResourceValue(val, new ConverterAdditionalInfo(null, false, null));
40         assertEquals(new DecimalType(6), type);
41     }
42
43     private WSWeekdayValue convertFromOHType(WSWeekdayValue IHCvalue, Type OHval,
44             ConverterAdditionalInfo converterAdditionalInfo) throws ConversionException {
45         Converter<WSResourceValue, Type> converter = ConverterFactory.getInstance().getConverter(IHCvalue.getClass(),
46                 DecimalType.class);
47         return (WSWeekdayValue) converter.convertFromOHType(OHval, IHCvalue, converterAdditionalInfo);
48     }
49
50     private DecimalType convertFromResourceValue(WSWeekdayValue IHCvalue,
51             ConverterAdditionalInfo converterAdditionalInfo) throws ConversionException {
52         Converter<WSResourceValue, Type> converter = ConverterFactory.getInstance().getConverter(IHCvalue.getClass(),
53                 DecimalType.class);
54         return (DecimalType) converter.convertFromResourceValue(IHCvalue, converterAdditionalInfo);
55     }
56 }