Просмотр исходного кода

Simple-linked-list: use JUnit's @Rule feature

Omerovic Dzenan 9 лет назад
Родитель
Сommit
add44e0c5e
1 измененных файлов: 7 добавлений и 2 удалений
  1. 7
    2
      exercises/simple-linked-list/src/test/java/SimpleLinkedListTest.java

+ 7
- 2
exercises/simple-linked-list/src/test/java/SimpleLinkedListTest.java Просмотреть файл

@@ -1,5 +1,7 @@
1 1
 import org.junit.Ignore;
2 2
 import org.junit.Test;
3
+import org.junit.Rule;
4
+import org.junit.rules.ExpectedException;
3 5
 
4 6
 import java.util.NoSuchElementException;
5 7
 
@@ -8,7 +10,9 @@ import static org.junit.Assert.*;
8 10
 
9 11
 public class SimpleLinkedListTest {
10 12
 
11
-
13
+    @Rule
14
+    public ExpectedException thrown = ExpectedException.none();
15
+    
12 16
     @Test
13 17
     public void aNewListIsEmpty() {
14 18
         SimpleLinkedList list = new SimpleLinkedList();
@@ -24,8 +28,9 @@ public class SimpleLinkedListTest {
24 28
     }
25 29
 
26 30
     @Ignore
27
-    @Test(expected = NoSuchElementException.class)
31
+    @Test
28 32
     public void popOnEmptyListWillThrow() {
33
+        thrown.expect(NoSuchElementException.class);
29 34
         SimpleLinkedList list = new SimpleLinkedList();
30 35
         list.pop();
31 36
     }