From f587149965f62eb068e99f641563eafbe834d5d2 Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Wed, 21 Jun 2023 18:58:54 +0100 Subject: [PATCH 1/3] Some modernisation. This came about due to a need for a fully JPMS compliant library, i.e. the addition of a `module-info.java`. This is supported by Java 9 and later, but to be able to make a jar compatible with earlier versions we need to use an MRJAR (multi-release). This is supported in Java 8 and onwards, so that must become the lowest common denominator. For this reason, I have made this a major version bump. The change also necessitated updating some Maven plugins and dependencies including JUnit. As a result of updating JUnit, many deprecations needed to be fixed. The source is now warning free (with the need for a few suppression annotations). To recap, * Minimum Java version increased to Java 8. * A Multi-release Jar is built with JPMS support. The module name is the same as the package, `com.github.jgonian.ipmath`. * Various Maven plugins updated. * Testing dependencies updated. * Resulting deprecations fixed. --- commons-ip-math-gwt/pom.xml | 2 +- commons-ip-math/pom.xml | 50 ++++++++++- .../com/github/jgonian/ipmath/AbstractIp.java | 1 + .../jgonian/ipmath/AbstractIpRange.java | 1 + .../github/jgonian/ipmath/AbstractRange.java | 3 +- .../com/github/jgonian/ipmath/AsnRange.java | 1 + .../java/com/github/jgonian/ipmath/Ipv6.java | 1 - .../github/jgonian/ipmath/SizeComparator.java | 2 +- .../github/jgonian/ipmath/SortedRangeSet.java | 2 +- .../src/main/java9/module-info.java | 3 + .../jgonian/ipmath/AbstractRangeTest.java | 7 +- .../github/jgonian/ipmath/AsnRangeTest.java | 10 ++- .../jgonian/ipmath/Ipv4ParseInvalidTest.java | 19 ++-- .../github/jgonian/ipmath/Ipv4RangeTest.java | 6 +- .../com/github/jgonian/ipmath/Ipv4Test.java | 90 +++++++++---------- .../jgonian/ipmath/Ipv6DoubleColonTest.java | 19 ++-- .../jgonian/ipmath/Ipv6ParseInvalidTest.java | 19 ++-- .../jgonian/ipmath/Ipv6ParseValidTest.java | 11 +-- .../com/github/jgonian/ipmath/Ipv6Test.java | 2 +- .../ipmath/SizeComparatorReverseTest.java | 3 +- .../jgonian/ipmath/SizeComparatorTest.java | 3 +- .../jgonian/ipmath/SortedRangeSetTest.java | 4 +- .../jgonian/ipmath/SortedResourceSetTest.java | 4 +- .../StartAndSizeComparatorReverseTest.java | 3 +- .../ipmath/StartAndSizeComparatorTest.java | 3 +- pom.xml | 6 +- 26 files changed, 160 insertions(+), 115 deletions(-) create mode 100644 commons-ip-math/src/main/java9/module-info.java diff --git a/commons-ip-math-gwt/pom.xml b/commons-ip-math-gwt/pom.xml index 8724b1f..36c40de 100644 --- a/commons-ip-math-gwt/pom.xml +++ b/commons-ip-math-gwt/pom.xml @@ -5,7 +5,7 @@ com.github.jgonian commons-ip-math-parent - 1.33-SNAPSHOT + 2.0-SNAPSHOT commons-ip-math-gwt diff --git a/commons-ip-math/pom.xml b/commons-ip-math/pom.xml index de305d6..0859ef6 100644 --- a/commons-ip-math/pom.xml +++ b/commons-ip-math/pom.xml @@ -4,7 +4,7 @@ com.github.jgonian commons-ip-math-parent - 1.33-SNAPSHOT + 2.0-SNAPSHOT commons-ip-math @@ -16,13 +16,13 @@ junit junit - 4.12 + 4.13.2 test nl.jqno.equalsverifier equalsverifier - 1.7.5 + 3.14.2 test @@ -34,6 +34,50 @@ org.apache.maven.plugins maven-source-plugin + + org.apache.maven.plugins + maven-jar-plugin + + + + true + + + true + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + compile + + compile + + + 8 + + + + compile9 + compile + + compile + + + 9 + + ${project.basedir}/src/main/java + ${project.basedir}/src/main/java9 + + true + + + + diff --git a/commons-ip-math/src/main/java/com/github/jgonian/ipmath/AbstractIp.java b/commons-ip-math/src/main/java/com/github/jgonian/ipmath/AbstractIp.java index b58b10d..a3e5d09 100644 --- a/commons-ip-math/src/main/java/com/github/jgonian/ipmath/AbstractIp.java +++ b/commons-ip-math/src/main/java/com/github/jgonian/ipmath/AbstractIp.java @@ -23,6 +23,7 @@ */ package com.github.jgonian.ipmath; +@SuppressWarnings("serial") public abstract class AbstractIp, R extends AbstractIpRange> implements SingleInternetResource { diff --git a/commons-ip-math/src/main/java/com/github/jgonian/ipmath/AbstractIpRange.java b/commons-ip-math/src/main/java/com/github/jgonian/ipmath/AbstractIpRange.java index f562486..2baa751 100644 --- a/commons-ip-math/src/main/java/com/github/jgonian/ipmath/AbstractIpRange.java +++ b/commons-ip-math/src/main/java/com/github/jgonian/ipmath/AbstractIpRange.java @@ -30,6 +30,7 @@ import static java.math.BigInteger.ONE; import static java.math.BigInteger.ZERO; +@SuppressWarnings("serial") public abstract class AbstractIpRange, R extends AbstractIpRange> extends AbstractRange implements InternetResourceRange { diff --git a/commons-ip-math/src/main/java/com/github/jgonian/ipmath/AbstractRange.java b/commons-ip-math/src/main/java/com/github/jgonian/ipmath/AbstractRange.java index 4605e5d..91ecbcd 100644 --- a/commons-ip-math/src/main/java/com/github/jgonian/ipmath/AbstractRange.java +++ b/commons-ip-math/src/main/java/com/github/jgonian/ipmath/AbstractRange.java @@ -28,6 +28,7 @@ import java.util.Iterator; import java.util.List; +@SuppressWarnings("serial") public abstract class AbstractRange, R extends Range> implements Range { private final C start; @@ -188,7 +189,7 @@ public final boolean equals(Object o) { if (!(o instanceof AbstractRange)) { return false; } - AbstractRange that = (AbstractRange) o; + AbstractRange that = (AbstractRange) o; if (!start.equals(that.start)) { return false; } diff --git a/commons-ip-math/src/main/java/com/github/jgonian/ipmath/AsnRange.java b/commons-ip-math/src/main/java/com/github/jgonian/ipmath/AsnRange.java index 4f0be0e..cb575d0 100644 --- a/commons-ip-math/src/main/java/com/github/jgonian/ipmath/AsnRange.java +++ b/commons-ip-math/src/main/java/com/github/jgonian/ipmath/AsnRange.java @@ -23,6 +23,7 @@ */ package com.github.jgonian.ipmath; +@SuppressWarnings("serial") public final class AsnRange extends AbstractRange implements InternetResourceRange { protected AsnRange(Asn start, Asn end) { diff --git a/commons-ip-math/src/main/java/com/github/jgonian/ipmath/Ipv6.java b/commons-ip-math/src/main/java/com/github/jgonian/ipmath/Ipv6.java index 57b1f1a..e0574ad 100644 --- a/commons-ip-math/src/main/java/com/github/jgonian/ipmath/Ipv6.java +++ b/commons-ip-math/src/main/java/com/github/jgonian/ipmath/Ipv6.java @@ -24,7 +24,6 @@ package com.github.jgonian.ipmath; import java.math.BigInteger; -import java.util.regex.Pattern; import static java.math.BigInteger.ONE; diff --git a/commons-ip-math/src/main/java/com/github/jgonian/ipmath/SizeComparator.java b/commons-ip-math/src/main/java/com/github/jgonian/ipmath/SizeComparator.java index 1294c5d..f746910 100644 --- a/commons-ip-math/src/main/java/com/github/jgonian/ipmath/SizeComparator.java +++ b/commons-ip-math/src/main/java/com/github/jgonian/ipmath/SizeComparator.java @@ -47,7 +47,7 @@ public static > Comparator reverse() { private SizeComparator() { } - @SuppressWarnings({"unchecked"}) + @SuppressWarnings({"unchecked", "rawtypes"}) @Override public int compare(R left, R right) { return ((Comparable)left.size()).compareTo(right.size()); diff --git a/commons-ip-math/src/main/java/com/github/jgonian/ipmath/SortedRangeSet.java b/commons-ip-math/src/main/java/com/github/jgonian/ipmath/SortedRangeSet.java index 8406fb1..9903d4d 100644 --- a/commons-ip-math/src/main/java/com/github/jgonian/ipmath/SortedRangeSet.java +++ b/commons-ip-math/src/main/java/com/github/jgonian/ipmath/SortedRangeSet.java @@ -142,7 +142,7 @@ public final boolean equals(Object o) { if (!(o instanceof SortedRangeSet)) { return false; } - SortedRangeSet that = (SortedRangeSet) o; + SortedRangeSet that = (SortedRangeSet) o; return set.equals(that.set); } diff --git a/commons-ip-math/src/main/java9/module-info.java b/commons-ip-math/src/main/java9/module-info.java new file mode 100644 index 0000000..95ec28c --- /dev/null +++ b/commons-ip-math/src/main/java9/module-info.java @@ -0,0 +1,3 @@ +module com.github.jgonian.ipmath { + exports com.github.jgonian.ipmath; +} \ No newline at end of file diff --git a/commons-ip-math/src/test/java/com/github/jgonian/ipmath/AbstractRangeTest.java b/commons-ip-math/src/test/java/com/github/jgonian/ipmath/AbstractRangeTest.java index 24346ae..ac99f0d 100644 --- a/commons-ip-math/src/test/java/com/github/jgonian/ipmath/AbstractRangeTest.java +++ b/commons-ip-math/src/test/java/com/github/jgonian/ipmath/AbstractRangeTest.java @@ -23,9 +23,9 @@ */ package com.github.jgonian.ipmath; -import static junit.framework.Assert.assertFalse; -import static junit.framework.Assert.assertTrue; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertFalse; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -830,7 +830,8 @@ public void shouldRemoveIfOtherIsContainedAndOnStart() { assertEquals(result, range.exclude(other)); } - @Test + @SuppressWarnings("serial") + @Test public void shouldRemoveIfOtherIsContained() { // range |---------| [10, 20] // other |--| [13, 15] diff --git a/commons-ip-math/src/test/java/com/github/jgonian/ipmath/AsnRangeTest.java b/commons-ip-math/src/test/java/com/github/jgonian/ipmath/AsnRangeTest.java index a9092f0..b894547 100644 --- a/commons-ip-math/src/test/java/com/github/jgonian/ipmath/AsnRangeTest.java +++ b/commons-ip-math/src/test/java/com/github/jgonian/ipmath/AsnRangeTest.java @@ -23,7 +23,9 @@ */ package com.github.jgonian.ipmath; -import static junit.framework.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertFalse; import static com.github.jgonian.ipmath.Asn.*; import java.util.ArrayList; import java.util.Arrays; @@ -117,9 +119,9 @@ public void testToString() { @Test public void testSize() { - assertEquals(new Long(1), as1.asRange().size()); - assertEquals(new Long(ASN_16_BIT_MAX_VALUE + 1), AsnRange.from(FIRST_ASN).to(Asn.LAST_16_BIT_ASN).size()); - assertEquals(new Long(ASN_32_BIT_MAX_VALUE + 1), AsnRange.from(FIRST_ASN).to(Asn.LAST_32_BIT_ASN).size()); + assertEquals(Long.valueOf(1), as1.asRange().size()); + assertEquals(Long.valueOf(ASN_16_BIT_MAX_VALUE + 1), AsnRange.from(FIRST_ASN).to(Asn.LAST_16_BIT_ASN).size()); + assertEquals(Long.valueOf(ASN_32_BIT_MAX_VALUE + 1), AsnRange.from(FIRST_ASN).to(Asn.LAST_32_BIT_ASN).size()); } @Override diff --git a/commons-ip-math/src/test/java/com/github/jgonian/ipmath/Ipv4ParseInvalidTest.java b/commons-ip-math/src/test/java/com/github/jgonian/ipmath/Ipv4ParseInvalidTest.java index 2824223..a1a2c13 100644 --- a/commons-ip-math/src/test/java/com/github/jgonian/ipmath/Ipv4ParseInvalidTest.java +++ b/commons-ip-math/src/test/java/com/github/jgonian/ipmath/Ipv4ParseInvalidTest.java @@ -23,31 +23,28 @@ */ package com.github.jgonian.ipmath; -import org.junit.Rule; +import static org.junit.Assert.assertThrows; + +import java.util.Arrays; +import java.util.List; + import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; -import java.util.Arrays; -import java.util.List; - @RunWith(Parameterized.class) public class Ipv4ParseInvalidTest { - @Rule - public ExpectedException thrown = ExpectedException.none(); - @Parameter(0) public String input; @Test public void test() { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Invalid IPv4 address: '" + input + "'"); - Ipv4.parse(input); + assertThrows("Invalid IPv4 address: '" + input + "'", IllegalArgumentException.class, () -> { + Ipv4.parse(input); + }); } @Parameters(name = "{index}: parse({0})") diff --git a/commons-ip-math/src/test/java/com/github/jgonian/ipmath/Ipv4RangeTest.java b/commons-ip-math/src/test/java/com/github/jgonian/ipmath/Ipv4RangeTest.java index d293b69..41bfe58 100644 --- a/commons-ip-math/src/test/java/com/github/jgonian/ipmath/Ipv4RangeTest.java +++ b/commons-ip-math/src/test/java/com/github/jgonian/ipmath/Ipv4RangeTest.java @@ -32,7 +32,7 @@ import static com.github.jgonian.ipmath.Ipv4.FIRST_IPV4_ADDRESS; import static com.github.jgonian.ipmath.Ipv4.LAST_IPV4_ADDRESS; import static com.github.jgonian.ipmath.Ipv4.MAXIMUM_VALUE; -import static junit.framework.Assert.assertFalse; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertEquals; public class Ipv4RangeTest extends AbstractRangeTest { @@ -185,8 +185,8 @@ public void testToStringInDecimalNotation() { @Test public void testSize() { - assertEquals(new Long(1), ip1.asRange().size()); - assertEquals(new Long(MAXIMUM_VALUE + 1), Ipv4Range.from(FIRST_IPV4_ADDRESS).to(LAST_IPV4_ADDRESS).size()); + assertEquals(Long.valueOf(1), ip1.asRange().size()); + assertEquals(Long.valueOf(MAXIMUM_VALUE + 1), Ipv4Range.from(FIRST_IPV4_ADDRESS).to(LAST_IPV4_ADDRESS).size()); } @Override diff --git a/commons-ip-math/src/test/java/com/github/jgonian/ipmath/Ipv4Test.java b/commons-ip-math/src/test/java/com/github/jgonian/ipmath/Ipv4Test.java index 7863e62..74da8ac 100644 --- a/commons-ip-math/src/test/java/com/github/jgonian/ipmath/Ipv4Test.java +++ b/commons-ip-math/src/test/java/com/github/jgonian/ipmath/Ipv4Test.java @@ -23,22 +23,20 @@ */ package com.github.jgonian.ipmath; -import static junit.framework.Assert.assertEquals; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; + import java.math.BigInteger; +import org.junit.Test; + import nl.jqno.equalsverifier.EqualsVerifier; import nl.jqno.equalsverifier.Warning; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; public class Ipv4Test { - @Rule - public ExpectedException thrown = ExpectedException.none(); - @Test public void testEqualsContract() { EqualsVerifier.forClass(Ipv4.class).suppress(Warning.NULL_FIELDS).withRedefinedSuperclass().verify(); @@ -54,23 +52,23 @@ public void testBuilderMethods() { @Test public void testBuilderWithNull() { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("from cannot be null"); - Ipv4.of((BigInteger) null); + assertThrows("from cannot be null", IllegalArgumentException.class, () -> { + Ipv4.of((BigInteger) null); + }); } @Test public void testUpperBound() { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Value of IPv4 has to be less than or equal to 4294967295"); - new Ipv4(Ipv4.MAXIMUM_VALUE + 1); + assertThrows("Value of IPv4 has to be less than or equal to 4294967295", IllegalArgumentException.class, () -> { + new Ipv4(Ipv4.MAXIMUM_VALUE + 1); + }); } @Test public void testLowerBound() { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Value of IPv4 has to be greater than or equal to 0"); - new Ipv4(Ipv4.MINIMUM_VALUE - 1); + assertThrows("Value of IPv4 has to be greater than or equal to 0", IllegalArgumentException.class, () -> { + new Ipv4(Ipv4.MINIMUM_VALUE - 1); + }); } @Test @@ -100,58 +98,58 @@ public void shouldParseIPv4AddressWithLeadingAndTrailingSpaces() { @Test public void shouldFailOnLessOctets() { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Invalid IPv4 address: '10.1.1'"); - Ipv4.parse("10.1.1"); + assertThrows("Invalid IPv4 address: '10.1.1'", IllegalArgumentException.class, () -> { + Ipv4.parse("10.1.1"); + }); } @Test public void shouldFailOnMoreOctets() { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Invalid IPv4 address: '10.1.1.1.1'"); - Ipv4.parse("10.1.1.1.1"); + assertThrows("Invalid IPv4 address: '10.1.1.1.1'", IllegalArgumentException.class, () -> { + Ipv4.parse("10.1.1.1.1"); + }); } @Test public void shouldFailWhenEndingWithNonDigit() { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Invalid IPv4 address: '10.1.1.1.'"); - Ipv4.parse("10.1.1.1."); + assertThrows("Invalid IPv4 address: '10.1.1.1.'", IllegalArgumentException.class, () -> { + Ipv4.parse("10.1.1.1."); + }); } @Test public void shouldFailWhenStartingWithNonDigit() { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Invalid IPv4 address: '.10.1.1.1'"); - Ipv4.parse(".10.1.1.1"); + assertThrows("Invalid IPv4 address: '.10.1.1.1'", IllegalArgumentException.class, () -> { + Ipv4.parse(".10.1.1.1"); + }); } @Test public void shouldFailWhenOctetContainsNonDigit() { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Invalid IPv4 address: '10.a.1.0'"); - Ipv4.parse("10.a.1.0"); + assertThrows("Invalid IPv4 address: '10.a.1.0'", IllegalArgumentException.class, () -> { + Ipv4.parse("10.a.1.0"); + }); } @Test public void shouldFailOnOutOfBoundsByte() { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Invalid IPv4 address: '256.0.0.0'"); - Ipv4.parse("256.0.0.0"); + assertThrows("Invalid IPv4 address: '256.0.0.0'", IllegalArgumentException.class, () -> { + Ipv4.parse("256.0.0.0"); + }); } @Test public void shouldFailOnOutOfBoundsByte_NegativeByte() { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Invalid IPv4 address: '13.-40.0.0'"); - Ipv4.parse("13.-40.0.0"); + assertThrows("Invalid IPv4 address: '13.-40.0.0'", IllegalArgumentException.class, () -> { + Ipv4.parse("13.-40.0.0"); + }); } @Test public void shouldFailOnLeadingZeros() { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Invalid IPv4 address: '192.168.08.1'"); - Ipv4.parse("192.168.08.1"); + assertThrows("Invalid IPv4 address: '192.168.08.1'", IllegalArgumentException.class, () -> { + Ipv4.parse("192.168.08.1"); + }); } @Test @@ -174,16 +172,16 @@ public void shouldCalculateBoundsGivenAnAddressAndAPrefix() { @Test public void shouldFailToCalculateLowerBoundWhenPrefixIsOutOfRange() { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Value [33] out of range: [0..32]"); - Ipv4.parse("192.168.0.100").lowerBoundForPrefix(33); + assertThrows("Value [33] out of range: [0..32]", IllegalArgumentException.class, () -> { + Ipv4.parse("192.168.0.100").lowerBoundForPrefix(33); + }); } @Test public void shouldFailToCalculateUpperBoundWhenPrefixIsOutOfRange() { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Value [33] out of range: [0..32]"); - Ipv4.parse("192.168.0.100").upperBoundForPrefix(33); + assertThrows("Value [33] out of range: [0..32]", IllegalArgumentException.class, () -> { + Ipv4.parse("192.168.0.100").upperBoundForPrefix(33); + }); } @Test diff --git a/commons-ip-math/src/test/java/com/github/jgonian/ipmath/Ipv6DoubleColonTest.java b/commons-ip-math/src/test/java/com/github/jgonian/ipmath/Ipv6DoubleColonTest.java index 84d16f9..5268efb 100644 --- a/commons-ip-math/src/test/java/com/github/jgonian/ipmath/Ipv6DoubleColonTest.java +++ b/commons-ip-math/src/test/java/com/github/jgonian/ipmath/Ipv6DoubleColonTest.java @@ -23,31 +23,28 @@ */ package com.github.jgonian.ipmath; -import org.junit.Rule; +import static org.junit.Assert.assertThrows; + +import java.util.Arrays; +import java.util.List; + import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; -import java.util.Arrays; -import java.util.List; - @RunWith(Parameterized.class) public class Ipv6DoubleColonTest { - @Rule - public ExpectedException thrown = ExpectedException.none(); - @Parameter(0) public String input; @Test public void test() { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Invalid IPv6 address: '" + input + "'"); - Ipv6.parse(input); + assertThrows("Invalid IPv6 address: '" + input + "'", IllegalArgumentException.class, () -> { + Ipv6.parse(input); + }); } // Invalid IPv6 examples are taken from http://download.dartware.com/thirdparty/test-ipv6-regex.pl diff --git a/commons-ip-math/src/test/java/com/github/jgonian/ipmath/Ipv6ParseInvalidTest.java b/commons-ip-math/src/test/java/com/github/jgonian/ipmath/Ipv6ParseInvalidTest.java index 03b9c4c..fb9ccc7 100644 --- a/commons-ip-math/src/test/java/com/github/jgonian/ipmath/Ipv6ParseInvalidTest.java +++ b/commons-ip-math/src/test/java/com/github/jgonian/ipmath/Ipv6ParseInvalidTest.java @@ -23,31 +23,28 @@ */ package com.github.jgonian.ipmath; -import org.junit.Rule; +import static org.junit.Assert.assertThrows; + +import java.util.Arrays; +import java.util.List; + import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; -import java.util.Arrays; -import java.util.List; - @RunWith(Parameterized.class) public class Ipv6ParseInvalidTest { - @Rule - public ExpectedException thrown = ExpectedException.none(); - @Parameter(0) public String input; @Test public void test() { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Invalid IPv6 address: '" + input + "'"); - Ipv6.parse(input); + assertThrows("Invalid IPv6 address: '" + input + "'", IllegalArgumentException.class, () -> { + Ipv6.parse(input); + }); } // Invalid IPv6 examples are copied from http://download.dartware.com/thirdparty/test-ipv6-regex.pl diff --git a/commons-ip-math/src/test/java/com/github/jgonian/ipmath/Ipv6ParseValidTest.java b/commons-ip-math/src/test/java/com/github/jgonian/ipmath/Ipv6ParseValidTest.java index 0c85937..5b360bc 100644 --- a/commons-ip-math/src/test/java/com/github/jgonian/ipmath/Ipv6ParseValidTest.java +++ b/commons-ip-math/src/test/java/com/github/jgonian/ipmath/Ipv6ParseValidTest.java @@ -23,23 +23,18 @@ */ package com.github.jgonian.ipmath; -import org.junit.Rule; +import java.util.Arrays; +import java.util.List; + import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; -import java.util.Arrays; -import java.util.List; - @RunWith(Parameterized.class) public class Ipv6ParseValidTest { - @Rule - public ExpectedException thrown = ExpectedException.none(); - @Parameter(0) public String input; diff --git a/commons-ip-math/src/test/java/com/github/jgonian/ipmath/Ipv6Test.java b/commons-ip-math/src/test/java/com/github/jgonian/ipmath/Ipv6Test.java index dcd2c7f..ec565d5 100644 --- a/commons-ip-math/src/test/java/com/github/jgonian/ipmath/Ipv6Test.java +++ b/commons-ip-math/src/test/java/com/github/jgonian/ipmath/Ipv6Test.java @@ -30,7 +30,7 @@ import java.math.BigInteger; import java.util.ArrayList; -import static junit.framework.Assert.assertEquals; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.*; public class Ipv6Test { diff --git a/commons-ip-math/src/test/java/com/github/jgonian/ipmath/SizeComparatorReverseTest.java b/commons-ip-math/src/test/java/com/github/jgonian/ipmath/SizeComparatorReverseTest.java index 402162a..1fd77f4 100644 --- a/commons-ip-math/src/test/java/com/github/jgonian/ipmath/SizeComparatorReverseTest.java +++ b/commons-ip-math/src/test/java/com/github/jgonian/ipmath/SizeComparatorReverseTest.java @@ -23,7 +23,8 @@ */ package com.github.jgonian.ipmath; -import static junit.framework.Assert.*; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; import java.util.Comparator; import org.junit.Test; diff --git a/commons-ip-math/src/test/java/com/github/jgonian/ipmath/SizeComparatorTest.java b/commons-ip-math/src/test/java/com/github/jgonian/ipmath/SizeComparatorTest.java index d5277c4..9a8ed1d 100644 --- a/commons-ip-math/src/test/java/com/github/jgonian/ipmath/SizeComparatorTest.java +++ b/commons-ip-math/src/test/java/com/github/jgonian/ipmath/SizeComparatorTest.java @@ -23,7 +23,8 @@ */ package com.github.jgonian.ipmath; -import static junit.framework.Assert.*; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; import java.util.Comparator; import org.junit.Test; diff --git a/commons-ip-math/src/test/java/com/github/jgonian/ipmath/SortedRangeSetTest.java b/commons-ip-math/src/test/java/com/github/jgonian/ipmath/SortedRangeSetTest.java index 3a5a6bf..fdb9cc4 100644 --- a/commons-ip-math/src/test/java/com/github/jgonian/ipmath/SortedRangeSetTest.java +++ b/commons-ip-math/src/test/java/com/github/jgonian/ipmath/SortedRangeSetTest.java @@ -23,7 +23,9 @@ */ package com.github.jgonian.ipmath; -import static junit.framework.Assert.*; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertEquals; import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; diff --git a/commons-ip-math/src/test/java/com/github/jgonian/ipmath/SortedResourceSetTest.java b/commons-ip-math/src/test/java/com/github/jgonian/ipmath/SortedResourceSetTest.java index 165a595..7032fec 100644 --- a/commons-ip-math/src/test/java/com/github/jgonian/ipmath/SortedResourceSetTest.java +++ b/commons-ip-math/src/test/java/com/github/jgonian/ipmath/SortedResourceSetTest.java @@ -23,7 +23,9 @@ */ package com.github.jgonian.ipmath; -import static junit.framework.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertFalse; import java.util.HashSet; import java.util.Set; diff --git a/commons-ip-math/src/test/java/com/github/jgonian/ipmath/StartAndSizeComparatorReverseTest.java b/commons-ip-math/src/test/java/com/github/jgonian/ipmath/StartAndSizeComparatorReverseTest.java index ab9d0aa..8e8d021 100644 --- a/commons-ip-math/src/test/java/com/github/jgonian/ipmath/StartAndSizeComparatorReverseTest.java +++ b/commons-ip-math/src/test/java/com/github/jgonian/ipmath/StartAndSizeComparatorReverseTest.java @@ -23,7 +23,8 @@ */ package com.github.jgonian.ipmath; -import static junit.framework.Assert.*; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertSame; import java.util.Comparator; import org.junit.Test; diff --git a/commons-ip-math/src/test/java/com/github/jgonian/ipmath/StartAndSizeComparatorTest.java b/commons-ip-math/src/test/java/com/github/jgonian/ipmath/StartAndSizeComparatorTest.java index 1b25126..4298f45 100644 --- a/commons-ip-math/src/test/java/com/github/jgonian/ipmath/StartAndSizeComparatorTest.java +++ b/commons-ip-math/src/test/java/com/github/jgonian/ipmath/StartAndSizeComparatorTest.java @@ -23,7 +23,8 @@ */ package com.github.jgonian.ipmath; -import static junit.framework.Assert.*; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertSame; import java.util.Comparator; import org.junit.Test; diff --git a/pom.xml b/pom.xml index bdd4b9a..3b07672 100644 --- a/pom.xml +++ b/pom.xml @@ -3,14 +3,14 @@ com.github.jgonian commons-ip-math-parent - 1.33-SNAPSHOT + 2.0-SNAPSHOT pom ${project.groupId}:${project.artifactId} A project to make it easier to work with Internet resources, such as IPv4, IPv6 and AS numbers. http://github.com/jgonian/commons-ip-math - 1.6 + 1.8 UTF-8 @@ -52,7 +52,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.3 + 3.8.1 ${target.jdk} ${target.jdk} From 6e4e77129854248dba624eab984671e89631f109 Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Thu, 22 Jun 2023 21:58:39 +0100 Subject: [PATCH 2/3] Added some information about Java version requirements to the README.md. --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index f1add76..3c98468 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,17 @@ libraryDependencies += "com.github.jgonian" % "commons-ip-math" % s"${version}" For the latest released `version`, check [the Central Repository](https://maven-badges.herokuapp.com/maven-central/com.github.jgonian/commons-ip-math). +Versions +-------- + +Starting from version *2.0*, the minimum Java version required has changed to Java 8. This is in +order to support [JPMS](https://en.wikipedia.org/wiki/Java_Platform_Module_System). + + * To use version *2.0* or later as a module, a minimum of Java 9 will be required. The module name is `com.github.jgonian.ipmath`. + * To use version *2.0* or later as a traditional classpath library, a minimum of Java 8 will be required. + * To use with Java 1.6 and Java 1.7, your must use version *1.3* of this library + + Examples --------- From a07f7d09360c1072f27f18ed93fb1347e4fa5657 Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Thu, 22 Jun 2023 22:09:17 +0100 Subject: [PATCH 3/3] Tweaked text. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3c98468..68ba695 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ order to support [JPMS](https://en.wikipedia.org/wiki/Java_Platform_Module_Syste * To use version *2.0* or later as a module, a minimum of Java 9 will be required. The module name is `com.github.jgonian.ipmath`. * To use version *2.0* or later as a traditional classpath library, a minimum of Java 8 will be required. - * To use with Java 1.6 and Java 1.7, your must use version *1.3* of this library + * To use with Java 1.6 and Java 1.7, your should use latest the latest of the *1.x* versions of this library. Examples