Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to JUnit 5 #140

Merged
merged 3 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dev-bin/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 34 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,40 @@
</developers>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.10.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>java-hamcrest</artifactId>
<version>2.0.0.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.4.1</version>
<executions>
<execution>
<id>enforce-maven</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>3.2.5</version>
</requireMavenVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
Expand Down Expand Up @@ -121,6 +147,11 @@
<target>11</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.2</version>
</plugin>
<plugin>
<groupId>org.eluder.coveralls</groupId>
<artifactId>coveralls-maven-plugin</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/maxmind/db/Networks.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public DatabaseRecord<T> next() {
prefixLength -= 96;
}

return new DatabaseRecord<T>(data, ipAddr, prefixLength);
return new DatabaseRecord<>(data, ipAddr, prefixLength);
} catch (IOException e) {
throw new NetworksIterationException(e);
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/maxmind/db/Reader.java
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,9 @@ public <T> Networks<T> networksWithin(
int node = traverseResult[0];
int prefix = traverseResult[1];

return new Networks<T>(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);
}

/**
Expand Down
32 changes: 16 additions & 16 deletions src/test/java/com/maxmind/db/DecoderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -434,42 +434,42 @@ private static <T> void testTypeDecoding(Type type, Map<T, byte[]> 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);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/maxmind/db/MultiThreadedTest.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {

Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/maxmind/db/NetworkTest.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/maxmind/db/PointerTest.java
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
66 changes: 40 additions & 26 deletions src/test/java/com/maxmind/db/ReaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -339,7 +341,7 @@ public void testNetworksWithin() throws IOException, InvalidNetworkException{
boolean includeAliasedNetworks = !test.skipAliasedNetworks;
Networks networks = reader.networksWithin(network, includeAliasedNetworks, Map.class);

ArrayList<String> innerIPs = new ArrayList<String>();
ArrayList<String> innerIPs = new ArrayList<>();
while(networks.hasNext()){
DatabaseRecord<Map<String,String>> iteration = networks.next();
innerIPs.add(iteration.getNetwork().toString());
Expand Down Expand Up @@ -376,7 +378,7 @@ public void testGeoIPNetworksWithin() throws IOException, InvalidNetworkExceptio

Networks networks = reader.networksWithin(network, test.skipAliasedNetworks, Map.class);

ArrayList<String> innerIPs = new ArrayList<String>();
ArrayList<String> innerIPs = new ArrayList<>();
while(networks.hasNext()){
DatabaseRecord<Map<String,String>> iteration = networks.next();
innerIPs.add(iteration.getNetwork().toString());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -1237,8 +1239,11 @@ private void testIpV4(Reader reader, File file) throws IOException {
Map<String, String> 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<String, String> pairs = new HashMap<>();
Expand All @@ -1253,8 +1258,11 @@ private void testIpV4(Reader reader, File file) throws IOException {
Map<String, String> 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"}) {
Expand All @@ -1271,8 +1279,11 @@ private void testIpV6(Reader reader, File file) throws IOException {
Map<String, String> 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<String, String> pairs = new HashMap<>();
Expand All @@ -1289,8 +1300,11 @@ private void testIpV6(Reader reader, File file) throws IOException {
Map<String, String> 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::"}) {
Expand Down
Loading