]> git.basschouten.com Git - openhab-addons.git/blob
9ab5748e664d4f1c1cd55e90fce253789f932c7a
[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.ihc.internal;
14
15 import static org.junit.jupiter.api.Assertions.*;
16
17 import java.time.Duration;
18
19 import org.junit.jupiter.api.Test;
20
21 /**
22  * Test for IHC / ELKO binding
23  *
24  * @author Pauli Anttila - Initial contribution
25  */
26 public class ButtonPressDurationDetectorTest {
27
28     @Test
29     public void testShortPress() {
30         Duration duration = Duration.ofMillis(450);
31         long longPressTime = 1000;
32         long longPressMaxTime = 2000;
33
34         ButtonPressDurationDetector button = new ButtonPressDurationDetector(duration, longPressTime, longPressMaxTime);
35
36         assertTrue(button.isShortPress());
37         assertFalse(button.isLongPress());
38     }
39
40     @Test
41     public void testLongPress() {
42         Duration duration = Duration.ofMillis(1003);
43         long longPressTime = 1000;
44         long longPressMaxTime = 2000;
45
46         ButtonPressDurationDetector button = new ButtonPressDurationDetector(duration, longPressTime, longPressMaxTime);
47
48         assertFalse(button.isShortPress());
49         assertTrue(button.isLongPress());
50     }
51
52     @Test
53     public void testExtraLongPress() {
54         Duration duration = Duration.ofMillis(2423);
55         long longPressTime = 1000;
56         long longPressMaxTime = 2000;
57
58         ButtonPressDurationDetector button = new ButtonPressDurationDetector(duration, longPressTime, longPressMaxTime);
59
60         assertFalse(button.isShortPress());
61         assertFalse(button.isLongPress());
62     }
63
64     @Test
65     public void testTooLongPress() {
66         Duration duration = Duration.ofMillis(5001);
67         long longPressTime = 1000;
68         long longPressMaxTime = 2000;
69
70         ButtonPressDurationDetector button = new ButtonPressDurationDetector(duration, longPressTime, longPressMaxTime);
71
72         assertFalse(button.isShortPress());
73         assertFalse(button.isLongPress());
74     }
75 }