From 2430a28a1cf2e5b1fd3765c2db4818d2fbcae0d9 Mon Sep 17 00:00:00 2001 From: Anton Keks Date: Tue, 19 Jan 2021 23:02:22 +0200 Subject: [PATCH] add TCPPingerTest to see it's results on a macOS --- .../azib/ipscan/core/net/TCPPingerTest.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 test/net/azib/ipscan/core/net/TCPPingerTest.java diff --git a/test/net/azib/ipscan/core/net/TCPPingerTest.java b/test/net/azib/ipscan/core/net/TCPPingerTest.java new file mode 100644 index 00000000..45dd6a21 --- /dev/null +++ b/test/net/azib/ipscan/core/net/TCPPingerTest.java @@ -0,0 +1,27 @@ +package net.azib.ipscan.core.net; + +import net.azib.ipscan.core.ScanningSubject; +import org.junit.Test; + +import java.io.IOException; +import java.net.InetAddress; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class TCPPingerTest { + Pinger pinger = new TCPPinger(10); + + @Test + public void pingAlive() throws IOException { + PingResult result = pinger.ping(new ScanningSubject(InetAddress.getLocalHost()), 3); + assertTrue(result.isAlive()); + assertTrue(result.getAverageTime() <= 10); + } + + @Test + public void pingDead() throws IOException { + PingResult result = pinger.ping(new ScanningSubject(InetAddress.getByName("192.168.99.253")), 1); + assertFalse(result.isAlive()); + } +} \ No newline at end of file