|
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()); |
14 | 18 | } |
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()); |
22 | 26 | } |
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()); |
30 | 34 | } |
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()); |
38 | 42 | } |
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()); |
46 | 50 | } |
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()); |
54 | 58 | } |
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()); |
62 | 66 | } |
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()); |
70 | 74 | } |
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()); |
78 | 82 | } |
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 | } |
0 commit comments