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.mielecloud.internal.handler.channel;
15 import static org.junit.jupiter.api.Assertions.assertEquals;
17 import java.util.Optional;
18 import java.util.stream.Stream;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.junit.jupiter.params.ParameterizedTest;
22 import org.junit.jupiter.params.provider.Arguments;
23 import org.junit.jupiter.params.provider.MethodSource;
24 import org.openhab.binding.mielecloud.internal.webservice.api.Quantity;
25 import org.openhab.core.library.types.QuantityType;
26 import org.openhab.core.library.unit.Units;
27 import org.openhab.core.types.State;
28 import org.openhab.core.types.UnDefType;
31 * @author Björn Lange - Initial contribution
34 public class ChannelTypeUtilTest {
35 private static Stream<Arguments> quantityToStateConversionArguments() {
36 return Stream.of(Arguments.of(Optional.empty(), UnDefType.UNDEF),
37 Arguments.of(Optional.of(new Quantity(10.0, "Gold")), UnDefType.UNDEF),
38 Arguments.of(Optional.of(new Quantity(3.0, null)), new QuantityType<>(3.0, Units.ONE)),
39 Arguments.of(Optional.of(new Quantity(1.0 / 3.0, "l")), new QuantityType<>(0.333, Units.LITRE)),
40 Arguments.of(Optional.of(new Quantity(20.123, "kWh")), new QuantityType<>(20.123, Units.KILOWATT_HOUR)),
41 Arguments.of(Optional.of(new Quantity(0.5, "l")), new QuantityType<>(0.5, Units.LITRE)));
45 @MethodSource("quantityToStateConversionArguments")
46 void quantityCanBeConvertedToState(Optional<Quantity> input, State expected) {
48 var state = ChannelTypeUtil.quantityToState(input);
51 assertEquals(expected, state);