From 7aa836c6838b58752576ad198451de531eeea023 Mon Sep 17 00:00:00 2001
From: akwizgran <akwizgran@users.sourceforge.net>
Date: Thu, 10 Apr 2014 13:13:13 +0100
Subject: [PATCH] Skip tests that can't be run on the present machine.

---
 .../file/UnixRemovableDriveMonitorTest.java   | 10 +++++++--
 .../plugins/tcp/LanTcpPluginTest.java         | 21 +++++++++++++++++++
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/briar-tests/src/org/briarproject/plugins/file/UnixRemovableDriveMonitorTest.java b/briar-tests/src/org/briarproject/plugins/file/UnixRemovableDriveMonitorTest.java
index 26116ef0bc..6710db1d54 100644
--- a/briar-tests/src/org/briarproject/plugins/file/UnixRemovableDriveMonitorTest.java
+++ b/briar-tests/src/org/briarproject/plugins/file/UnixRemovableDriveMonitorTest.java
@@ -1,7 +1,6 @@
 package org.briarproject.plugins.file;
 
 import static java.util.concurrent.TimeUnit.SECONDS;
-import static org.junit.Assume.assumeTrue;
 
 import java.io.File;
 import java.io.IOException;
@@ -23,12 +22,15 @@ public class UnixRemovableDriveMonitorTest extends BriarTestCase {
 
 	@Before
 	public void setUp() {
-		assumeTrue(OsUtils.isLinux() || OsUtils.isMacLeopardOrNewer());
 		testDir.mkdirs();
 	}
 
 	@Test
 	public void testNonexistentDir() throws Exception {
+		if(!(OsUtils.isLinux() || OsUtils.isMacLeopardOrNewer())) {
+			System.err.println("WARNING: Skipping test, can't run on this OS");
+			return;
+		}
 		File doesNotExist = new File(testDir, "doesNotExist");
 		RemovableDriveMonitor monitor = createMonitor(doesNotExist);
 		monitor.start(new Callback() {
@@ -46,6 +48,10 @@ public class UnixRemovableDriveMonitorTest extends BriarTestCase {
 
 	@Test
 	public void testOneCallbackPerFile() throws Exception {
+		if(!(OsUtils.isLinux() || OsUtils.isMacLeopardOrNewer())) {
+			System.err.println("WARNING: Skipping test, can't run on this OS");
+			return;
+		}
 		// Create a callback that will wait for two files before stopping
 		final List<File> detected = new ArrayList<File>();
 		final CountDownLatch latch = new CountDownLatch(2);
diff --git a/briar-tests/src/org/briarproject/plugins/tcp/LanTcpPluginTest.java b/briar-tests/src/org/briarproject/plugins/tcp/LanTcpPluginTest.java
index f5bd88d294..fcbb30c52b 100644
--- a/briar-tests/src/org/briarproject/plugins/tcp/LanTcpPluginTest.java
+++ b/briar-tests/src/org/briarproject/plugins/tcp/LanTcpPluginTest.java
@@ -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 =
-- 
GitLab