Skip tests that can't be run on the present machine.

This commit is contained in:
akwizgran
2014-04-10 13:13:13 +01:00
parent a2f5f68f87
commit 7aa836c683
2 changed files with 29 additions and 2 deletions

View File

@@ -6,8 +6,10 @@ import java.io.IOException;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.NetworkInterface;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Collections;
import java.util.Hashtable;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
@@ -73,6 +75,10 @@ public class LanTcpPluginTest extends BriarTestCase {
@Test
public void testIncomingConnection() throws Exception {
if(!systemHasLocalIpv4Address()) {
System.err.println("WARNING: Skipping test, no local IPv4 address");
return;
}
Callback callback = new Callback();
Executor executor = Executors.newCachedThreadPool();
DuplexPlugin plugin = new LanTcpPlugin(executor, callback, 0, 0, 0);
@@ -101,6 +107,10 @@ public class LanTcpPluginTest extends BriarTestCase {
@Test
public void testOutgoingConnection() throws Exception {
if(!systemHasLocalIpv4Address()) {
System.err.println("WARNING: Skipping test, no local IPv4 address");
return;
}
Callback callback = new Callback();
Executor executor = Executors.newCachedThreadPool();
DuplexPlugin plugin = new LanTcpPlugin(executor, callback, 0, 0, 0);
@@ -143,6 +153,17 @@ public class LanTcpPluginTest extends BriarTestCase {
plugin.stop();
}
private boolean systemHasLocalIpv4Address() throws Exception {
for(NetworkInterface i : Collections.list(
NetworkInterface.getNetworkInterfaces())) {
for(InetAddress a : Collections.list(i.getInetAddresses())) {
if(a instanceof Inet4Address)
return a.isLinkLocalAddress() || a.isSiteLocalAddress();
}
}
return false;
}
private static class Callback implements DuplexPluginCallback {
private final Map<ContactId, TransportProperties> remote =