Explorar el Código

Merge pull request #293 from michaelspets/junit_rules

Migrate to JUnit @Rule in triangle exercise [Fix #268]
FridaTveit hace 9 años
padre
commit
4e98d87290
Se han modificado 1 ficheros con 29 adiciones y 20 borrados
  1. 29
    20
      exercises/triangle/src/test/java/TriangleTest.java

+ 29
- 20
exercises/triangle/src/test/java/TriangleTest.java Ver fichero

@@ -1,13 +1,17 @@
1 1
 import org.junit.Test;
2 2
 import org.junit.Ignore;
3
+import org.junit.Rule;
4
+import org.junit.rules.ExpectedException;
3 5
 
4 6
 import static org.junit.Assert.assertEquals;
5 7
 
6 8
 public class TriangleTest {
7 9
 
10
+    @Rule
11
+    public final ExpectedException thrown = ExpectedException.none();
8 12
 
9 13
     @Test
10
-    public void equilateralTriangleHaveEqualSides() throws Exception {
14
+    public void equilateralTriangleHaveEqualSides() throws TriangleException {
11 15
         Triangle triangle = new Triangle(2, 2, 2);
12 16
 
13 17
         assertEquals(TriangleKind.EQUILATERAL, triangle.getKind());
@@ -15,7 +19,7 @@ public class TriangleTest {
15 19
 
16 20
     @Ignore
17 21
     @Test
18
-    public void largerEquilateralTrianglesAlsoHaveEqualSides() throws Exception {
22
+    public void largerEquilateralTrianglesAlsoHaveEqualSides() throws TriangleException {
19 23
         Triangle triangle = new Triangle(10, 10, 10);
20 24
 
21 25
         assertEquals(TriangleKind.EQUILATERAL, triangle.getKind());
@@ -23,7 +27,7 @@ public class TriangleTest {
23 27
 
24 28
     @Ignore
25 29
     @Test
26
-    public void isoscelesTrianglesHaveLastTwoSidesEqual() throws Exception {
30
+    public void isoscelesTrianglesHaveLastTwoSidesEqual() throws TriangleException {
27 31
         Triangle triangle = new Triangle(3, 4, 4);
28 32
 
29 33
         assertEquals(TriangleKind.ISOSCELES, triangle.getKind());
@@ -31,7 +35,7 @@ public class TriangleTest {
31 35
 
32 36
     @Ignore
33 37
     @Test
34
-    public void isoscelesTrianglesHaveFirstAndLastSidesEqual() throws Exception {
38
+    public void isoscelesTrianglesHaveFirstAndLastSidesEqual() throws TriangleException {
35 39
         Triangle triangle = new Triangle(4, 3, 4);
36 40
 
37 41
         assertEquals(TriangleKind.ISOSCELES, triangle.getKind());
@@ -39,7 +43,7 @@ public class TriangleTest {
39 43
 
40 44
     @Ignore
41 45
     @Test
42
-    public void isoscelesTrianglesHaveTwoFirstSidesEqual() throws Exception {
46
+    public void isoscelesTrianglesHaveTwoFirstSidesEqual() throws TriangleException {
43 47
         Triangle triangle = new Triangle(4, 4, 3);
44 48
 
45 49
         assertEquals(TriangleKind.ISOSCELES, triangle.getKind());
@@ -47,7 +51,7 @@ public class TriangleTest {
47 51
 
48 52
     @Ignore
49 53
     @Test
50
-    public void isoscelesTrianglesHaveInFactExactlyTwoSidesEqual() throws Exception {
54
+    public void isoscelesTrianglesHaveInFactExactlyTwoSidesEqual() throws TriangleException {
51 55
         Triangle triangle = new Triangle(10, 10, 2);
52 56
 
53 57
         assertEquals(TriangleKind.ISOSCELES, triangle.getKind());
@@ -55,7 +59,7 @@ public class TriangleTest {
55 59
 
56 60
     @Ignore
57 61
     @Test
58
-    public void scaleneTrianglesHaveNoEqualSides() throws Exception {
62
+    public void scaleneTrianglesHaveNoEqualSides() throws TriangleException {
59 63
         Triangle triangle = new Triangle(3, 4, 5);
60 64
 
61 65
         assertEquals(TriangleKind.SCALENE, triangle.getKind());
@@ -63,7 +67,7 @@ public class TriangleTest {
63 67
 
64 68
     @Ignore
65 69
     @Test
66
-    public void scaleneTrianglesHaveNoEqualSidesAtLargerScaleEither() throws Exception {
70
+    public void scaleneTrianglesHaveNoEqualSidesAtLargerScaleEither() throws TriangleException {
67 71
         Triangle triangle = new Triangle(10, 11, 12);
68 72
 
69 73
         assertEquals(TriangleKind.SCALENE, triangle.getKind());
@@ -71,7 +75,7 @@ public class TriangleTest {
71 75
 
72 76
     @Ignore
73 77
     @Test
74
-    public void scaleneTrianglesHaveNoEqualSidesInDescendingOrderEither() throws Exception {
78
+    public void scaleneTrianglesHaveNoEqualSidesInDescendingOrderEither() throws TriangleException {
75 79
         Triangle triangle = new Triangle(5, 4, 2);
76 80
 
77 81
         assertEquals(TriangleKind.SCALENE, triangle.getKind());
@@ -79,39 +83,44 @@ public class TriangleTest {
79 83
 
80 84
     @Ignore
81 85
     @Test
82
-    public void verySmallTrianglesAreLegal() throws Exception {
86
+    public void verySmallTrianglesAreLegal() throws TriangleException {
83 87
         Triangle triangle = new Triangle(0.4, 0.6, 0.3);
84 88
 
85 89
         assertEquals(TriangleKind.SCALENE, triangle.getKind());
86 90
     }
87 91
 
88 92
     @Ignore
89
-    @Test(expected = TriangleException.class)
90
-    public void trianglesWithNoSizeAreIllegal() throws Exception {
93
+    @Test
94
+    public void trianglesWithNoSizeAreIllegal() throws TriangleException {
95
+        thrown.expect(TriangleException.class);
91 96
         new Triangle(0, 0, 0);
92 97
     }
93 98
 
94 99
     @Ignore
95
-    @Test(expected = TriangleException.class)
96
-    public void trianglesWithNegativeSidesAreIllegal() throws Exception {
100
+    @Test
101
+    public void trianglesWithNegativeSidesAreIllegal() throws TriangleException {
102
+        thrown.expect(TriangleException.class);
97 103
         new Triangle(3, 4, -5);
98 104
     }
99 105
 
100 106
     @Ignore
101
-    @Test(expected = TriangleException.class)
102
-    public void trianglesViolatingTriangleInequalityAreIllegal() throws Exception {
107
+    @Test
108
+    public void trianglesViolatingTriangleInequalityAreIllegal() throws TriangleException {
109
+        thrown.expect(TriangleException.class);
103 110
         new Triangle(1, 1, 3);
104 111
     }
105 112
 
106 113
     @Ignore
107
-    @Test(expected = TriangleException.class)
108
-    public void trianglesViolatingTriangleInequalityAreIllegal2() throws Exception {
114
+    @Test
115
+    public void trianglesViolatingTriangleInequalityAreIllegal2() throws TriangleException {
116
+        thrown.expect(TriangleException.class);
109 117
         new Triangle(2, 4, 2);
110 118
     }
111 119
 
112 120
     @Ignore
113
-    @Test(expected = TriangleException.class)
114
-    public void trianglesViolatingTriangleInequalityAreIllegal3() throws Exception {
121
+    @Test
122
+    public void trianglesViolatingTriangleInequalityAreIllegal3() throws TriangleException {
123
+        thrown.expect(TriangleException.class);
115 124
         new Triangle(7, 3, 2);
116 125
     }
117 126
 }