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

View File

@ -3,16 +3,14 @@ package org.insa.graph;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import org.insa.graph.RoadInformation.RoadType; import org.insa.graph.RoadInformation.RoadType;
import org.junit.jupiter.api.BeforeAll; import org.junit.BeforeClass;
import org.junit.jupiter.api.Test; import org.junit.Test;
import org.junit.jupiter.api.function.Executable;
public class PathTest { public class PathTest {
@ -29,8 +27,8 @@ public class PathTest {
// Some paths... // Some paths...
private static Path emptyPath, shortPath, longPath, loopPath, longLoopPath, invalidPath; private static Path emptyPath, shortPath, longPath, loopPath, longLoopPath, invalidPath;
@BeforeAll @BeforeClass
static void initAll() throws IOException { public static void initAll() throws IOException {
// 10 and 20 meters per seconds // 10 and 20 meters per seconds
RoadInformation speed10 = new RoadInformation(RoadType.ROAD, true, 36, ""), RoadInformation speed10 = new RoadInformation(RoadType.ROAD, true, 36, ""),
@ -66,7 +64,7 @@ public class PathTest {
} }
@Test @Test
void testConstructor() { public void testConstructor() {
assertEquals(graph, emptyPath.getGraph()); assertEquals(graph, emptyPath.getGraph());
assertEquals(graph, shortPath.getGraph()); assertEquals(graph, shortPath.getGraph());
assertEquals(graph, longPath.getGraph()); assertEquals(graph, longPath.getGraph());
@ -75,24 +73,13 @@ public class PathTest {
assertEquals(graph, invalidPath.getGraph()); assertEquals(graph, invalidPath.getGraph());
} }
@Test @Test(expected = UnsupportedOperationException.class)
void testImmutability() { public void testImmutability() {
assertThrows(UnsupportedOperationException.class, new Executable() { emptyPath.getArcs().add(a2b);
@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 @Test
void testIsEmpty() { public void testIsEmpty() {
assertTrue(emptyPath.isEmpty()); assertTrue(emptyPath.isEmpty());
assertFalse(shortPath.isEmpty()); assertFalse(shortPath.isEmpty());
@ -103,7 +90,7 @@ public class PathTest {
} }
@Test @Test
void testIsValid() { public void testIsValid() {
assertTrue(emptyPath.isValid()); assertTrue(emptyPath.isValid());
assertTrue(shortPath.isValid()); assertTrue(shortPath.isValid());
assertTrue(longPath.isValid()); assertTrue(longPath.isValid());
@ -114,7 +101,7 @@ public class PathTest {
} }
@Test @Test
void testGetLength() { public void testGetLength() {
assertEquals(emptyPath.getLength(), 0); assertEquals(emptyPath.getLength(), 0);
assertEquals(shortPath.getLength(), 40); assertEquals(shortPath.getLength(), 40);
assertEquals(longPath.getLength(), 60); assertEquals(longPath.getLength(), 60);
@ -123,7 +110,7 @@ public class PathTest {
} }
@Test @Test
void testGetMinimumTravelTime() { public void testGetMinimumTravelTime() {
assertEquals(emptyPath.getMinimumTravelTime(), 0, 1e-4); assertEquals(emptyPath.getMinimumTravelTime(), 0, 1e-4);
assertEquals(shortPath.getMinimumTravelTime(), 4, 1e-4); assertEquals(shortPath.getMinimumTravelTime(), 4, 1e-4);
assertEquals(longPath.getMinimumTravelTime(), 5, 1e-4); assertEquals(longPath.getMinimumTravelTime(), 5, 1e-4);
@ -132,7 +119,7 @@ public class PathTest {
} }
@Test @Test
void testCreateFastestPathFromNodes() { public void testCreateFastestPathFromNodes() {
Path path; Path path;
Arc[] expected; Arc[] expected;
@ -152,18 +139,10 @@ public class PathTest {
for (int i = 0; i < expected.length; ++i) { for (int i = 0; i < expected.length; ++i) {
assertEquals(expected[i], path.getArcs().get(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 @Test
void testCreateShortestPathFromNodes() { public void testCreateShortestPathFromNodes() {
Path path; Path path;
Arc[] expected; Arc[] expected;
@ -183,13 +162,16 @@ public class PathTest {
for (int i = 0; i < expected.length; ++i) { for (int i = 0; i < expected.length; ++i) {
assertEquals(expected[i], path.getArcs().get(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; 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.BufferedInputStream;
import java.io.DataInputStream; import java.io.DataInputStream;
@ -11,8 +11,8 @@ import java.util.List;
import org.insa.graph.Graph; import org.insa.graph.Graph;
import org.insa.graph.Node; import org.insa.graph.Node;
import org.insa.graph.Point; import org.insa.graph.Point;
import org.junit.jupiter.api.BeforeAll; import org.junit.BeforeClass;
import org.junit.jupiter.api.Test; import org.junit.Test;
public class BinaryGraphReaderTest { public class BinaryGraphReaderTest {
@ -21,20 +21,20 @@ public class BinaryGraphReaderTest {
private static Graph midip; private static Graph midip;
@BeforeAll @BeforeClass
static void initAll() throws IOException { public static void initAll() throws IOException {
BinaryGraphReader reader = new BinaryGraphReader( BinaryGraphReader reader = new BinaryGraphReader(
new DataInputStream(new BufferedInputStream(new FileInputStream("Maps/midip.map")))); new DataInputStream(new BufferedInputStream(new FileInputStream("Maps/midip.map"))));
midip = reader.read(); 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.getLongitude(), longitude, EPS);
assertEquals(p1.getLatitude(), latitude, EPS); assertEquals(p1.getLatitude(), latitude, EPS);
} }
@Test @Test
void testMidipNodes() { public void testMidipNodes() {
List<Node> nodes = midip.getNodes(); List<Node> nodes = midip.getNodes();
assertEquals(nodes.size(), 150827); assertEquals(nodes.size(), 150827);
@ -49,7 +49,7 @@ public class BinaryGraphReaderTest {
} }
@Test @Test
void testMidipArcs() { public void testMidipArcs() {
// TODO: Check the number of edges. // TODO: Check the number of edges.
// TODO: Check information for some edges. // TODO: Check information for some edges.
} }

View File

@ -1,13 +1,13 @@
package org.insa.utility; package org.insa.utility;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Arrays; import java.util.Arrays;
import java.util.stream.IntStream; import java.util.stream.IntStream;
import org.junit.jupiter.api.BeforeEach; import org.junit.Before;
import org.junit.jupiter.api.Test; import org.junit.Test;
public class BinaryHeapTest { public class BinaryHeapTest {
@ -16,8 +16,8 @@ public class BinaryHeapTest {
private BinaryHeap<Integer> heap1, heap2; private BinaryHeap<Integer> heap1, heap2;
@BeforeEach @Before
void init() { public void init() {
// Create the range heap // Create the range heap
this.heap1 = new BinaryHeap<Integer>(); this.heap1 = new BinaryHeap<Integer>();
this.heap2 = new BinaryHeap<Integer>(); this.heap2 = new BinaryHeap<Integer>();
@ -29,7 +29,7 @@ public class BinaryHeapTest {
} }
@Test @Test
void testInsert() { public void testInsert() {
BinaryHeap<Integer> heap = new BinaryHeap<Integer>(); BinaryHeap<Integer> heap = new BinaryHeap<Integer>();
int size = 0; int size = 0;
for (int x: data1) { for (int x: data1) {
@ -50,7 +50,7 @@ public class BinaryHeapTest {
} }
@Test @Test
void testDeleteMin() { public void testDeleteMin() {
// range 1 (sorted) // range 1 (sorted)
int[] range1 = data1; int[] range1 = data1;
int size = range1.length; int size = range1.length;