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.webthing.internal.link;
15 import static org.junit.jupiter.api.Assertions.*;
16 import static org.junit.jupiter.api.Assumptions.*;
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;
26 * @author Gregor Roth - Initial contribution
29 public class TypeConverterTest {
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));
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));
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));
54 state = typeConverter.toStateCommand(45.2);
55 assumeTrue(state instanceof DecimalType);
56 assertEquals(45, typeConverter.toPropertyValue((State) state));