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.ihc.internal;
15 import static org.junit.jupiter.api.Assertions.*;
17 import java.time.Duration;
19 import org.junit.jupiter.api.Test;
22 * Test for IHC / ELKO binding
24 * @author Pauli Anttila - Initial contribution
26 public class ButtonPressDurationDetectorTest {
29 public void testShortPress() {
30 Duration duration = Duration.ofMillis(450);
31 long longPressTime = 1000;
32 long longPressMaxTime = 2000;
34 ButtonPressDurationDetector button = new ButtonPressDurationDetector(duration, longPressTime, longPressMaxTime);
36 assertTrue(button.isShortPress());
37 assertFalse(button.isLongPress());
41 public void testLongPress() {
42 Duration duration = Duration.ofMillis(1003);
43 long longPressTime = 1000;
44 long longPressMaxTime = 2000;
46 ButtonPressDurationDetector button = new ButtonPressDurationDetector(duration, longPressTime, longPressMaxTime);
48 assertFalse(button.isShortPress());
49 assertTrue(button.isLongPress());
53 public void testExtraLongPress() {
54 Duration duration = Duration.ofMillis(2423);
55 long longPressTime = 1000;
56 long longPressMaxTime = 2000;
58 ButtonPressDurationDetector button = new ButtonPressDurationDetector(duration, longPressTime, longPressMaxTime);
60 assertFalse(button.isShortPress());
61 assertFalse(button.isLongPress());
65 public void testTooLongPress() {
66 Duration duration = Duration.ofMillis(5001);
67 long longPressTime = 1000;
68 long longPressMaxTime = 2000;
70 ButtonPressDurationDetector button = new ButtonPressDurationDetector(duration, longPressTime, longPressMaxTime);
72 assertFalse(button.isShortPress());
73 assertFalse(button.isLongPress());