Skip to content

Commit

Permalink
migrate all tests to junit jupiter
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy2003 committed May 29, 2024
1 parent b8941e3 commit 2aa6816
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 106 deletions.
8 changes: 1 addition & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<version>3.13.0</version>
<configuration>
<source>${neo4j.java.version}</source>
<target>${neo4j.java.version}</target>
Expand Down Expand Up @@ -304,12 +304,6 @@
</dependency>

<!-- The JUnit-Hamcrest-Mockito combo -->
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/org/neo4j/gis/spatial/LayersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME;

import java.io.File;
Expand Down Expand Up @@ -274,12 +274,12 @@ private String testSpecificEditableLayer(String layerName, Class<? extends Geome
inTx(tx -> {
Layer layer = spatial.createLayer(tx, layerName, geometryEncoderClass, layerClass);
assertNotNull(layer);
assertTrue(layer instanceof EditableLayer, "Should be an editable layer");
assertInstanceOf(EditableLayer.class, layer, "Should be an editable layer");
});
inTx(tx -> {
Layer layer = spatial.getLayer(tx, layerName);
assertNotNull(layer);
assertTrue(layer instanceof EditableLayer, "Should be an editable layer");
assertInstanceOf(EditableLayer.class, layer, "Should be an editable layer");
EditableLayer editableLayer = (EditableLayer) layer;

CoordinateList coordinates = new CoordinateList();
Expand Down Expand Up @@ -388,7 +388,7 @@ public void testIndexAccessAfterBulkInsertion() {
Result result = tx.execute(cypher);
// System.out.println(result.columns().toString());
Object obj = result.columnAs("count(p)").next();
assertTrue(obj instanceof Long);
assertInstanceOf(Long.class, obj);
assertEquals(1000L, (long) ((Long) obj));
tx.commit();
}
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/org/neo4j/gis/spatial/Neo4jTestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
*/
package org.neo4j.gis.spatial;

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

import java.io.File;
import java.util.ArrayList;
Expand Down Expand Up @@ -117,7 +117,7 @@ public static void printTree(Node root, int depth) {

public static <T> void assertCollection(Collection<T> collection, T... expectedItems) {
String collectionString = join(", ", collection.toArray());
assertEquals(collectionString, expectedItems.length, collection.size());
assertEquals(expectedItems.length, collection.size(), collectionString);
for (T item : expectedItems) {
assertTrue(collection.contains(item));
}
Expand Down
93 changes: 48 additions & 45 deletions src/test/java/org/neo4j/gis/spatial/RTreeBulkInsertTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.lessThan;
import static org.hamcrest.Matchers.lessThanOrEqualTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME;
import static org.neo4j.gis.spatial.rtree.RTreeIndex.DEFAULT_MAX_NODE_REFERENCES;
import static org.neo4j.internal.helpers.collection.MapUtil.map;
Expand All @@ -49,11 +50,11 @@
import org.geotools.api.referencing.crs.CoordinateReferenceSystem;
import org.geotools.data.neo4j.Neo4jFeatureBuilder;
import org.geotools.referencing.crs.DefaultEngineeringCRS;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.Geometry;
import org.neo4j.dbms.api.DatabaseManagementService;
Expand Down Expand Up @@ -94,17 +95,17 @@ public class RTreeBulkInsertTest {
// While the current lucene index implmentation is so slow (16n/s) we disable all benchmarks for lucene backed indexes
private static final boolean enableLucene = false;

@Before
@BeforeEach
public void before() throws IOException {
restart();
}

@After
@AfterEach
public void after() throws IOException {
doCleanShutdown();
}

@Ignore
@Disabled
public void shouldDeleteRecursiveTree() {
int depth = 5;
int width = 2;
Expand Down Expand Up @@ -185,7 +186,7 @@ private EditableLayer getOrCreateSimplePointLayer(String name, String index, Str
}
}

@Ignore
@Disabled
public void shouldInsertSimpleRTree() {
int width = 20;
int blockSize = 10000;
Expand Down Expand Up @@ -603,12 +604,12 @@ public void shouldInsertManyNodesInBulkWithHilbert_small() throws FactoryExcepti
insertManyNodesInBulk(new HilbertIndexMaker("Coordinates", "Bulk", testConfigs.get("small")), 5000);
}

@Ignore // takes too long, change to @Test when benchmarking
@Disabled // takes too long, change to @Test when benchmarking
public void shouldInsertManyNodesIndividuallyWithQuadraticSplit_small_10() throws FactoryException, IOException {
insertManyNodesIndividually(RTreeIndex.QUADRATIC_SPLIT, 5000, 10, testConfigs.get("small"));
}

@Ignore // takes too long, change to @Test when benchmarking
@Disabled // takes too long, change to @Test when benchmarking
public void shouldInsertManyNodesIndividuallyGreenesSplit_small_10() throws FactoryException, IOException {
insertManyNodesIndividually(RTreeIndex.GREENES_SPLIT, 5000, 10, testConfigs.get("small"));
}
Expand All @@ -627,12 +628,12 @@ public void shouldInsertManyNodesInBulkWithGreenesSplit_small_10() throws Factor
* Small model 250*250 nodes (shallow tree)
*/

@Ignore // takes too long, change to @Test when benchmarking
@Disabled // takes too long, change to @Test when benchmarking
public void shouldInsertManyNodesIndividuallyWithQuadraticSplit_small_100() throws FactoryException, IOException {
insertManyNodesIndividually(RTreeIndex.QUADRATIC_SPLIT, 5000, 100, testConfigs.get("small"));
}

@Ignore // takes too long, change to @Test when benchmarking
@Disabled // takes too long, change to @Test when benchmarking
public void shouldInsertManyNodesIndividuallyGreenesSplit_small_100() throws FactoryException, IOException {
insertManyNodesIndividually(RTreeIndex.GREENES_SPLIT, 5000, 100, testConfigs.get("small"));
}
Expand Down Expand Up @@ -681,12 +682,12 @@ public void shouldInsertManyNodesInBulkWithHilbert_medium() throws FactoryExcept
insertManyNodesInBulk(new HilbertIndexMaker("Coordinates", "Bulk", testConfigs.get("medium")), 5000);
}

@Ignore
@Disabled
public void shouldInsertManyNodesIndividuallyWithQuadraticSplit_medium_10() throws FactoryException, IOException {
insertManyNodesIndividually(RTreeIndex.QUADRATIC_SPLIT, 5000, 10, testConfigs.get("medium"));
}

@Ignore
@Disabled
public void shouldInsertManyNodesIndividuallyGreenesSplit_medium_10() throws FactoryException, IOException {
insertManyNodesIndividually(RTreeIndex.GREENES_SPLIT, 5000, 10, testConfigs.get("medium"));
}
Expand All @@ -701,12 +702,12 @@ public void shouldInsertManyNodesInBulkWithGreenesSplit_medium_10() throws Facto
insertManyNodesInBulk(RTreeIndex.GREENES_SPLIT, 5000, 10, testConfigs.get("medium"));
}

@Ignore
@Disabled
public void shouldInsertManyNodesInBulkWithQuadraticSplit_medium_10_merge() throws FactoryException, IOException {
insertManyNodesInBulk(RTreeIndex.QUADRATIC_SPLIT, 5000, 10, testConfigs.get("medium"), true);
}

@Ignore
@Disabled
public void shouldInsertManyNodesInBulkWithGreenesSplit_medium_10_merge() throws FactoryException, IOException {
insertManyNodesInBulk(RTreeIndex.GREENES_SPLIT, 5000, 10, testConfigs.get("medium"), true);
}
Expand All @@ -715,17 +716,17 @@ public void shouldInsertManyNodesInBulkWithGreenesSplit_medium_10_merge() throws
* Medium model 500*500 nodes (shallow tree - factor 100)
*/

@Ignore
@Disabled
public void shouldInsertManyNodesIndividuallyWithQuadraticSplit_medium_100() throws FactoryException, IOException {
insertManyNodesIndividually(RTreeIndex.QUADRATIC_SPLIT, 5000, 100, testConfigs.get("medium"));
}

@Ignore
@Disabled
public void shouldInsertManyNodesIndividuallyGreenesSplit_medium_100() throws FactoryException, IOException {
insertManyNodesIndividually(RTreeIndex.GREENES_SPLIT, 5000, 100, testConfigs.get("medium"));
}

@Ignore // takes too long, change to @Test when benchmarking
@Disabled // takes too long, change to @Test when benchmarking
public void shouldInsertManyNodesInBulkWithQuadraticSplit_medium_100() throws FactoryException, IOException {
insertManyNodesInBulk(RTreeIndex.QUADRATIC_SPLIT, 5000, 100, testConfigs.get("medium"));
}
Expand All @@ -735,12 +736,12 @@ public void shouldInsertManyNodesInBulkWithGreenesSplit_medium_100() throws Fact
insertManyNodesInBulk(RTreeIndex.GREENES_SPLIT, 5000, 100, testConfigs.get("medium"));
}

@Ignore
@Disabled
public void shouldInsertManyNodesInBulkWithQuadraticSplit_medium_100_merge() throws FactoryException, IOException {
insertManyNodesInBulk(RTreeIndex.QUADRATIC_SPLIT, 5000, 100, testConfigs.get("medium"), true);
}

@Ignore
@Disabled
public void shouldInsertManyNodesInBulkWithGreenesSplit_medium_100_merge() throws FactoryException, IOException {
insertManyNodesInBulk(RTreeIndex.GREENES_SPLIT, 5000, 100, testConfigs.get("medium"), true);
}
Expand Down Expand Up @@ -779,22 +780,22 @@ public void shouldInsertManyNodesInBulkWithHilbert_large() throws FactoryExcepti
insertManyNodesInBulk(new HilbertIndexMaker("Coordinates", "Bulk", testConfigs.get("large")), 5000);
}

@Ignore // takes too long, change to @Test when benchmarking
@Disabled // takes too long, change to @Test when benchmarking
public void shouldInsertManyNodesInBulkWithQuadraticSplit_large_10() throws FactoryException, IOException {
insertManyNodesInBulk(RTreeIndex.QUADRATIC_SPLIT, 5000, 10, testConfigs.get("large"));
}

@Ignore // takes too long, change to @Test when benchmarking
@Disabled // takes too long, change to @Test when benchmarking
public void shouldInsertManyNodesInBulkWithGreenesSplit_large_10() throws FactoryException, IOException {
insertManyNodesInBulk(RTreeIndex.GREENES_SPLIT, 5000, 10, testConfigs.get("large"));
}

@Ignore // takes too long, change to @Test when benchmarking
@Disabled // takes too long, change to @Test when benchmarking
public void shouldInsertManyNodesInBulkWithQuadraticSplit_large_100() throws FactoryException, IOException {
insertManyNodesInBulk(RTreeIndex.QUADRATIC_SPLIT, 5000, 100, testConfigs.get("large"));
}

@Ignore // takes too long, change to @Test when benchmarking
@Disabled // takes too long, change to @Test when benchmarking
public void shouldInsertManyNodesInBulkWithGreenesSplit_large_100() throws FactoryException, IOException {
insertManyNodesInBulk(RTreeIndex.GREENES_SPLIT, 5000, 100, testConfigs.get("large"));
}
Expand Down Expand Up @@ -916,7 +917,7 @@ private void insertManyNodesIndividually(IndexMaker indexMaker, int blockSize) {
* Run this manually to generate images of RTree that can be used for animation.
* ffmpeg -f image2 -r 12 -i rtree-single/rtree-%d.png -r 12 -s 1280x960 rtree-single2_12fps.mp4
*/
@Ignore
@Disabled
public void shouldInsertManyNodesIndividuallyAndGenerateImagesForAnimation() throws FactoryException, IOException {
IndexTestConfig config = testConfigs.get("medium");
int blockSize = 5;
Expand Down Expand Up @@ -1029,7 +1030,7 @@ private void insertManyNodesInBulk(IndexMaker indexMaker, int blockSize) {
* Run this manually to generate images of RTree that can be used for animation.
* ffmpeg -f image2 -r 12 -i rtree-single/rtree-%d.png -r 12 -s 1280x960 rtree-single2_12fps.mp4
*/
@Ignore
@Disabled
public void shouldInsertManyNodesInBulkAndGenerateImagesForAnimation() throws FactoryException, IOException {
IndexTestConfig config = testConfigs.get("medium");
int blockSize = 1000;
Expand Down Expand Up @@ -1085,7 +1086,7 @@ public void shouldInsertManyNodesInBulkAndGenerateImagesForAnimation() throws Fa
// debugIndexTree((RTreeIndex) layer.getIndex());
}

@Ignore
@Disabled
public void shouldAccessIndexAfterBulkInsertion() throws Exception {
// Use these two lines if you want to examine the output.
// File dbPath = new File("target/var/BulkTest");
Expand Down Expand Up @@ -1137,7 +1138,7 @@ public void shouldAccessIndexAfterBulkInsertion() throws Exception {
Result result = tx.execute(cypher);
// System.out.println(result.columns().toString());
Object obj = result.columnAs("count").next();
assertTrue(obj instanceof Long);
assertInstanceOf(Long.class, obj);
assertEquals((long) ((Long) obj), numNodes);
tx.commit();
}
Expand All @@ -1152,14 +1153,14 @@ public void shouldAccessIndexAfterBulkInsertion() throws Exception {
Result result = tx.execute(cypher);
// System.out.println(result.columns().toString());
Object obj = result.columnAs("count").next();
assertTrue(obj instanceof Long);
assertInstanceOf(Long.class, obj);
assertEquals((long) ((Long) obj), numNodes);
tx.commit();
}
System.out.println("\t" + (System.currentTimeMillis() - start) + "ms");
}

@Ignore
@Disabled
public void shouldBuildTreeFromScratch() throws Exception {
//GraphDatabaseService db = this.databases.database("BultTest2");
GraphDatabaseService db = this.db;
Expand Down Expand Up @@ -1215,7 +1216,7 @@ public void shouldBuildTreeFromScratch() throws Exception {
}
}

@Ignore
@Disabled
public void shouldPerformRTreeBulkInsertion() throws Exception {
// Use this line if you want to examine the output.
//GraphDatabaseService db = databases.database("BulkTest");
Expand Down Expand Up @@ -1492,8 +1493,8 @@ private List<Node> queryIndex(Layer layer, TestStats stats) {
stats.put("Indexed", geometrySize);
System.out.println("Index contains " + geometrySize + " geometries");
}
assertEquals("Expected " + config.expectedGeometries + " nodes to be returned", config.expectedGeometries,
countGeometries);
assertEquals(config.expectedGeometries, countGeometries,
"Expected " + config.expectedGeometries + " nodes to be returned");
return nodes;
}

Expand Down Expand Up @@ -1529,7 +1530,8 @@ private void getRTreeIndexStats(RTreeIndex index, TreeMonitor monitor, TestStats
// unless the polygon is a rectangle, in which case they are not contained, leading to
// different numbers for expectedGeometries and expectedCount.
// See https://github.com/locationtech/jts/blob/master/modules/core/src/main/java/org/locationtech/jts/operation/predicate/RectangleContains.java#L70
assertEquals("Expected " + config.expectedCount + " nodes to be matched", config.expectedCount, matched);
assertEquals(config.expectedCount, matched,
"Expected " + config.expectedCount + " nodes to be matched");
int maxNodeReferences = stats.maxNodeReferences;
int maxExpectedGeometriesTouched = matched * maxNodeReferences;
if (countGeometries > 1 && assertTouches) {
Expand All @@ -1555,7 +1557,8 @@ private void getExplicitIndexBackedIndexStats(ExplicitIndexBackedPointIndex inde
// unless the polygon is a rectangle, in which case they are not contained, leading to
// different numbers for expectedGeometries and expectedCount.
// See https://github.com/locationtech/jts/blob/master/modules/core/src/main/java/org/locationtech/jts/operation/predicate/RectangleContains.java#L70
assertEquals("Expected " + config.expectedCount + " nodes to be matched", config.expectedCount, matched);
assertEquals(config.expectedCount, matched,
"Expected " + config.expectedCount + " nodes to be matched");
}

private class TimedLogger {
Expand Down Expand Up @@ -1599,17 +1602,17 @@ private void log(String line, long number) {

private void verifyGeohashIndex(Layer layer) {
LayerIndexReader index = layer.getIndex();
assertTrue("Index should be a geohash index", index instanceof LayerGeohashPointIndex);
assertInstanceOf(LayerGeohashPointIndex.class, index, "Index should be a geohash index");
}

private void verifyHilbertIndex(Layer layer) {
LayerIndexReader index = layer.getIndex();
assertTrue("Index should be a hilbert index", index instanceof LayerHilbertPointIndex);
assertInstanceOf(LayerHilbertPointIndex.class, index, "Index should be a hilbert index");
}

private void verifyZOrderIndex(Layer layer) {
LayerIndexReader index = layer.getIndex();
assertTrue("Index should be a Z-Order index", index instanceof LayerZOrderPointIndex);
assertInstanceOf(LayerZOrderPointIndex.class, index, "Index should be a Z-Order index");
}

private void verifyTreeStructure(Layer layer, String splitMode, TestStats stats) {
Expand Down Expand Up @@ -1650,7 +1653,7 @@ private void verifyTreeStructure(Layer layer, String splitMode, TestStats stats)
System.out.println("Tree depth to all geometries: " + depthMap);
}
}
assertEquals("All geometries should be at the same depth", 1, balanced);
assertEquals(1, balanced, "All geometries should be at the same depth");
Map<String, Object> leafMap;
try (Transaction tx = db.beginTx()) {
Result resultNumChildren = tx.execute(queryNumChildren, params);
Expand Down Expand Up @@ -1803,7 +1806,7 @@ public String toString() {

private static final LinkedHashSet<TestStats> allStats = new LinkedHashSet<>();

@AfterClass
@AfterAll
public static void afterClass() {
System.out.println("\n\nComposite stats for " + allStats.size() + " tests run");
System.out.println(TestStats.headerString());
Expand Down
Loading

0 comments on commit 2aa6816

Please sign in to comment.