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

Change JUnit @Test expected parameter with ExpectedException @Rule in triangle exercise [Fix #268]

MichaelSpets 9 лет назад
Родитель
Сommit
63784f3bd6
1 измененных файлов: 13 добавлений и 6 удалений
  1. 13
    6
      exercises/triangle/src/test/java/TriangleTest.java

+ 13
- 6
exercises/triangle/src/test/java/TriangleTest.java Просмотреть файл

1
 import org.junit.Test;
1
 import org.junit.Test;
2
 import org.junit.Ignore;
2
 import org.junit.Ignore;
3
+import org.junit.rules.TestWatcher;
3
 
4
 
4
 import static org.junit.Assert.assertEquals;
5
 import static org.junit.Assert.assertEquals;
5
 
6
 
6
 public class TriangleTest {
7
 public class TriangleTest {
7
 
8
 
8
-
9
+    @Rule
10
+    public final ExpectedException thrown = ExpectedException.none();
9
     @Test
11
     @Test
10
     public void equilateralTriangleHaveEqualSides() throws Exception {
12
     public void equilateralTriangleHaveEqualSides() throws Exception {
11
         Triangle triangle = new Triangle(2, 2, 2);
13
         Triangle triangle = new Triangle(2, 2, 2);
86
     }
88
     }
87
 
89
 
88
     @Ignore
90
     @Ignore
89
-    @Test(expected = TriangleException.class)
91
+    @Test
90
     public void trianglesWithNoSizeAreIllegal() throws Exception {
92
     public void trianglesWithNoSizeAreIllegal() throws Exception {
93
+        thrown.expect(TriangleException.class);
91
         new Triangle(0, 0, 0);
94
         new Triangle(0, 0, 0);
92
     }
95
     }
93
 
96
 
94
     @Ignore
97
     @Ignore
95
-    @Test(expected = TriangleException.class)
98
+    @Test
96
     public void trianglesWithNegativeSidesAreIllegal() throws Exception {
99
     public void trianglesWithNegativeSidesAreIllegal() throws Exception {
100
+        thrown.expect(TriangleException.class);
97
         new Triangle(3, 4, -5);
101
         new Triangle(3, 4, -5);
98
     }
102
     }
99
 
103
 
100
     @Ignore
104
     @Ignore
101
-    @Test(expected = TriangleException.class)
105
+    @Test
102
     public void trianglesViolatingTriangleInequalityAreIllegal() throws Exception {
106
     public void trianglesViolatingTriangleInequalityAreIllegal() throws Exception {
107
+        thrown.expect(TriangleException.class);
103
         new Triangle(1, 1, 3);
108
         new Triangle(1, 1, 3);
104
     }
109
     }
105
 
110
 
106
     @Ignore
111
     @Ignore
107
-    @Test(expected = TriangleException.class)
112
+    @Test
108
     public void trianglesViolatingTriangleInequalityAreIllegal2() throws Exception {
113
     public void trianglesViolatingTriangleInequalityAreIllegal2() throws Exception {
114
+        thrown.expect(TriangleException.class);
109
         new Triangle(2, 4, 2);
115
         new Triangle(2, 4, 2);
110
     }
116
     }
111
 
117
 
112
     @Ignore
118
     @Ignore
113
-    @Test(expected = TriangleException.class)
119
+    @Test
114
     public void trianglesViolatingTriangleInequalityAreIllegal3() throws Exception {
120
     public void trianglesViolatingTriangleInequalityAreIllegal3() throws Exception {
121
+        thrown.expect(TriangleException.class);
115
         new Triangle(7, 3, 2);
122
         new Triangle(7, 3, 2);
116
     }
123
     }
117
 }
124
 }