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

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