Skip to content

Commit 04d5d2f

Browse files
JUnit 5 Migration (williamfiset#381)
* Replace JUnit 4 dependencies with JUnit 5 * Replace JUnit 4 API uses in data structure tests with JUnit 5 API * Bump up all test dependencies * Replace JUnit 4 API uses in remaining tests with JUnit 5 API * Bump com.google.truth:truth from 1.1.3 to 1.1.5 Bumps [com.google.truth:truth](https://github.com/google/truth) from 1.1.3 to 1.1.5. - [Release notes](https://github.com/google/truth/releases) - [Commits](https://github.com/google/truth/commits/v1.1.5) --- updated-dependencies: - dependency-name: com.google.truth:truth dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent e894211 commit 04d5d2f

File tree

75 files changed

+625
-564
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+625
-564
lines changed

build.gradle

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,21 @@ repositories {
2727
// 'compile' for project dependencies.
2828
dependencies {
2929
// Apache commons lang
30-
testImplementation 'org.apache.commons:commons-lang3:3.6'
31-
32-
// JUnit framework
33-
testImplementation 'junit:junit:4.+'
30+
testImplementation 'org.apache.commons:commons-lang3:3.12.0'
3431

3532
// JUnit 5 / Jupiter
36-
testImplementation('org.junit.jupiter:junit-jupiter-api:5.4.2')
37-
33+
testImplementation('org.junit.jupiter:junit-jupiter:5.9.3')
34+
testRuntimeOnly('org.junit.jupiter:junit-jupiter-engine:5.9.3')
35+
3836
// Google Guava lib
39-
testImplementation group: 'com.google.guava', name: 'guava', version: '22.0'
37+
testImplementation group: 'com.google.guava', name: 'guava', version: '23.0'
4038

4139
// Google Truth test framework
4240
// https://mvnrepository.com/artifact/com.google.truth/truth
43-
testImplementation group: 'com.google.truth', name: 'truth', version: '1.0'
41+
testImplementation group: 'com.google.truth', name: 'truth', version: '1.1.5'
4442

4543
// Test mocking framework
46-
testImplementation "org.mockito:mockito-core:1.+"
44+
testImplementation "org.mockito:mockito-core:5.+"
4745
}
4846

4947
test {

src/test/java/com/williamfiset/algorithms/datastructures/balancedtree/AVLTreeTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import java.util.Collections;
77
import java.util.List;
88
import java.util.TreeSet;
9-
import org.junit.Before;
10-
import org.junit.Test;
9+
10+
import org.junit.jupiter.api.*;
1111

1212
public class AVLTreeTest {
1313

@@ -18,7 +18,7 @@ public class AVLTreeTest {
1818

1919
private AVLTreeRecursive<Integer> tree;
2020

21-
@Before
21+
@BeforeEach
2222
public void setup() {
2323
tree = new AVLTreeRecursive<>();
2424
}

src/test/java/com/williamfiset/algorithms/datastructures/balancedtree/RedBlackTreeTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package com.williamfiset.algorithms.datastructures.balancedtree;
22

33
import static com.google.common.truth.Truth.assertThat;
4+
import static org.junit.jupiter.api.Assertions.assertThrows;
45

56
import java.util.*;
6-
import org.junit.Before;
7-
import org.junit.Test;
7+
8+
import org.junit.jupiter.api.*;
89

910
public class RedBlackTreeTest {
1011

@@ -15,14 +16,14 @@ public class RedBlackTreeTest {
1516

1617
private RedBlackTree<Integer> tree;
1718

18-
@Before
19+
@BeforeEach
1920
public void setup() {
2021
tree = new RedBlackTree<>();
2122
}
2223

23-
@Test(expected = IllegalArgumentException.class)
24+
@Test
2425
public void testNullInsertion() {
25-
tree.insert(null);
26+
assertThrows(IllegalArgumentException.class, () -> tree.insert(null));
2627
}
2728

2829
@Test

src/test/java/com/williamfiset/algorithms/datastructures/balancedtree/TreapTreeTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package com.williamfiset.algorithms.datastructures.balancedtree;
22

33
import static com.google.common.truth.Truth.assertThat;
4+
import static org.junit.jupiter.api.Assertions.assertThrows;
45

56
import java.util.ArrayList;
67
import java.util.Collections;
78
import java.util.List;
89
import java.util.TreeSet;
9-
import org.junit.Before;
10-
import org.junit.Test;
10+
11+
import org.junit.jupiter.api.*;
1112

1213
public class TreapTreeTest {
1314

@@ -18,14 +19,14 @@ public class TreapTreeTest {
1819

1920
private TreapTree<Integer> tree;
2021

21-
@Before
22+
@BeforeEach
2223
public void setup() {
2324
tree = new TreapTree<>();
2425
}
2526

26-
@Test(expected = IllegalArgumentException.class)
27+
@Test
2728
public void testNullInsertion() {
28-
tree.insert(null);
29+
assertThrows(IllegalArgumentException.class, () -> tree.insert(null));
2930
}
3031

3132
@Test

src/test/java/com/williamfiset/algorithms/datastructures/binarysearchtree/BinarySearchTreeTest.java

Lines changed: 60 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.williamfiset.algorithms.datastructures.binarysearchtree;
22

33
import static com.google.common.truth.Truth.assertThat;
4+
import static org.junit.jupiter.api.Assertions.assertThrows;
45

56
import java.util.ArrayDeque;
67
import java.util.ArrayList;
@@ -9,8 +10,8 @@
910
import java.util.Deque;
1011
import java.util.Iterator;
1112
import java.util.List;
12-
import org.junit.Before;
13-
import org.junit.Test;
13+
14+
import org.junit.jupiter.api.*;
1415

1516
class TestTreeNode {
1617

@@ -84,7 +85,7 @@ public class BinarySearchTreeTest {
8485

8586
static final int LOOPS = 100;
8687

87-
@Before
88+
@BeforeEach
8889
public void setup() {}
8990

9091
@Test
@@ -202,7 +203,7 @@ public void testContains() {
202203
assertThat(tree.contains('C')).isTrue();
203204
}
204205

205-
@Test(expected = ConcurrentModificationException.class)
206+
@Test
206207
public void concurrentModificationErrorPreOrder() {
207208

208209
BinarySearchTree<Integer> bst = new BinarySearchTree<>();
@@ -213,13 +214,15 @@ public void concurrentModificationErrorPreOrder() {
213214

214215
Iterator<Integer> iter = bst.traverse(TreeTraversalOrder.PRE_ORDER);
215216

216-
while (iter.hasNext()) {
217-
bst.add(0);
218-
iter.next();
219-
}
217+
assertThrows(ConcurrentModificationException.class, () -> {
218+
while (iter.hasNext()) {
219+
bst.add(0);
220+
iter.next();
221+
}
222+
});
220223
}
221224

222-
@Test(expected = ConcurrentModificationException.class)
225+
@Test
223226
public void concurrentModificationErrorInOrderOrder() {
224227

225228
BinarySearchTree<Integer> bst = new BinarySearchTree<>();
@@ -230,13 +233,15 @@ public void concurrentModificationErrorInOrderOrder() {
230233

231234
Iterator<Integer> iter = bst.traverse(TreeTraversalOrder.IN_ORDER);
232235

233-
while (iter.hasNext()) {
234-
bst.add(0);
235-
iter.next();
236-
}
236+
assertThrows(ConcurrentModificationException.class, () -> {
237+
while (iter.hasNext()) {
238+
bst.add(0);
239+
iter.next();
240+
}
241+
});
237242
}
238243

239-
@Test(expected = ConcurrentModificationException.class)
244+
@Test
240245
public void concurrentModificationErrorPostOrder() {
241246

242247
BinarySearchTree<Integer> bst = new BinarySearchTree<>();
@@ -247,13 +252,15 @@ public void concurrentModificationErrorPostOrder() {
247252

248253
Iterator<Integer> iter = bst.traverse(TreeTraversalOrder.POST_ORDER);
249254

250-
while (iter.hasNext()) {
251-
bst.add(0);
252-
iter.next();
253-
}
255+
assertThrows(ConcurrentModificationException.class, () -> {
256+
while (iter.hasNext()) {
257+
bst.add(0);
258+
iter.next();
259+
}
260+
});
254261
}
255262

256-
@Test(expected = ConcurrentModificationException.class)
263+
@Test
257264
public void concurrentModificationErrorLevelOrder() {
258265

259266
BinarySearchTree<Integer> bst = new BinarySearchTree<>();
@@ -264,13 +271,15 @@ public void concurrentModificationErrorLevelOrder() {
264271

265272
Iterator<Integer> iter = bst.traverse(TreeTraversalOrder.LEVEL_ORDER);
266273

267-
while (iter.hasNext()) {
268-
bst.add(0);
269-
iter.next();
270-
}
274+
assertThrows(ConcurrentModificationException.class, () -> {
275+
while (iter.hasNext()) {
276+
bst.add(0);
277+
iter.next();
278+
}
279+
});
271280
}
272281

273-
@Test(expected = ConcurrentModificationException.class)
282+
@Test
274283
public void concurrentModificationErrorRemovingPreOrder() {
275284

276285
BinarySearchTree<Integer> bst = new BinarySearchTree<>();
@@ -281,13 +290,15 @@ public void concurrentModificationErrorRemovingPreOrder() {
281290

282291
Iterator<Integer> iter = bst.traverse(TreeTraversalOrder.PRE_ORDER);
283292

284-
while (iter.hasNext()) {
285-
bst.remove(2);
286-
iter.next();
287-
}
293+
assertThrows(ConcurrentModificationException.class, () -> {
294+
while (iter.hasNext()) {
295+
bst.remove(2);
296+
iter.next();
297+
}
298+
});
288299
}
289300

290-
@Test(expected = ConcurrentModificationException.class)
301+
@Test
291302
public void concurrentModificationErrorRemovingInOrderOrder() {
292303

293304
BinarySearchTree<Integer> bst = new BinarySearchTree<>();
@@ -298,13 +309,15 @@ public void concurrentModificationErrorRemovingInOrderOrder() {
298309

299310
Iterator<Integer> iter = bst.traverse(TreeTraversalOrder.IN_ORDER);
300311

301-
while (iter.hasNext()) {
302-
bst.remove(2);
303-
iter.next();
304-
}
312+
assertThrows(ConcurrentModificationException.class, () -> {
313+
while (iter.hasNext()) {
314+
bst.remove(2);
315+
iter.next();
316+
}
317+
});
305318
}
306319

307-
@Test(expected = ConcurrentModificationException.class)
320+
@Test
308321
public void concurrentModificationErrorRemovingPostOrder() {
309322

310323
BinarySearchTree<Integer> bst = new BinarySearchTree<>();
@@ -315,13 +328,15 @@ public void concurrentModificationErrorRemovingPostOrder() {
315328

316329
Iterator<Integer> iter = bst.traverse(TreeTraversalOrder.POST_ORDER);
317330

318-
while (iter.hasNext()) {
319-
bst.remove(2);
320-
iter.next();
321-
}
331+
assertThrows(ConcurrentModificationException.class, () -> {
332+
while (iter.hasNext()) {
333+
bst.remove(2);
334+
iter.next();
335+
}
336+
});
322337
}
323338

324-
@Test(expected = ConcurrentModificationException.class)
339+
@Test
325340
public void concurrentModificationErrorRemovingLevelOrder() {
326341

327342
BinarySearchTree<Integer> bst = new BinarySearchTree<>();
@@ -332,10 +347,12 @@ public void concurrentModificationErrorRemovingLevelOrder() {
332347

333348
Iterator<Integer> iter = bst.traverse(TreeTraversalOrder.LEVEL_ORDER);
334349

335-
while (iter.hasNext()) {
336-
bst.remove(2);
337-
iter.next();
338-
}
350+
assertThrows(ConcurrentModificationException.class, () -> {
351+
while (iter.hasNext()) {
352+
bst.remove(2);
353+
iter.next();
354+
}
355+
});
339356
}
340357

341358
@Test

src/test/java/com/williamfiset/algorithms/datastructures/binarysearchtree/SplayTreeTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
import com.williamfiset.algorithms.datastructures.utils.TestUtils;
66
import java.util.*;
7-
import org.junit.Test;
7+
8+
import org.junit.jupiter.api.Test;
89

910
public class SplayTreeTest {
1011

src/test/java/com/williamfiset/algorithms/datastructures/bloomfilter/BloomFilterTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import java.util.HashSet;
77
import java.util.Random;
88
import java.util.Set;
9-
import org.junit.Before;
10-
import org.junit.Test;
9+
10+
import org.junit.jupiter.api.*;
1111

1212
public class BloomFilterTest {
1313

@@ -20,7 +20,7 @@ public class BloomFilterTest {
2020
static final int TEST_SZ = 1000;
2121
static final int LOOPS = 1000;
2222

23-
@Before
23+
@BeforeEach
2424
public void setup() {}
2525

2626
@Test

src/test/java/com/williamfiset/algorithms/datastructures/fenwicktree/FenwickTreeRangeQueryPointUpdateTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.williamfiset.algorithms.datastructures.fenwicktree;
22

33
import static com.google.common.truth.Truth.assertThat;
4+
import static org.junit.jupiter.api.Assertions.assertThrows;
45

5-
import org.junit.Before;
6-
import org.junit.Test;
6+
import org.junit.jupiter.api.*;
77

88
public class FenwickTreeRangeQueryPointUpdateTest {
99

@@ -15,7 +15,7 @@ public class FenwickTreeRangeQueryPointUpdateTest {
1515

1616
static long UNUSED_VAL;
1717

18-
@Before
18+
@BeforeEach
1919
public void setup() {
2020
UNUSED_VAL = randValue();
2121
}
@@ -169,9 +169,9 @@ public static long randValue() {
169169
return (long) (Math.random() * MAX_RAND_NUM * 2) + MIN_RAND_NUM;
170170
}
171171

172-
@Test(expected = IllegalArgumentException.class)
172+
@Test
173173
public void testIllegalCreation() {
174-
new FenwickTreeRangeQueryPointUpdate(null);
174+
assertThrows(IllegalArgumentException.class, () -> new FenwickTreeRangeQueryPointUpdate(null));
175175
}
176176

177177
// Generate a list of random numbers, one based

0 commit comments

Comments
 (0)