]> git.basschouten.com Git - openhab-addons.git/blob
b265fbc3cd5371a1d5c00a7d0f285b72f10ba1b9
[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.webthing.internal.link;
14
15 import static org.junit.jupiter.api.Assertions.*;
16 import static org.junit.jupiter.api.Assumptions.*;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.junit.jupiter.api.Test;
20 import org.openhab.core.library.types.DecimalType;
21 import org.openhab.core.library.types.StringType;
22 import org.openhab.core.types.State;
23
24 /**
25  *
26  * @author Gregor Roth - Initial contribution
27  */
28 @NonNullByDefault
29 public class TypeConverterTest {
30
31     @Test
32     public void testStringType() throws Exception {
33         var typeConverter = TypeConverters.create("String", "String");
34         var state = typeConverter.toStateCommand("motion");
35         assumeTrue(state instanceof StringType);
36         assertEquals("motion", typeConverter.toPropertyValue((State) state));
37     }
38
39     @Test
40     public void testNumberType() throws Exception {
41         var typeConverter = TypeConverters.create("Number", "Number");
42         var state = typeConverter.toStateCommand(45.6);
43         assumeTrue(state instanceof DecimalType);
44         assertEquals(45.6, typeConverter.toPropertyValue((State) state));
45     }
46
47     @Test
48     public void testNumberIntegerType() throws Exception {
49         var typeConverter = TypeConverters.create("Number", "Integer");
50         var state = typeConverter.toStateCommand(45);
51         assumeTrue(state instanceof DecimalType);
52         assertEquals(45, typeConverter.toPropertyValue((State) state));
53
54         state = typeConverter.toStateCommand(45.2);
55         assumeTrue(state instanceof DecimalType);
56         assertEquals(45, typeConverter.toPropertyValue((State) state));
57     }
58 }