From 42f38bb75832b741de399f4857e6f6c026925b0e Mon Sep 17 00:00:00 2001 From: Holt59 Date: Tue, 27 Feb 2018 18:24:28 +0100 Subject: [PATCH] Switch JUnit 5 -> Junit 4. --- .classpath | 2 +- src/test/org/insa/graph/PathTest.java | 68 +++++++------------ .../insa/graph/io/BinaryGraphReaderTest.java | 16 ++--- src/test/org/insa/utility/BinaryHeapTest.java | 14 ++-- 4 files changed, 41 insertions(+), 59 deletions(-) diff --git a/.classpath b/.classpath index e29c93f..b968b3c 100644 --- a/.classpath +++ b/.classpath @@ -17,7 +17,6 @@ - @@ -64,5 +63,6 @@ + diff --git a/src/test/org/insa/graph/PathTest.java b/src/test/org/insa/graph/PathTest.java index 10089b3..e9627d9 100644 --- a/src/test/org/insa/graph/PathTest.java +++ b/src/test/org/insa/graph/PathTest.java @@ -3,16 +3,14 @@ package org.insa.graph; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import org.insa.graph.RoadInformation.RoadType; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.function.Executable; +import org.junit.BeforeClass; +import org.junit.Test; public class PathTest { @@ -29,8 +27,8 @@ public class PathTest { // Some paths... private static Path emptyPath, shortPath, longPath, loopPath, longLoopPath, invalidPath; - @BeforeAll - static void initAll() throws IOException { + @BeforeClass + public static void initAll() throws IOException { // 10 and 20 meters per seconds RoadInformation speed10 = new RoadInformation(RoadType.ROAD, true, 36, ""), @@ -66,7 +64,7 @@ public class PathTest { } @Test - void testConstructor() { + public void testConstructor() { assertEquals(graph, emptyPath.getGraph()); assertEquals(graph, shortPath.getGraph()); assertEquals(graph, longPath.getGraph()); @@ -75,24 +73,13 @@ public class PathTest { assertEquals(graph, invalidPath.getGraph()); } - @Test - void testImmutability() { - assertThrows(UnsupportedOperationException.class, new Executable() { - @Override - public void execute() throws Throwable { - emptyPath.getArcs().add(a2b); - } - }); - assertThrows(UnsupportedOperationException.class, new Executable() { - @Override - public void execute() throws Throwable { - shortPath.getArcs().add(d2e); - } - }); + @Test(expected = UnsupportedOperationException.class) + public void testImmutability() { + emptyPath.getArcs().add(a2b); } @Test - void testIsEmpty() { + public void testIsEmpty() { assertTrue(emptyPath.isEmpty()); assertFalse(shortPath.isEmpty()); @@ -103,7 +90,7 @@ public class PathTest { } @Test - void testIsValid() { + public void testIsValid() { assertTrue(emptyPath.isValid()); assertTrue(shortPath.isValid()); assertTrue(longPath.isValid()); @@ -114,7 +101,7 @@ public class PathTest { } @Test - void testGetLength() { + public void testGetLength() { assertEquals(emptyPath.getLength(), 0); assertEquals(shortPath.getLength(), 40); assertEquals(longPath.getLength(), 60); @@ -123,7 +110,7 @@ public class PathTest { } @Test - void testGetMinimumTravelTime() { + public void testGetMinimumTravelTime() { assertEquals(emptyPath.getMinimumTravelTime(), 0, 1e-4); assertEquals(shortPath.getMinimumTravelTime(), 4, 1e-4); assertEquals(longPath.getMinimumTravelTime(), 5, 1e-4); @@ -132,7 +119,7 @@ public class PathTest { } @Test - void testCreateFastestPathFromNodes() { + public void testCreateFastestPathFromNodes() { Path path; Arc[] expected; @@ -152,18 +139,10 @@ public class PathTest { for (int i = 0; i < expected.length; ++i) { assertEquals(expected[i], path.getArcs().get(i)); } - - // Wrong construction - assertThrows(IllegalArgumentException.class, new Executable() { - @Override - public void execute() throws Throwable { - Path.createFastestPathFromNodes(graph, Arrays.asList(new Node[] { nodes[1], nodes[0] })); - } - }); } @Test - void testCreateShortestPathFromNodes() { + public void testCreateShortestPathFromNodes() { Path path; Arc[] expected; @@ -183,13 +162,16 @@ public class PathTest { for (int i = 0; i < expected.length; ++i) { assertEquals(expected[i], path.getArcs().get(i)); } - - // Wrong construction - assertThrows(IllegalArgumentException.class, new Executable() { - @Override - public void execute() throws Throwable { - Path.createShortestPathFromNodes(graph, Arrays.asList(new Node[] { nodes[1], nodes[0] })); - } - }); } + + @Test(expected = IllegalArgumentException.class) + public void testCreateFastestPathFromNodesException() { + Path.createFastestPathFromNodes(graph, Arrays.asList(new Node[] { nodes[1], nodes[0] })); + } + + @Test(expected = IllegalArgumentException.class) + public void testCreateShortestPathFromNodesException() { + Path.createShortestPathFromNodes(graph, Arrays.asList(new Node[] { nodes[1], nodes[0] })); + } + } diff --git a/src/test/org/insa/graph/io/BinaryGraphReaderTest.java b/src/test/org/insa/graph/io/BinaryGraphReaderTest.java index 12dee09..468a3d7 100644 --- a/src/test/org/insa/graph/io/BinaryGraphReaderTest.java +++ b/src/test/org/insa/graph/io/BinaryGraphReaderTest.java @@ -1,6 +1,6 @@ package org.insa.graph.io; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.Assert.assertEquals; import java.io.BufferedInputStream; import java.io.DataInputStream; @@ -11,8 +11,8 @@ import java.util.List; import org.insa.graph.Graph; import org.insa.graph.Node; import org.insa.graph.Point; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; +import org.junit.BeforeClass; +import org.junit.Test; public class BinaryGraphReaderTest { @@ -21,20 +21,20 @@ public class BinaryGraphReaderTest { private static Graph midip; - @BeforeAll - static void initAll() throws IOException { + @BeforeClass + public static void initAll() throws IOException { BinaryGraphReader reader = new BinaryGraphReader( new DataInputStream(new BufferedInputStream(new FileInputStream("Maps/midip.map")))); midip = reader.read(); } - void assertPointAt(Point p1, double longitude, double latitude) { + public void assertPointAt(Point p1, double longitude, double latitude) { assertEquals(p1.getLongitude(), longitude, EPS); assertEquals(p1.getLatitude(), latitude, EPS); } @Test - void testMidipNodes() { + public void testMidipNodes() { List nodes = midip.getNodes(); assertEquals(nodes.size(), 150827); @@ -49,7 +49,7 @@ public class BinaryGraphReaderTest { } @Test - void testMidipArcs() { + public void testMidipArcs() { // TODO: Check the number of edges. // TODO: Check information for some edges. } diff --git a/src/test/org/insa/utility/BinaryHeapTest.java b/src/test/org/insa/utility/BinaryHeapTest.java index 5a23ce5..a8e38a1 100644 --- a/src/test/org/insa/utility/BinaryHeapTest.java +++ b/src/test/org/insa/utility/BinaryHeapTest.java @@ -1,13 +1,13 @@ package org.insa.utility; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.Arrays; import java.util.stream.IntStream; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.Before; +import org.junit.Test; public class BinaryHeapTest { @@ -16,8 +16,8 @@ public class BinaryHeapTest { private BinaryHeap heap1, heap2; - @BeforeEach - void init() { + @Before + public void init() { // Create the range heap this.heap1 = new BinaryHeap(); this.heap2 = new BinaryHeap(); @@ -29,7 +29,7 @@ public class BinaryHeapTest { } @Test - void testInsert() { + public void testInsert() { BinaryHeap heap = new BinaryHeap(); int size = 0; for (int x: data1) { @@ -50,7 +50,7 @@ public class BinaryHeapTest { } @Test - void testDeleteMin() { + public void testDeleteMin() { // range 1 (sorted) int[] range1 = data1; int size = range1.length;