]> git.basschouten.com Git - openhab-addons.git/blob
70f5a28b7b8ceda4c85e69b8800acf4cd24ceacd
[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.mielecloud.internal.handler.channel;
14
15 import static org.junit.jupiter.api.Assertions.assertEquals;
16
17 import java.util.Optional;
18 import java.util.stream.Stream;
19
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;
29
30 /**
31  * @author Björn Lange - Initial contribution
32  */
33 @NonNullByDefault
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)));
42     }
43
44     @ParameterizedTest
45     @MethodSource("quantityToStateConversionArguments")
46     void quantityCanBeConvertedToState(Optional<Quantity> input, State expected) {
47         // when:
48         var state = ChannelTypeUtil.quantityToState(input);
49
50         // then:
51         assertEquals(expected, state);
52     }
53 }