2 * Copyright (c) 2010-2024 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.boschshc.internal.services.userstate.dto;
15 import static org.junit.jupiter.api.Assertions.assertEquals;
17 import java.util.stream.Stream;
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;
27 * Unit tests for UserStateServiceStateTest
29 * @author Patrick Gell - Initial contribution
31 class UserStateServiceStateTest {
33 UserStateServiceState subject;
37 subject = new UserStateServiceState();
41 @MethodSource("provideStringsForIsBlank")
42 void setStateFromStringUpdatesTheState(String inputState, boolean expectedState) {
43 subject.setStateFromString(inputState);
45 assertEquals(expectedState, subject.isState());
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));
56 void getStateAsStringReturnsState() {
57 subject.setState(false);
59 assertEquals("false", subject.getStateAsString());
61 subject.setState(true);
62 assertEquals("true", subject.getStateAsString());
66 void toOnOffTypeReturnsType() {
67 subject.setState(false);
69 assertEquals(OnOffType.OFF, subject.toOnOffType());
71 subject.setState(true);
72 assertEquals(OnOffType.ON, subject.toOnOffType());