Skip to content

Commit

Permalink
JUnit 5 Migration (#381)
Browse files Browse the repository at this point in the history
* 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] <[email protected]>

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
syoon2 and dependabot[bot] authored Jun 27, 2023
1 parent e894211 commit 04d5d2f
Show file tree
Hide file tree
Showing 75 changed files with 625 additions and 564 deletions.
16 changes: 7 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,21 @@ repositories {
// 'compile' for project dependencies.
dependencies {
// Apache commons lang
testImplementation 'org.apache.commons:commons-lang3:3.6'

// JUnit framework
testImplementation 'junit:junit:4.+'
testImplementation 'org.apache.commons:commons-lang3:3.12.0'

// JUnit 5 / Jupiter
testImplementation('org.junit.jupiter:junit-jupiter-api:5.4.2')

testImplementation('org.junit.jupiter:junit-jupiter:5.9.3')
testRuntimeOnly('org.junit.jupiter:junit-jupiter-engine:5.9.3')

// Google Guava lib
testImplementation group: 'com.google.guava', name: 'guava', version: '22.0'
testImplementation group: 'com.google.guava', name: 'guava', version: '23.0'

// Google Truth test framework
// https://mvnrepository.com/artifact/com.google.truth/truth
testImplementation group: 'com.google.truth', name: 'truth', version: '1.0'
testImplementation group: 'com.google.truth', name: 'truth', version: '1.1.5'

// Test mocking framework
testImplementation "org.mockito:mockito-core:1.+"
testImplementation "org.mockito:mockito-core:5.+"
}

test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import java.util.Collections;
import java.util.List;
import java.util.TreeSet;
import org.junit.Before;
import org.junit.Test;

import org.junit.jupiter.api.*;

public class AVLTreeTest {

Expand All @@ -18,7 +18,7 @@ public class AVLTreeTest {

private AVLTreeRecursive<Integer> tree;

@Before
@BeforeEach
public void setup() {
tree = new AVLTreeRecursive<>();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.williamfiset.algorithms.datastructures.balancedtree;

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

import java.util.*;
import org.junit.Before;
import org.junit.Test;

import org.junit.jupiter.api.*;

public class RedBlackTreeTest {

Expand All @@ -15,14 +16,14 @@ public class RedBlackTreeTest {

private RedBlackTree<Integer> tree;

@Before
@BeforeEach
public void setup() {
tree = new RedBlackTree<>();
}

@Test(expected = IllegalArgumentException.class)
@Test
public void testNullInsertion() {
tree.insert(null);
assertThrows(IllegalArgumentException.class, () -> tree.insert(null));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.williamfiset.algorithms.datastructures.balancedtree;

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

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.TreeSet;
import org.junit.Before;
import org.junit.Test;

import org.junit.jupiter.api.*;

public class TreapTreeTest {

Expand All @@ -18,14 +19,14 @@ public class TreapTreeTest {

private TreapTree<Integer> tree;

@Before
@BeforeEach
public void setup() {
tree = new TreapTree<>();
}

@Test(expected = IllegalArgumentException.class)
@Test
public void testNullInsertion() {
tree.insert(null);
assertThrows(IllegalArgumentException.class, () -> tree.insert(null));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.williamfiset.algorithms.datastructures.binarysearchtree;

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

import java.util.ArrayDeque;
import java.util.ArrayList;
Expand All @@ -9,8 +10,8 @@
import java.util.Deque;
import java.util.Iterator;
import java.util.List;
import org.junit.Before;
import org.junit.Test;

import org.junit.jupiter.api.*;

class TestTreeNode {

Expand Down Expand Up @@ -84,7 +85,7 @@ public class BinarySearchTreeTest {

static final int LOOPS = 100;

@Before
@BeforeEach
public void setup() {}

@Test
Expand Down Expand Up @@ -202,7 +203,7 @@ public void testContains() {
assertThat(tree.contains('C')).isTrue();
}

@Test(expected = ConcurrentModificationException.class)
@Test
public void concurrentModificationErrorPreOrder() {

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

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

while (iter.hasNext()) {
bst.add(0);
iter.next();
}
assertThrows(ConcurrentModificationException.class, () -> {
while (iter.hasNext()) {
bst.add(0);
iter.next();
}
});
}

@Test(expected = ConcurrentModificationException.class)
@Test
public void concurrentModificationErrorInOrderOrder() {

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

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

while (iter.hasNext()) {
bst.add(0);
iter.next();
}
assertThrows(ConcurrentModificationException.class, () -> {
while (iter.hasNext()) {
bst.add(0);
iter.next();
}
});
}

@Test(expected = ConcurrentModificationException.class)
@Test
public void concurrentModificationErrorPostOrder() {

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

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

while (iter.hasNext()) {
bst.add(0);
iter.next();
}
assertThrows(ConcurrentModificationException.class, () -> {
while (iter.hasNext()) {
bst.add(0);
iter.next();
}
});
}

@Test(expected = ConcurrentModificationException.class)
@Test
public void concurrentModificationErrorLevelOrder() {

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

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

while (iter.hasNext()) {
bst.add(0);
iter.next();
}
assertThrows(ConcurrentModificationException.class, () -> {
while (iter.hasNext()) {
bst.add(0);
iter.next();
}
});
}

@Test(expected = ConcurrentModificationException.class)
@Test
public void concurrentModificationErrorRemovingPreOrder() {

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

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

while (iter.hasNext()) {
bst.remove(2);
iter.next();
}
assertThrows(ConcurrentModificationException.class, () -> {
while (iter.hasNext()) {
bst.remove(2);
iter.next();
}
});
}

@Test(expected = ConcurrentModificationException.class)
@Test
public void concurrentModificationErrorRemovingInOrderOrder() {

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

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

while (iter.hasNext()) {
bst.remove(2);
iter.next();
}
assertThrows(ConcurrentModificationException.class, () -> {
while (iter.hasNext()) {
bst.remove(2);
iter.next();
}
});
}

@Test(expected = ConcurrentModificationException.class)
@Test
public void concurrentModificationErrorRemovingPostOrder() {

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

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

while (iter.hasNext()) {
bst.remove(2);
iter.next();
}
assertThrows(ConcurrentModificationException.class, () -> {
while (iter.hasNext()) {
bst.remove(2);
iter.next();
}
});
}

@Test(expected = ConcurrentModificationException.class)
@Test
public void concurrentModificationErrorRemovingLevelOrder() {

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

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

while (iter.hasNext()) {
bst.remove(2);
iter.next();
}
assertThrows(ConcurrentModificationException.class, () -> {
while (iter.hasNext()) {
bst.remove(2);
iter.next();
}
});
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

import com.williamfiset.algorithms.datastructures.utils.TestUtils;
import java.util.*;
import org.junit.Test;

import org.junit.jupiter.api.Test;

public class SplayTreeTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import java.util.HashSet;
import java.util.Random;
import java.util.Set;
import org.junit.Before;
import org.junit.Test;

import org.junit.jupiter.api.*;

public class BloomFilterTest {

Expand All @@ -20,7 +20,7 @@ public class BloomFilterTest {
static final int TEST_SZ = 1000;
static final int LOOPS = 1000;

@Before
@BeforeEach
public void setup() {}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.williamfiset.algorithms.datastructures.fenwicktree;

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

import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.*;

public class FenwickTreeRangeQueryPointUpdateTest {

Expand All @@ -15,7 +15,7 @@ public class FenwickTreeRangeQueryPointUpdateTest {

static long UNUSED_VAL;

@Before
@BeforeEach
public void setup() {
UNUSED_VAL = randValue();
}
Expand Down Expand Up @@ -169,9 +169,9 @@ public static long randValue() {
return (long) (Math.random() * MAX_RAND_NUM * 2) + MIN_RAND_NUM;
}

@Test(expected = IllegalArgumentException.class)
@Test
public void testIllegalCreation() {
new FenwickTreeRangeQueryPointUpdate(null);
assertThrows(IllegalArgumentException.class, () -> new FenwickTreeRangeQueryPointUpdate(null));
}

// Generate a list of random numbers, one based
Expand Down
Loading

0 comments on commit 04d5d2f

Please sign in to comment.