add more pinger tests

This commit is contained in:
Anton Keks 2021-01-19 23:23:05 +02:00
parent fb6419daf5
commit a6cf076a1f
5 changed files with 53 additions and 48 deletions

View File

@ -0,0 +1,31 @@
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;
abstract class AbstractPingerTest {
Pinger pinger;
AbstractPingerTest(Pinger pinger) {
this.pinger = pinger;
}
@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());
}
}

View File

@ -0,0 +1,7 @@
package net.azib.ipscan.core.net;
public class CombinedUnprivilegedPingerTest extends AbstractPingerTest {
public CombinedUnprivilegedPingerTest() {
super(new CombinedUnprivilegedPinger(10));
}
}

View File

@ -1,27 +1,7 @@
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 JavaPingerTest {
JavaPinger pinger = new JavaPinger(10);
@Test
public void pingAlive() throws IOException {
PingResult result = pinger.ping(new ScanningSubject(InetAddress.getLocalHost()), 3);
assertTrue(result.isAlive());
assertTrue(result.getAverageTime() <= 10);
public class JavaPingerTest extends AbstractPingerTest {
public JavaPingerTest() {
super(new JavaPinger(10));
}
@Test
public void pingDead() throws IOException {
PingResult result = pinger.ping(new ScanningSubject(InetAddress.getByName("192.168.99.253")), 1);
assertFalse(result.isAlive());
}
}
}

View File

@ -1,27 +1,7 @@
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);
public class TCPPingerTest extends AbstractPingerTest {
public TCPPingerTest() {
super(new TCPPinger(10));
}
@Test
public void pingDead() throws IOException {
PingResult result = pinger.ping(new ScanningSubject(InetAddress.getByName("192.168.99.253")), 1);
assertFalse(result.isAlive());
}
}
}

View File

@ -0,0 +1,7 @@
package net.azib.ipscan.core.net;
public class UDPPingerTest extends AbstractPingerTest {
public UDPPingerTest() {
super(new UDPPinger(10));
}
}