Skip to content

Commit

Permalink
Switch to JUint 5
Browse files Browse the repository at this point in the history
  • Loading branch information
oschwald committed Nov 27, 2023
1 parent 0d64ce3 commit 9b20755
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 49 deletions.
17 changes: 14 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,15 @@
</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>
Expand Down Expand Up @@ -121,6 +127,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
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
62 changes: 38 additions & 24 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 @@ -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

0 comments on commit 9b20755

Please sign in to comment.