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.network.internal;
15 import static org.hamcrest.CoreMatchers.*;
16 import static org.hamcrest.MatcherAssert.assertThat;
17 import static org.junit.jupiter.api.Assertions.*;
19 import org.junit.jupiter.api.Test;
22 * Tests cases for {@see PresenceDetectionValue}
24 * @author David Graeff - Initial contribution
26 public class PresenceDetectionValuesTest {
28 public void updateLatencyTests() {
29 PresenceDetectionValue value = new PresenceDetectionValue("127.0.0.1", 10.0);
30 assertThat(value.getLowestLatency(), is(10.0));
31 value.updateLatency(20.0);
32 assertThat(value.getLowestLatency(), is(10.0));
33 value.updateLatency(0.0);
34 assertThat(value.getLowestLatency(), is(10.0));
35 value.updateLatency(5.0);
36 assertThat(value.getLowestLatency(), is(5.0));
40 public void tcpTests() {
41 PresenceDetectionValue value = new PresenceDetectionValue("127.0.0.1", 10.0);
42 assertFalse(value.isTCPServiceReachable());
43 value.addReachableTcpService(1010);
44 assertThat(value.getReachableTCPports(), hasItem(1010));
45 value.addType(PresenceDetectionType.TCP_CONNECTION);
46 assertTrue(value.isTCPServiceReachable());
47 assertThat(value.getSuccessfulDetectionTypes(), is("TCP_CONNECTION"));
51 public void isFinishedTests() {
52 PresenceDetectionValue value = new PresenceDetectionValue("127.0.0.1", 10.0);
53 assertFalse(value.isFinished());
54 value.setDetectionIsFinished(true);
55 assertTrue(value.isFinished());
59 public void pingTests() {
60 PresenceDetectionValue value = new PresenceDetectionValue("127.0.0.1", 10.0);
61 assertFalse(value.isPingReachable());
62 value.addType(PresenceDetectionType.ICMP_PING);
63 assertTrue(value.isPingReachable());
65 value.addType(PresenceDetectionType.ARP_PING);
66 value.addType(PresenceDetectionType.TCP_CONNECTION);
67 assertThat(value.getSuccessfulDetectionTypes(), is("ARP_PING, ICMP_PING, TCP_CONNECTION"));