Ver código fonte

Merge pull request #299 from odzeno/nth-prime

Nth-prime: use JUnit's @Rule feature [Fix #263]
Stuart Kent 9 anos atrás
pai
commit
8eed8d6b3a
1 arquivos alterados com 8 adições e 1 exclusões
  1. 8
    1
      exercises/nth-prime/src/test/java/PrimeTest.java

+ 8
- 1
exercises/nth-prime/src/test/java/PrimeTest.java Ver arquivo

1
 import org.junit.Test;
1
 import org.junit.Test;
2
 import org.junit.Ignore;
2
 import org.junit.Ignore;
3
+import org.junit.Rule;
4
+import org.junit.rules.ExpectedException;
3
 
5
 
4
 import static org.hamcrest.CoreMatchers.*;
6
 import static org.hamcrest.CoreMatchers.*;
5
 import static org.junit.Assert.*;
7
 import static org.junit.Assert.*;
6
 
8
 
7
 public class PrimeTest {
9
 public class PrimeTest {
8
 
10
 
11
+    @Rule
12
+    public ExpectedException thrown = ExpectedException.none();
13
+    
9
     @Test
14
     @Test
10
     public void testFirstPrime() {
15
     public void testFirstPrime() {
11
         assertThat(Prime.nth(1), is(2));
16
         assertThat(Prime.nth(1), is(2));
30
     }
35
     }
31
 
36
 
32
     @Ignore
37
     @Ignore
33
-    @Test(expected = IllegalArgumentException.class)
38
+    @Test
34
     public void testUndefinedPrime() {
39
     public void testUndefinedPrime() {
40
+        thrown.expect(IllegalArgumentException.class);
35
         Prime.nth(0);
41
         Prime.nth(0);
36
     }
42
     }
43
+    
37
 }
44
 }