Switch JUnit 5 -> Junit 4.

This commit is contained in:
Holt59 2018-02-27 18:24:28 +01:00
parent 7de61ac27e
commit 42f38bb758
4 changed files with 41 additions and 59 deletions

View File

@ -17,7 +17,6 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
@ -64,5 +63,6 @@
<attribute name="javadoc_location" value="jar:platform:/resource/be-graphes-reloaded/libs/svg-salamander-1.0-javadoc.jar!/"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@ -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] }));
}
}

View File

@ -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<Node> 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.
}

View File

@ -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<Integer> heap1, heap2;
@BeforeEach
void init() {
@Before
public void init() {
// Create the range heap
this.heap1 = new BinaryHeap<Integer>();
this.heap2 = new BinaryHeap<Integer>();
@ -29,7 +29,7 @@ public class BinaryHeapTest {
}
@Test
void testInsert() {
public void testInsert() {
BinaryHeap<Integer> heap = new BinaryHeap<Integer>();
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;