]> git.basschouten.com Git - openhab-addons.git/blob
7d21e34eafe39254497576e196e1bdce94726a60
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.boschshc.internal.services.userstate.dto;
14
15 import static org.junit.jupiter.api.Assertions.assertEquals;
16
17 import java.util.stream.Stream;
18
19 import org.junit.jupiter.api.BeforeEach;
20 import org.junit.jupiter.api.Test;
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.core.library.types.OnOffType;
25
26 /**
27  * Unit tests for UserStateServiceStateTest
28  *
29  * @author Patrick Gell - Initial contribution
30  */
31 class UserStateServiceStateTest {
32
33     UserStateServiceState subject;
34
35     @BeforeEach
36     void setUp() {
37         subject = new UserStateServiceState();
38     }
39
40     @ParameterizedTest
41     @MethodSource("provideStringsForIsBlank")
42     void setStateFromStringUpdatesTheState(String inputState, boolean expectedState) {
43         subject.setStateFromString(inputState);
44
45         assertEquals(expectedState, subject.isState());
46     }
47
48     private static Stream<Arguments> provideStringsForIsBlank() {
49         return Stream.of(Arguments.of("true", true), Arguments.of("false", false), Arguments.of("True", true),
50                 Arguments.of("False", false), Arguments.of("TRUE", true), Arguments.of("FALSE", false),
51                 Arguments.of(null, false), Arguments.of("", false), Arguments.of("  ", false),
52                 Arguments.of("not blank", false));
53     }
54
55     @Test
56     void getStateAsStringReturnsState() {
57         subject.setState(false);
58
59         assertEquals("false", subject.getStateAsString());
60
61         subject.setState(true);
62         assertEquals("true", subject.getStateAsString());
63     }
64
65     @Test
66     void toOnOffTypeReturnsType() {
67         subject.setState(false);
68
69         assertEquals(OnOffType.OFF, subject.toOnOffType());
70
71         subject.setState(true);
72         assertEquals(OnOffType.ON, subject.toOnOffType());
73     }
74 }