diff --git a/dev-bin/release.sh b/dev-bin/release.sh index 3f6c13c3..9d6f2fd9 100755 --- a/dev-bin/release.sh +++ b/dev-bin/release.sh @@ -50,6 +50,7 @@ fi popd +mvn versions:display-plugin-updates mvn versions:display-dependency-updates read -r -n 1 -p "Continue given above dependencies? (y/n) " should_continue diff --git a/pom.xml b/pom.xml index bb6cf441..ada08dae 100644 --- a/pom.xml +++ b/pom.xml @@ -37,14 +37,40 @@ - junit - junit - 4.13.2 + org.junit.jupiter + junit-jupiter + 5.10.1 + test + + + org.hamcrest + java-hamcrest + 2.0.0.0 test + + org.apache.maven.plugins + maven-enforcer-plugin + 3.4.1 + + + enforce-maven + + enforce + + + + + 3.2.5 + + + + + + org.apache.maven.plugins maven-checkstyle-plugin @@ -121,6 +147,11 @@ 11 + + org.apache.maven.plugins + maven-surefire-plugin + 3.2.2 + org.eluder.coveralls coveralls-maven-plugin diff --git a/src/main/java/com/maxmind/db/Networks.java b/src/main/java/com/maxmind/db/Networks.java index b585d6ea..4214357c 100644 --- a/src/main/java/com/maxmind/db/Networks.java +++ b/src/main/java/com/maxmind/db/Networks.java @@ -96,7 +96,7 @@ public DatabaseRecord next() { prefixLength -= 96; } - return new DatabaseRecord(data, ipAddr, prefixLength); + return new DatabaseRecord<>(data, ipAddr, prefixLength); } catch (IOException e) { throw new NetworksIterationException(e); } diff --git a/src/main/java/com/maxmind/db/Reader.java b/src/main/java/com/maxmind/db/Reader.java index c54b675d..3f83a5ad 100644 --- a/src/main/java/com/maxmind/db/Reader.java +++ b/src/main/java/com/maxmind/db/Reader.java @@ -322,9 +322,9 @@ public Networks networksWithin( int node = traverseResult[0]; int prefix = traverseResult[1]; - return new Networks(this, includeAliasedNetworks, - new Networks.NetworkNode[]{new Networks.NetworkNode(ipBytes, prefix, node)}, - typeParameterClass); + return new Networks<>(this, includeAliasedNetworks, + new Networks.NetworkNode[] {new Networks.NetworkNode(ipBytes, prefix, node)}, + typeParameterClass); } /** diff --git a/src/test/java/com/maxmind/db/DecoderTest.java b/src/test/java/com/maxmind/db/DecoderTest.java index 154baafd..2668bd58 100644 --- a/src/test/java/com/maxmind/db/DecoderTest.java +++ b/src/test/java/com/maxmind/db/DecoderTest.java @@ -2,9 +2,9 @@ import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.File; import java.io.IOException; @@ -20,7 +20,7 @@ import java.util.List; import java.util.Map; import java.util.UUID; -import org.junit.Test; +import org.junit.jupiter.api.Test; @SuppressWarnings({"boxing", "static-method"}) public class DecoderTest { @@ -434,42 +434,42 @@ private static void testTypeDecoding(Type type, Map tests) // XXX - this could be streamlined if (type.equals(Type.BYTES)) { - assertArrayEquals(desc, (byte[]) expect, decoder.decode(0, byte[].class)); + assertArrayEquals((byte[]) expect, decoder.decode(0, byte[].class), desc); } else if (type.equals(Type.ARRAY)) { - assertEquals(desc, expect, decoder.decode(0, List.class)); + assertEquals(expect, decoder.decode(0, List.class), desc); } else if (type.equals(Type.UINT16) || type.equals(Type.INT32)) { - assertEquals(desc, expect, decoder.decode(0, Integer.class)); + assertEquals(expect, decoder.decode(0, Integer.class), desc); } else if (type.equals(Type.UINT32) || type.equals(Type.POINTER)) { - assertEquals(desc, expect, decoder.decode(0, Long.class)); + assertEquals(expect, decoder.decode(0, Long.class), desc); } else if (type.equals(Type.UINT64) || type.equals(Type.UINT128)) { - assertEquals(desc, expect, decoder.decode(0, BigInteger.class)); + assertEquals(expect, decoder.decode(0, BigInteger.class), desc); } else if (type.equals(Type.DOUBLE)) { - assertEquals(desc, expect, decoder.decode(0, Double.class)); + assertEquals(expect, decoder.decode(0, Double.class), desc); } else if (type.equals(Type.FLOAT)) { - assertEquals(desc, expect, decoder.decode(0, Float.class)); + assertEquals(expect, decoder.decode(0, Float.class), desc); } else if (type.equals(Type.UTF8_STRING)) { - assertEquals(desc, expect, decoder.decode(0, String.class)); + assertEquals(expect, decoder.decode(0, String.class), desc); } else if (type.equals(Type.BOOLEAN)) { - assertEquals(desc, expect, decoder.decode(0, Boolean.class)); + assertEquals(expect, decoder.decode(0, Boolean.class), desc); } else { // We hit this for Type.MAP. Map got = decoder.decode(0, Map.class); Map expectMap = (Map) expect; - assertEquals(desc, expectMap.size(), got.size()); + assertEquals(expectMap.size(), got.size(), desc); for (Object keyObject : expectMap.keySet()) { String key = (String) keyObject; Object value = expectMap.get(key); if (value instanceof Object[]) { - assertArrayEquals(desc, (Object[]) value, (Object[]) got.get(key)); + assertArrayEquals((Object[]) value, (Object[]) got.get(key), desc); } else { - assertEquals(desc, value, got.get(key)); + assertEquals(value, got.get(key), desc); } } } diff --git a/src/test/java/com/maxmind/db/MultiThreadedTest.java b/src/test/java/com/maxmind/db/MultiThreadedTest.java index b6900aa3..bbf6b4a3 100644 --- a/src/test/java/com/maxmind/db/MultiThreadedTest.java +++ b/src/test/java/com/maxmind/db/MultiThreadedTest.java @@ -1,6 +1,6 @@ package com.maxmind.db; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; import java.net.InetAddress; @@ -12,7 +12,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class MultiThreadedTest { diff --git a/src/test/java/com/maxmind/db/NetworkTest.java b/src/test/java/com/maxmind/db/NetworkTest.java index ad3d4841..d04d7fa6 100644 --- a/src/test/java/com/maxmind/db/NetworkTest.java +++ b/src/test/java/com/maxmind/db/NetworkTest.java @@ -1,10 +1,10 @@ package com.maxmind.db; -import static junit.framework.TestCase.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.net.InetAddress; import java.net.UnknownHostException; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class NetworkTest { @Test diff --git a/src/test/java/com/maxmind/db/PointerTest.java b/src/test/java/com/maxmind/db/PointerTest.java index f8c0dee4..1aa755f6 100644 --- a/src/test/java/com/maxmind/db/PointerTest.java +++ b/src/test/java/com/maxmind/db/PointerTest.java @@ -1,13 +1,13 @@ package com.maxmind.db; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import com.maxmind.db.Reader.FileMode; import java.io.File; import java.io.IOException; import java.util.HashMap; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class PointerTest { @SuppressWarnings("static-method") diff --git a/src/test/java/com/maxmind/db/ReaderTest.java b/src/test/java/com/maxmind/db/ReaderTest.java index b7998496..0f4d09b9 100644 --- a/src/test/java/com/maxmind/db/ReaderTest.java +++ b/src/test/java/com/maxmind/db/ReaderTest.java @@ -3,14 +3,14 @@ import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.File; import java.io.IOException; @@ -27,19 +27,19 @@ import java.util.Map; import java.util.Vector; import java.util.concurrent.ConcurrentHashMap; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class ReaderTest { private Reader testReader; - @Before + @BeforeEach public void setupReader() { this.testReader = null; } - @After + @AfterEach public void teardownReader() throws IOException { if (this.testReader != null) { this.testReader.close(); @@ -93,9 +93,11 @@ public void testNetworks() throws IOException, InvalidDatabaseException, Invalid InetAddress actualIPInData = InetAddress.getByName(data.get("ip")); - assertEquals("expected ip address", + assertEquals( iteration.getNetwork().getNetworkAddress(), - actualIPInData); + actualIPInData, + "expected ip address" + ); } reader.close(); @@ -339,7 +341,7 @@ public void testNetworksWithin() throws IOException, InvalidNetworkException{ boolean includeAliasedNetworks = !test.skipAliasedNetworks; Networks networks = reader.networksWithin(network, includeAliasedNetworks, Map.class); - ArrayList innerIPs = new ArrayList(); + ArrayList innerIPs = new ArrayList<>(); while(networks.hasNext()){ DatabaseRecord> iteration = networks.next(); innerIPs.add(iteration.getNetwork().toString()); @@ -376,7 +378,7 @@ public void testGeoIPNetworksWithin() throws IOException, InvalidNetworkExceptio Networks networks = reader.networksWithin(network, test.skipAliasedNetworks, Map.class); - ArrayList innerIPs = new ArrayList(); + ArrayList innerIPs = new ArrayList<>(); while(networks.hasNext()){ DatabaseRecord> iteration = networks.next(); innerIPs.add(iteration.getNetwork().toString()); @@ -1208,7 +1210,7 @@ private void testMetadata(Reader reader, int ipVersion, long recordSize) { Metadata metadata = reader.getMetadata(); - assertEquals("major version", 2, metadata.getBinaryFormatMajorVersion()); + assertEquals(2, metadata.getBinaryFormatMajorVersion(), "major version"); assertEquals(0, metadata.getBinaryFormatMinorVersion()); assertEquals(ipVersion, metadata.getIpVersion()); assertEquals("Test", metadata.getDatabaseType()); @@ -1237,8 +1239,11 @@ private void testIpV4(Reader reader, File file) throws IOException { Map data = new HashMap<>(); data.put("ip", address); - assertEquals("found expected data record for " + address + " in " - + file, data, reader.get(InetAddress.getByName(address), Map.class)); + assertEquals( + data, + reader.get(InetAddress.getByName(address), Map.class), + "found expected data record for " + address + " in " + file + ); } Map pairs = new HashMap<>(); @@ -1253,8 +1258,11 @@ private void testIpV4(Reader reader, File file) throws IOException { Map data = new HashMap<>(); data.put("ip", pairs.get(address)); - assertEquals("found expected data record for " + address + " in " - + file, data, reader.get(InetAddress.getByName(address), Map.class)); + assertEquals( + data, + reader.get(InetAddress.getByName(address), Map.class), + "found expected data record for " + address + " in " + file + ); } for (String ip : new String[] {"1.1.1.33", "255.254.253.123"}) { @@ -1271,8 +1279,11 @@ private void testIpV6(Reader reader, File file) throws IOException { Map data = new HashMap<>(); data.put("ip", address); - assertEquals("found expected data record for " + address + " in " - + file, data, reader.get(InetAddress.getByName(address), Map.class)); + assertEquals( + data, + reader.get(InetAddress.getByName(address), Map.class), + "found expected data record for " + address + " in " + file + ); } Map pairs = new HashMap<>(); @@ -1289,8 +1300,11 @@ private void testIpV6(Reader reader, File file) throws IOException { Map data = new HashMap<>(); data.put("ip", pairs.get(address)); - assertEquals("found expected data record for " + address + " in " - + file, data, reader.get(InetAddress.getByName(address), Map.class)); + assertEquals( + data, + reader.get(InetAddress.getByName(address), Map.class), + "found expected data record for " + address + " in " + file + ); } for (String ip : new String[] {"1.1.1.33", "255.254.253.123", "89fa::"}) {