Skip to content
This repository was archived by the owner on Jan 13, 2023. It is now read-only.

Commit 3b31299

Browse files
committed
GP-7: fix mismatches of JUnit4 and JUnit5
1 parent b65df00 commit 3b31299

File tree

3 files changed

+26
-22
lines changed

3 files changed

+26
-22
lines changed

binary-search-tree/src/test/java/com/bobocode/bst/BinarySearchTreeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
import java.util.List;
77

88
import static org.hamcrest.CoreMatchers.is;
9+
import static org.hamcrest.MatcherAssert.assertThat;
910
import static org.hamcrest.Matchers.contains;
1011
import static org.hamcrest.Matchers.empty;
11-
import static org.junit.Assert.assertThat;
1212

1313
public class BinarySearchTreeTest {
1414

linked-list/src/test/java/com/bobocode/LinkedListTest.java

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
package com.bobocode;
22

3+
34
import org.junit.jupiter.api.Test;
45

56
import java.util.NoSuchElementException;
67

7-
import static org.junit.Assert.*;
8+
import static org.junit.jupiter.api.Assertions.assertEquals;
9+
import static org.junit.jupiter.api.Assertions.assertFalse;
10+
import static org.junit.jupiter.api.Assertions.assertThrows;
11+
import static org.junit.jupiter.api.Assertions.assertTrue;
12+
813

914
public class LinkedListTest {
1015

@@ -60,14 +65,14 @@ public void testGetLastElement() {
6065
assertEquals(42, intList.getLast().intValue());
6166
}
6267

63-
@Test(expected = NoSuchElementException.class)
68+
@Test
6469
public void testGetFirstOfEmptyList() {
65-
intList.getFirst();
70+
assertThrows(NoSuchElementException.class, () -> intList.getFirst());
6671
}
6772

68-
@Test(expected = NoSuchElementException.class)
73+
@Test
6974
public void testGetLastOfEmptyList() {
70-
intList.getLast();
75+
assertThrows(NoSuchElementException.class, () -> intList.getLast());
7176
}
7277

7378
@Test
@@ -79,23 +84,23 @@ public void testGetElementByIndex() {
7984
assertEquals(52, intList.get(2).intValue());
8085
}
8186

82-
@Test(expected = IndexOutOfBoundsException.class)
87+
@Test
8388
public void testGetElementByIndexOfEmptyTree() {
84-
intList.get(1);
89+
assertThrows(IndexOutOfBoundsException.class, () -> intList.get(1));
8590
}
8691

87-
@Test(expected = IndexOutOfBoundsException.class)
92+
@Test
8893
public void testGetElementByNegativeIndex() {
8994
intList = LinkedList.of(1, 2, 3);
9095

91-
intList.get(-2);
96+
assertThrows(IndexOutOfBoundsException.class, () -> intList.get(-2));
9297
}
9398

94-
@Test(expected = IndexOutOfBoundsException.class)
99+
@Test
95100
public void testGetElementBySizeIndex() {
96101
intList = LinkedList.of(1, 2, 3);
97102

98-
intList.get(3);
103+
assertThrows(IndexOutOfBoundsException.class, () -> intList.get(3));
99104
}
100105

101106
@Test
@@ -153,11 +158,11 @@ public void testSetElementByIndex() {
153158
assertEquals(3, intList.size());
154159
}
155160

156-
@Test(expected = IndexOutOfBoundsException.class)
161+
@Test
157162
public void testSetElementByInvalidIndex() {
158163
intList = LinkedList.of(110, 111);
159164

160-
intList.set(3, 114);
165+
assertThrows(IndexOutOfBoundsException.class, () -> intList.set(3, 114));
161166
}
162167

163168
@Test
@@ -207,9 +212,9 @@ public void testRemoveSingleElementByIndex() {
207212
assertEquals(0, intList.size());
208213
}
209214

210-
@Test(expected = IndexOutOfBoundsException.class)
215+
@Test
211216
public void testRemoveElementOfEmptyList() {
212-
intList.remove(0);
217+
assertThrows(IndexOutOfBoundsException.class, () -> intList.remove(0));
213218
}
214219

215220
@Test

stack/src/test/java/com/bobocode/StackTest.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
package com.bobocode;
22

3-
import org.junit.jupiter.api.Test;
43
import com.bobocode.exception.EmptyStackException;
4+
import org.junit.jupiter.api.Test;
55

6+
import static org.hamcrest.MatcherAssert.assertThat;
67
import static org.hamcrest.Matchers.is;
7-
import static org.junit.Assert.assertEquals;
8-
import static org.junit.Assert.assertThat;
9-
import static org.junit.Assert.assertTrue;
8+
import static org.junit.jupiter.api.Assertions.assertThrows;
109

1110
public class StackTest {
1211

@@ -17,9 +16,9 @@ public void testPushElementOntoEmptyStack() {
1716
intStack.push(234);
1817
}
1918

20-
@Test(expected = EmptyStackException.class)
19+
@Test
2120
public void testPopElementFromEmptyStack() {
22-
intStack.pop();
21+
assertThrows(EmptyStackException.class, () -> intStack.pop());
2322
}
2423

2524
@Test

0 commit comments

Comments
 (0)