Skip to content

Commit

Permalink
chore: upgrade junit4 to junit5
Browse files Browse the repository at this point in the history
Import statement was changed.
Also the way of handling exception was also updated
  • Loading branch information
puthusseri authored and davidmoten committed Nov 7, 2024
1 parent 11c8fb2 commit 5c4f654
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 69 deletions.
6 changes: 3 additions & 3 deletions geo-mem/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
</dependency>
<!-- Test Dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.11.3</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package com.github.davidmoten.geo.mem;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.List;
import java.util.UUID;

import org.junit.Test;

import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.google.common.collect.Lists;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

public class GeomemTest {

Expand Down Expand Up @@ -118,7 +114,7 @@ public void testGeomemFindWhenOneEntryOutsideRegion() {
/**
* Indicates 4.5MB per 1000 records. Thus one million entries needs 4500
* entries.
*
*
* @throws InterruptedException
*/
@Test
Expand Down
6 changes: 3 additions & 3 deletions geo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.11.3</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
9 changes: 5 additions & 4 deletions geo/src/test/java/com/github/davidmoten/geo/Base32Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import static com.github.davidmoten.geo.Base32.decodeBase32;
import static com.github.davidmoten.geo.Base32.encodeBase32;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import org.junit.Test;

import org.junit.jupiter.api.Test;
/**
* Unit tests for {@link Base32}.
*
Expand Down Expand Up @@ -66,9 +67,9 @@ public void testEncodePadsToLength12() {
assertEquals("00000000003v", encodeBase32(123));
}

@Test(expected = IllegalArgumentException.class)
@Test
public void testGetCharIndexThrowsExceptionWhenNonBase32CharacterGiven() {
Base32.getCharIndex('?');
assertThrows(IllegalArgumentException.class, () -> Base32.getCharIndex('?'));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.github.davidmoten.geo;

import static org.junit.Assert.assertEquals;

import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;

/**
* Unit tests for {@link CoverageLongs}.
Expand Down
9 changes: 4 additions & 5 deletions geo/src/test/java/com/github/davidmoten/geo/CoverageTest.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.github.davidmoten.geo;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import org.junit.Test;

import com.google.common.collect.Sets;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* Unit tests for {@link Coverage}.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.github.davidmoten.geo;

import static org.junit.Assert.assertEquals;
import org.junit.jupiter.api.Test;

import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* Unit tests for {@link Direction}.
Expand Down
60 changes: 29 additions & 31 deletions geo/src/test/java/com/github/davidmoten/geo/GeoHashTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,16 @@
import static com.github.davidmoten.geo.GeoHash.right;
import static com.github.davidmoten.geo.GeoHash.top;
import static com.github.davidmoten.geo.GeoHash.widthDegrees;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.*;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

import org.junit.Test;

import com.google.common.collect.Sets;
import org.junit.jupiter.api.Test;

/**
* Unit tests for {@link GeoHash}.
Expand Down Expand Up @@ -62,14 +58,14 @@ public void encodeHashToLong() {
assertEquals(0x65c0000000000002L, GeoHash.encodeHashToLong(41.842967, -72.727175, 2));
}

@Test(expected = IllegalArgumentException.class)
@Test
public void fromLongToStringInvalid() {
GeoHash.fromLongToString(0xff);
assertThrows(IllegalArgumentException.class, () -> GeoHash.fromLongToString(0xff));
}

@Test(expected = IllegalArgumentException.class)
@Test
public void fromLongToStringZero() {
GeoHash.fromLongToString(0);
assertThrows(IllegalArgumentException.class, () -> GeoHash.fromLongToString(0));
}

@Test
Expand Down Expand Up @@ -100,50 +96,50 @@ public void testFromGeoHashDotOrg() {
public void testHashOfNonDefaultLength() {
assertEquals("6gkzwg", encodeHash(-25.382708, -49.265506, 6));
}

@Test
public void testHashOfLength12() {
assertEquals("6gkzwgjzn820", encodeHash(-25.382708, -49.265506, 12));
}

@Test(expected = IllegalArgumentException.class)
@Test
public void testHashOfLength13() {
encodeHash(-25.382708, -49.265506, 13);
assertThrows(IllegalArgumentException.class, () -> encodeHash(-25.382708, -49.265506, 13));
}

@Test(expected = IllegalArgumentException.class)
@Test
public void testHashOfLength20() {
encodeHash(-25.382708, -49.265506, 20);
assertThrows(IllegalArgumentException.class, () -> encodeHash(-25.382708, -49.265506, 20));
}

@Test(expected = IllegalArgumentException.class)
@Test
public void testHashEncodeGivenNonPositiveLength() {
encodeHash(-25.382708, -49.265506, 0);
assertThrows(IllegalArgumentException.class, () -> encodeHash(-25.382708, -49.265506, 0));
}

@Test
public void testAnother() {
assertEquals("sew1c2vs2q5r", encodeHash(20, 31));
}

@Test(expected = IllegalArgumentException.class)
@Test
public void testEncodeHashWithLatTooBig() {
encodeHash(1000, 100, 4);
assertThrows(IllegalArgumentException.class, () -> encodeHash(1000, 100, 4));
}

@Test(expected = IllegalArgumentException.class)
@Test
public void testEncodeHashWithLatTooSmall() {
encodeHash(-1000, 100, 4);
assertThrows(IllegalArgumentException.class, () -> encodeHash(-1000, 100, 4));
}

@Test(expected = IllegalArgumentException.class)
@Test
public void testAdjacentHashThrowsExceptionGivenNullHash() {
GeoHash.adjacentHash(null, Direction.RIGHT);
assertThrows(IllegalArgumentException.class, () -> GeoHash.adjacentHash(null, Direction.RIGHT));
}

@Test(expected = IllegalArgumentException.class)
@Test
public void testAdjacentHashThrowsExceptionGivenBlankHash() {
GeoHash.adjacentHash("", Direction.RIGHT);
assertThrows(IllegalArgumentException.class, () -> GeoHash.adjacentHash("", Direction.RIGHT));
}

@Test
Expand Down Expand Up @@ -404,10 +400,12 @@ public void testCoverBoundingBoxWithHashLength3AroundBoston() {
assertEquals(Sets.newHashSet("dr7", "dre", "drk", "drs"), hashes);
}

@Test(expected = IllegalArgumentException.class)
@Test
public void testCoverBoundingBoxWithZeroLengthThrowsException() {
coverBoundingBox(SCHENECTADY_LAT, SCHENECTADY_LON, HARTFORD_LAT,
HARTFORD_LON, 0);
assertThrows(IllegalArgumentException.class, () ->
coverBoundingBox(SCHENECTADY_LAT, SCHENECTADY_LON, HARTFORD_LAT,
HARTFORD_LON, 0)
);
}

@Test
Expand Down Expand Up @@ -612,10 +610,10 @@ public void testNeighboursAtLongitudeMinus180() {
assertEquals("2pbpbpbpbpbr", neighbors.get(I_RIGHT_BOT));
}

@Test(expected=IllegalArgumentException.class)

@Test
public void testCoverBoundingBoxPreconditionLat() {
GeoHash.coverBoundingBox(0, 100, 10, 120);
assertThrows(IllegalArgumentException.class, () -> GeoHash.coverBoundingBox(0, 100, 10, 120));
}

}
4 changes: 2 additions & 2 deletions geo/src/test/java/com/github/davidmoten/geo/LatLongTest.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.github.davidmoten.geo;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* Unit tests for {@link LatLong}.
Expand Down
6 changes: 3 additions & 3 deletions geo/src/test/java/com/github/davidmoten/geo/TestingUtil.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.github.davidmoten.geo;

import static org.junit.Assert.assertTrue;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;

import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* Utility methods for unit tests.
*
Expand All @@ -17,7 +18,7 @@ public class TestingUtil {
/**
* Checks that a class has a no-argument private constructor and calls that
* constructor to instantiate the class.
*
*
* @param cls
*/
public static <T> void callConstructorAndCheckIsPrivate(Class<T> cls) {
Expand All @@ -43,5 +44,4 @@ public static <T> void callConstructorAndCheckIsPrivate(Class<T> cls) {
throw new RuntimeException(e);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.junit.Test;

import com.github.davidmoten.geo.Coverage;
import com.github.davidmoten.geo.GeoHash;
import com.google.common.collect.Lists;
import org.junit.jupiter.api.Test;

/**
* Displays benchmarks using geohashing with an H2 database.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.github.davidmoten.geo.util;

import org.junit.Test;

import com.github.davidmoten.geo.TestingUtil;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertThrows;

public class PreconditionsTest {

Expand All @@ -11,9 +12,9 @@ public void getCoverageOfConstructorAndCheckConstructorIsPrivate() {
TestingUtil.callConstructorAndCheckIsPrivate(Preconditions.class);
}

@Test(expected = NullPointerException.class)
@Test
public void testCheckNotNullGivenNullThrowsException() {
Preconditions.checkNotNull(null, "message");
assertThrows(NullPointerException.class, () -> Preconditions.checkNotNull(null, "message"));
}

}

0 comments on commit 5c4f654

Please sign in to comment.