Skip to content

Commit

Permalink
JUnit 5 Migration (#26)
Browse files Browse the repository at this point in the history
* Use JUnit 5 dependencies

* Replace JUnit 4 API with JUnit 5 API

* Organize dependencies
  • Loading branch information
syoon2 committed Mar 14, 2024
1 parent 775ce99 commit 812618f
Show file tree
Hide file tree
Showing 75 changed files with 598 additions and 556 deletions.
4 changes: 2 additions & 2 deletions jungrapht-layout/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package org.jungrapht.visualization.layout.algorithms;

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

import java.util.stream.IntStream;
import org.jgrapht.Graph;
import org.jgrapht.graph.DefaultGraphType;
import org.jgrapht.graph.builder.GraphTypeBuilder;
import org.jgrapht.util.SupplierUtil;
import org.jungrapht.visualization.layout.model.LayoutModel;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -17,7 +18,7 @@ public class TestTreeLayouts {
private static Logger log = LoggerFactory.getLogger(TestTreeLayouts.class);
Graph<String, Integer> graph;

@Before
@BeforeEach
public void setup() {
graph =
GraphTypeBuilder.<String, Integer>forGraphType(DefaultGraphType.dag())
Expand Down Expand Up @@ -83,11 +84,11 @@ private <V, E> void testEdgeAwareTrees(
layoutAlgorithmOne.visit(layoutModelOne);
layoutAlgorithmTwo.visit(layoutModelTwo);

Assert.assertEquals(layoutAlgorithmOne.getBaseBounds(), layoutAlgorithmTwo.getBaseBounds());
Assert.assertEquals(layoutModelOne.getLocations(), layoutModelTwo.getLocations());
assertEquals(layoutAlgorithmOne.getBaseBounds(), layoutAlgorithmTwo.getBaseBounds());
assertEquals(layoutModelOne.getLocations(), layoutModelTwo.getLocations());

Assert.assertEquals(layoutModelOne.getWidth(), layoutModelTwo.getWidth());
Assert.assertEquals(layoutModelOne.getHeight(), layoutModelTwo.getHeight());
assertEquals(layoutModelOne.getWidth(), layoutModelTwo.getWidth());
assertEquals(layoutModelOne.getHeight(), layoutModelTwo.getHeight());
log.info("treeLayout bounds: {}", layoutAlgorithmOne.getBaseBounds());
log.info("edgeSortingTreeLayoutBounds: {}", layoutAlgorithmTwo.getBaseBounds());
log.info("positions: {}", layoutModelOne.getLocations());
Expand All @@ -104,11 +105,11 @@ private <V> void testTrees(
layoutAlgorithmOne.visit(layoutModelOne);
layoutAlgorithmTwo.visit(layoutModelTwo);

Assert.assertEquals(layoutAlgorithmOne.getBaseBounds(), layoutAlgorithmTwo.getBaseBounds());
Assert.assertEquals(layoutModelOne.getLocations(), layoutModelTwo.getLocations());
assertEquals(layoutAlgorithmOne.getBaseBounds(), layoutAlgorithmTwo.getBaseBounds());
assertEquals(layoutModelOne.getLocations(), layoutModelTwo.getLocations());

Assert.assertEquals(layoutModelOne.getWidth(), layoutModelTwo.getWidth());
Assert.assertEquals(layoutModelOne.getHeight(), layoutModelTwo.getHeight());
assertEquals(layoutModelOne.getWidth(), layoutModelTwo.getWidth());
assertEquals(layoutModelOne.getHeight(), layoutModelTwo.getHeight());
log.info("treeLayout bounds: {}", layoutAlgorithmOne.getBaseBounds());
log.info("edgeSortingTreeLayoutBounds: {}", layoutAlgorithmTwo.getBaseBounds());
log.info("positions: {}", layoutModelOne.getLocations());
Expand Down Expand Up @@ -143,19 +144,14 @@ public void testTreeWithIsolatedVertices() {
private void testPositions(LayoutModel<String> layoutModel) {
// there should be 5 vertices in the top row, all with equal y values
log.info("Positions: {}", layoutModel.getLocations());
Assert.assertEquals(
"Y values should match", layoutModel.get("I1").y, layoutModel.get("I2").y, .1);
Assert.assertEquals(
"Y values should match", layoutModel.get("I2").y, layoutModel.get("L1").y, .1);
Assert.assertEquals(
"Y values should match", layoutModel.get("L1").y, layoutModel.get("L2").y, .1);
Assert.assertEquals(
"Y values should match", layoutModel.get("L2").y, layoutModel.get("R").y, .1);
Assert.assertNotEquals(
"Y values should not match", layoutModel.get("R").y, layoutModel.get("C1").y, .1);
assertEquals(layoutModel.get("I1").y, layoutModel.get("I2").y, .1, "Y values should match");
assertEquals(layoutModel.get("I2").y, layoutModel.get("L1").y, .1, "Y values should match");
assertEquals(layoutModel.get("L1").y, layoutModel.get("L2").y, .1, "Y values should match");
assertEquals(layoutModel.get("L2").y, layoutModel.get("R").y, .1, "Y values should match");
assertNotEquals(
layoutModel.get("R").y, layoutModel.get("C1").y, .1, "Y values should not match");

// there should be one vertex in row 2 with x value the same as "P"
Assert.assertEquals(
"X values should match", layoutModel.get("R").x, layoutModel.get("C1").x, .1);
assertEquals(layoutModel.get("R").x, layoutModel.get("C1").x, .1, "X values should match");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class ThingTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import org.jungrapht.visualization.layout.algorithms.sugiyama.LE;
import org.jungrapht.visualization.layout.algorithms.sugiyama.LV;
import org.jungrapht.visualization.layout.algorithms.sugiyama.TransformedGraphSupplier;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -31,7 +31,7 @@ public class EiglspergerTests {
EiglspergerStepsForward<String, Integer> stepsForward;
EiglspergerStepsBackward<String, Integer> stepsBackward;

@Before
@BeforeEach
public void setup() {
buildGraph();
createLayers();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import org.jungrapht.visualization.layout.algorithms.LayoutAlgorithm;
import org.jungrapht.visualization.layout.model.LayoutModel;
import org.jungrapht.visualization.layout.model.Rectangle;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -76,7 +76,7 @@ private Graph<Integer, Integer> getTwoComponentGraph() {
LayoutModel<Integer> layoutModel;
LayoutAlgorithm<Integer> layoutAlgorithm;

@Before
@BeforeEach
public void setup() {

layoutAlgorithm =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.IntStream;
import org.jungrapht.visualization.layout.algorithms.util.Pair;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.jungrapht.visualization.layout.algorithms.eiglsperger;

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

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
Expand All @@ -14,17 +17,16 @@
import org.jungrapht.visualization.layout.algorithms.sugiyama.LE;
import org.jungrapht.visualization.layout.algorithms.sugiyama.LV;
import org.jungrapht.visualization.layout.algorithms.sugiyama.TransformedGraphSupplier;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class TestSmallGraph {

private Graph<Integer, Integer> graph;
private Graph<LV<Integer>, LE<Integer, Integer>> svGraph;
private NeighborCache<LV<Integer>, LE<Integer, Integer>> neighborCache;

@Before
@BeforeEach
public void setup() {
graph = createInitialGraph();
}
Expand All @@ -40,10 +42,10 @@ public void testEiglsperger() {
Collection<LE<Integer, Integer>> feedbackArcs = greedyCycleRemoval.getFeedbackArcs();

// should be no feedback arcs in this graph
Assert.assertEquals(0, feedbackArcs.size());
assertEquals(0, feedbackArcs.size());

List<List<LV<Integer>>> layers = GraphLayers.assign(svGraph);
Assert.assertEquals(5, layers.size());
assertEquals(5, layers.size());

Synthetics<Integer, Integer> synthetics = new Synthetics<>(svGraph);
List<LE<Integer, Integer>> edges = new ArrayList<>(svGraph.edgeSet());
Expand Down Expand Up @@ -74,10 +76,10 @@ public void testEiglspergerWithGraph() {
Collection<LE<Integer, Integer>> feedbackArcs = greedyCycleRemoval.getFeedbackArcs();

// should be no feedback arcs in this graph
Assert.assertEquals(0, feedbackArcs.size());
assertEquals(0, feedbackArcs.size());

List<List<LV<Integer>>> layers = GraphLayers.assign(svGraph);
Assert.assertEquals(5, layers.size());
assertEquals(5, layers.size());

Synthetics<Integer, Integer> synthetics = new Synthetics<>(svGraph);
List<LE<Integer, Integer>> edges = new ArrayList<>(svGraph.edgeSet());
Expand All @@ -100,37 +102,37 @@ public void testEiglspergerWithGraph() {
}

private void checkLayersArray(LV<Integer>[][] layersArray) {
Assert.assertEquals(5, layersArray.length);
assertEquals(5, layersArray.length);
LV<Integer>[] layer = layersArray[0];
Assert.assertEquals(1, layer.length);
Assert.assertTrue(layer[0] instanceof LV);
Assert.assertEquals(0, (int) layer[0].getVertex());
assertEquals(1, layer.length);
assertInstanceOf(LV.class, layer[0]);
assertEquals(0, layer[0].getVertex());

layer = layersArray[1];
Assert.assertEquals(2, layer.length);
Assert.assertTrue(layer[0] instanceof LV);
Assert.assertEquals(1, (int) layer[0].getVertex());
Assert.assertTrue(layer[1] instanceof PVertex);
assertEquals(2, layer.length);
assertInstanceOf(LV.class, layer[0]);
assertEquals(1, layer[0].getVertex());
assertInstanceOf(PVertex.class, layer[1]);

layer = layersArray[2];
Assert.assertEquals(3, layer.length);
Assert.assertTrue(layer[0] instanceof LV);
Assert.assertEquals(2, (int) layer[0].getVertex());
Assert.assertTrue(layer[1] instanceof SyntheticLV);
Assert.assertTrue(layer[2] instanceof PVertex);
assertEquals(3, layer.length);
assertInstanceOf(LV.class, layer[0]);
assertEquals(2, layer[0].getVertex());
assertInstanceOf(SyntheticLV.class, layer[1]);
assertInstanceOf(PVertex.class, layer[2]);

layer = layersArray[3];
Assert.assertEquals(4, layer.length);
Assert.assertTrue(layer[0] instanceof LV);
Assert.assertEquals(3, (int) layer[0].getVertex());
Assert.assertTrue(layer[1] instanceof QVertex);
Assert.assertTrue(layer[2] instanceof QVertex);
Assert.assertTrue(layer[3] instanceof SyntheticLV);
assertEquals(4, layer.length);
assertInstanceOf(LV.class, layer[0]);
assertEquals(3, layer[0].getVertex());
assertInstanceOf(QVertex.class, layer[1]);
assertInstanceOf(QVertex.class, layer[2]);
assertInstanceOf(SyntheticLV.class, layer[3]);

layer = layersArray[4];
Assert.assertEquals(1, layer.length);
Assert.assertTrue(layer[0] instanceof LV);
Assert.assertEquals(4, (int) layer[0].getVertex());
assertEquals(1, layer.length);
assertInstanceOf(LV.class, layer[0]);
assertEquals(4, layer[0].getVertex());
}

private Graph<Integer, Integer> createInitialGraph() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package org.jungrapht.visualization.layout.algorithms.sugiyama;

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

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.jungrapht.visualization.layout.algorithms.util.InsertionSortCounter;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -73,7 +74,7 @@ public void runTest() {
Collections.shuffle(edges);
log.info("shuffled edges: {}", edges);
int count = crossingCount(edges);
Assert.assertEquals(12, count);
assertEquals(12, count);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.jungrapht.visualization.layout.algorithms.sugiyama;

import java.util.Arrays;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package org.jungrapht.visualization.layout.algorithms.sugiyama;

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

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.jungrapht.visualization.layout.algorithms.util.InsertionSortCounter;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -73,7 +74,7 @@ public void runTest() {
Collections.shuffle(edges);
log.info("shuffled edges: {}", edges);
int count = crossingCount(edges);
Assert.assertEquals(12, count);
assertEquals(12, count);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package org.jungrapht.visualization.layout.algorithms.sugiyama;

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

import java.util.HashSet;
import java.util.stream.IntStream;
import org.jgrapht.Graph;
import org.jgrapht.graph.builder.GraphTypeBuilder;
import org.jgrapht.util.SupplierUtil;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -85,7 +86,7 @@ void createDelegateGraph() {
svGraph = new TransformedGraphSupplier<>(graph).get();
}

@Before
@BeforeEach
public void setup() {
createInitialGraph();
}
Expand All @@ -95,17 +96,17 @@ public void makeBrandesKopf() {
BrandesKopf brandesKopf = new BrandesKopf(graph);
svGraph = brandesKopf.svGraph;
LV<Integer>[][] layers = brandesKopf.layersArray;
Assert.assertEquals(10, layers.length);
Assert.assertEquals(2, layers[0].length);
Assert.assertEquals(5, layers[1].length);
Assert.assertEquals(6, layers[2].length);
Assert.assertEquals(6, layers[3].length);
Assert.assertEquals(8, layers[4].length);
Assert.assertEquals(9, layers[5].length);
Assert.assertEquals(9, layers[6].length);
Assert.assertEquals(7, layers[7].length);
Assert.assertEquals(4, layers[8].length);
Assert.assertEquals(1, layers[9].length);
assertEquals(10, layers.length);
assertEquals(2, layers[0].length);
assertEquals(5, layers[1].length);
assertEquals(6, layers[2].length);
assertEquals(6, layers[3].length);
assertEquals(8, layers[4].length);
assertEquals(9, layers[5].length);
assertEquals(9, layers[6].length);
assertEquals(7, layers[7].length);
assertEquals(4, layers[8].length);
assertEquals(1, layers[9].length);

HorizontalCoordinateAssignment<Integer, Integer> horizontalCoordinateAssignment =
new HorizontalCoordinateAssignment<>(layers, svGraph, new HashSet<>(), 20, 20);
Expand Down
Loading

0 comments on commit 812618f

Please sign in to comment.