From cecb1f0848e63d9c721ca581c7e20e1c634745f8 Mon Sep 17 00:00:00 2001 From: Anton Keks Date: Mon, 23 Mar 2020 11:40:18 -0700 Subject: [PATCH 1/2] getLocalHost() is very slow on a mac in virtual machine - let's use a faster version that doesn't do any lookups --- .../core/ScanningResultComparatorTest.java | 29 ++++++++----------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/test/net/azib/ipscan/core/ScanningResultComparatorTest.java b/test/net/azib/ipscan/core/ScanningResultComparatorTest.java index 1c426fc9..9fc45a10 100644 --- a/test/net/azib/ipscan/core/ScanningResultComparatorTest.java +++ b/test/net/azib/ipscan/core/ScanningResultComparatorTest.java @@ -5,20 +5,16 @@ */ package net.azib.ipscan.core; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import net.azib.ipscan.core.values.*; +import org.junit.Test; import java.net.InetAddress; import java.net.UnknownHostException; -import java.util.Arrays; -import net.azib.ipscan.core.values.InetAddressHolder; -import net.azib.ipscan.core.values.IntegerWithUnit; -import net.azib.ipscan.core.values.NotAvailable; -import net.azib.ipscan.core.values.NotScanned; -import net.azib.ipscan.core.values.NumericRangeList; - -import org.junit.Test; +import static java.util.Arrays.asList; +import static java.util.Arrays.sort; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; /** * ScanningResultComparatorTest @@ -26,7 +22,6 @@ import org.junit.Test; * @author Anton Keks */ public class ScanningResultComparatorTest { - ScanningResultComparator comparator = new ScanningResultComparator(); @Test @@ -46,9 +41,9 @@ public class ScanningResultComparatorTest { assertTrue(comparator.compare(res(125), res(NotScanned.VALUE)) < 0); assertTrue(comparator.compare(res(9090), res(NotAvailable.VALUE)) < 0); - assertTrue(comparator.compare(res(9090), res(new NumericRangeList(Arrays.asList(9090), false))) == 0); - assertTrue(comparator.compare(res(new NumericRangeList(Arrays.asList(154), false)), res(155)) < 0); - assertTrue(comparator.compare(res(new NumericRangeList(Arrays.asList(1, 2, 3), false)), res(new NumericRangeList(Arrays.asList(5, 6), false))) > 0); + assertTrue(comparator.compare(res(9090), res(new NumericRangeList(asList(9090), false))) == 0); + assertTrue(comparator.compare(res(new NumericRangeList(asList(154), false)), res(155)) < 0); + assertTrue(comparator.compare(res(new NumericRangeList(asList(1, 2, 3), false)), res(new NumericRangeList(asList(5, 6), false))) > 0); assertTrue(comparator.compare(res("abc"), res("def")) < 0); assertTrue(comparator.compare(res("123"), res(123)) == 0); @@ -119,7 +114,7 @@ public class ScanningResultComparatorTest { }; comparator.byIndex(0, true); - Arrays.sort(results, comparator); + sort(results, comparator); assertEquals(1, results[0].getValues().get(0)); assertEquals(15, results[1].getValues().get(0)); @@ -130,7 +125,7 @@ public class ScanningResultComparatorTest { assertEquals(NotScanned.VALUE, results[6].getValues().get(0)); comparator.byIndex(0, false); - Arrays.sort(results, comparator); + sort(results, comparator); assertEquals("a", results[0].getValues().get(0)); assertEquals(15, results[1].getValues().get(0)); @@ -140,7 +135,7 @@ public class ScanningResultComparatorTest { } private ScanningResult res(Object ... values) throws UnknownHostException { - ScanningResult result = new ScanningResult(InetAddress.getLocalHost(), values.length); + ScanningResult result = new ScanningResult(InetAddress.getByName("127.0.0.1"), values.length); for (int i = 0; i < values.length; i++) { result.setValue(i, values[i]); } From 0db30a9e135225a42248ae31a4a7526edc09cea5 Mon Sep 17 00:00:00 2001 From: Anton Keks Date: Mon, 23 Mar 2020 12:25:06 -0700 Subject: [PATCH 2/2] add a warning to Mac users that running GUI-related tests will not currently work --- build.gradle | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/build.gradle b/build.gradle index fafc00cb..f7e35b26 100644 --- a/build.gradle +++ b/build.gradle @@ -54,6 +54,13 @@ configurations { compileJava.options.annotationProcessorGeneratedSourcesDirectory = new File('build/generated') +test { + if (platform == "mac") { + jvmArgs "-XstartOnFirstThread" + println("WARNING: tests that touch GUI will fail on Mac due to Cocoa restrictions and Gradle unable to run tests on main thread") + } +} + def packageTask(String platform, def moreJars = [], def moreLibs = [], Closure doMore) { return tasks.create(platform, Jar) { dependsOn = ['classes']