2 * Copyright (c) 2010-2020 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.junit.Assert.*;
18 import org.junit.Test;
21 * Tests cases for {@see PresenceDetectionValue}
23 * @author David Graeff - Initial contribution
25 public class PresenceDetectionValuesTest {
27 public void updateLatencyTests() {
28 PresenceDetectionValue value = new PresenceDetectionValue("127.0.0.1", 10.0);
29 assertThat(value.getLowestLatency(), is(10.0));
30 value.updateLatency(20.0);
31 assertThat(value.getLowestLatency(), is(10.0));
32 value.updateLatency(0.0);
33 assertThat(value.getLowestLatency(), is(10.0));
34 value.updateLatency(5.0);
35 assertThat(value.getLowestLatency(), is(5.0));
39 public void tcpTests() {
40 PresenceDetectionValue value = new PresenceDetectionValue("127.0.0.1", 10.0);
41 assertFalse(value.isTCPServiceReachable());
42 value.addReachableTcpService(1010);
43 assertThat(value.getReachableTCPports(), hasItem(1010));
44 value.addType(PresenceDetectionType.TCP_CONNECTION);
45 assertTrue(value.isTCPServiceReachable());
46 assertThat(value.getSuccessfulDetectionTypes(), is("TCP_CONNECTION"));
50 public void isFinishedTests() {
51 PresenceDetectionValue value = new PresenceDetectionValue("127.0.0.1", 10.0);
52 assertFalse(value.isFinished());
53 value.setDetectionIsFinished(true);
54 assertTrue(value.isFinished());
58 public void pingTests() {
59 PresenceDetectionValue value = new PresenceDetectionValue("127.0.0.1", 10.0);
60 assertFalse(value.isPingReachable());
61 value.addType(PresenceDetectionType.ICMP_PING);
62 assertTrue(value.isPingReachable());
64 value.addType(PresenceDetectionType.ARP_PING);
65 value.addType(PresenceDetectionType.TCP_CONNECTION);
66 assertThat(value.getSuccessfulDetectionTypes(), is("ARP_PING, ICMP_PING, TCP_CONNECTION"));