2 * Copyright (c) 2010-2020 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.http.internal.converter;
15 import java.util.function.Function;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.junit.jupiter.api.Assertions;
19 import org.junit.jupiter.api.Test;
20 import org.openhab.binding.http.internal.config.HttpChannelConfig;
21 import org.openhab.binding.http.internal.transform.NoOpValueTransformation;
22 import org.openhab.core.library.types.DecimalType;
23 import org.openhab.core.library.types.PointType;
24 import org.openhab.core.library.types.StringType;
25 import org.openhab.core.types.Command;
26 import org.openhab.core.types.State;
29 * The {@link ConverterTest} is a test class for state converters
31 * @author Jan N. Klug - Initial contribution
34 public class ConverterTest {
37 public void stringTypeConverter() {
38 GenericItemConverter converter = createConverter(StringType::new);
39 Assertions.assertEquals(new StringType("Test"), converter.toState("Test"));
43 public void decimalTypeConverter() {
44 GenericItemConverter converter = createConverter(DecimalType::new);
45 Assertions.assertEquals(new DecimalType(15.6), converter.toState("15.6"));
49 public void pointTypeConverter() {
50 GenericItemConverter converter = createConverter(PointType::new);
51 Assertions.assertEquals(new PointType(new DecimalType(51.1), new DecimalType(7.2), new DecimalType(100)),
52 converter.toState("51.1, 7.2, 100"));
55 private void sendHttpValue(String value) {
58 private void updateState(State state) {
61 public void postCommand(Command command) {
64 public GenericItemConverter createConverter(Function<String, State> fcn) {
65 return new GenericItemConverter(fcn, this::updateState, this::postCommand, this::sendHttpValue,
66 NoOpValueTransformation.getInstance(), NoOpValueTransformation.getInstance(), new HttpChannelConfig());