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.miio.internal;
15 import static org.junit.jupiter.api.Assertions.*;
17 import java.util.Collections;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.junit.jupiter.api.Test;
22 import org.openhab.binding.miio.internal.basic.ActionConditions;
23 import org.openhab.binding.miio.internal.basic.MiIoDeviceActionCondition;
25 import com.google.gson.JsonElement;
26 import com.google.gson.JsonPrimitive;
29 * Test case for {@link ActionConditions}
31 * @author Marcel Verpaalen - Initial contribution
35 public class ActionConditionTest {
38 public void assertBrightnessExisting() {
39 MiIoDeviceActionCondition condition = new MiIoDeviceActionCondition();
40 condition.setName("BrightnessExisting");
41 Map<String, Object> deviceVariables = Collections.emptyMap();
42 JsonElement value = new JsonPrimitive(1);
43 JsonElement resp = ActionConditions.executeAction(condition, deviceVariables, value, null);
46 assertEquals(new JsonPrimitive(1), resp);
49 value = new JsonPrimitive(100);
50 resp = ActionConditions.executeAction(condition, deviceVariables, value, null);
52 assertEquals(new JsonPrimitive(100), resp);
55 value = new JsonPrimitive(200);
56 resp = ActionConditions.executeAction(condition, deviceVariables, value, null);
58 assertEquals(new JsonPrimitive(100), resp);
60 // switched off = invalid brightness
61 value = new JsonPrimitive(0);
62 resp = ActionConditions.executeAction(condition, deviceVariables, value, null);
64 assertNotEquals(new JsonPrimitive(0), resp);
66 value = new JsonPrimitive(-1);
67 resp = ActionConditions.executeAction(condition, deviceVariables, value, null);
69 assertNotEquals(new JsonPrimitive(-1), resp);