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

Merge pull request #672 from exercism/exception-testing-info

Clean up exception-related hints
FridaTveit 9 лет назад
Родитель
Сommit
d4ebbc25d6

+ 0
- 4
exercises/all-your-base/src/test/java/BaseConverterTest.java Просмотреть файл

@@ -12,10 +12,6 @@ import static org.junit.Assert.assertArrayEquals;
12 12
  */
13 13
 public class BaseConverterTest {
14 14
 
15
-    /*
16
-     * See https://github.com/junit-team/junit4/wiki/Rules for information on JUnit Rules in general and
17
-     * ExpectedExceptions in particular.
18
-     */
19 15
     @Rule
20 16
     public ExpectedException expectedException = ExpectedException.none();
21 17
 

+ 0
- 4
exercises/change/src/test/java/ChangeCalculatorTest.java Просмотреть файл

@@ -10,10 +10,6 @@ import static org.junit.Assert.assertEquals;
10 10
 
11 11
 public class ChangeCalculatorTest {
12 12
 
13
-    /*
14
-     * See https://github.com/junit-team/junit4/wiki/Rules for information on JUnit Rules in general and
15
-     * ExpectedExceptions in particular.
16
-     */
17 13
     @Rule
18 14
     public ExpectedException expectedException = ExpectedException.none();
19 15
 

+ 12
- 0
exercises/hamming/HINTS.md Просмотреть файл

@@ -0,0 +1,12 @@
1
+## Hints
2
+
3
+This is the first exercise with tests that require you to throw an
4
+[`Exception`](https://docs.oracle.com/javase/8/docs/api/java/lang/Exception.html). `Exception`s are typically thrown to
5
+indicate that a program has encountered an unexpected input or state.
6
+
7
+We use JUnit's [`ExpectedException`](http://junit.org/junit4/javadoc/4.12/org/junit/rules/ExpectedException.html)
8
+[rule](https://github.com/junit-team/junit4/wiki/rules) throughout the track to verify that the exceptions you throw
9
+are:
10
+
11
+1. instances of a specified Java type;
12
+2. (optionally) initialized with a specified message.

+ 0
- 4
exercises/largest-series-product/src/test/java/LargestSeriesProductCalculatorTest.java Просмотреть файл

@@ -7,10 +7,6 @@ import static org.junit.Assert.assertEquals;
7 7
 
8 8
 public class LargestSeriesProductCalculatorTest {
9 9
 
10
-    /*
11
-     * See https://github.com/junit-team/junit4/wiki/Rules for information on JUnit Rules in general and
12
-     * ExpectedExceptions in particular.
13
-     */
14 10
     @Rule
15 11
     public ExpectedException expectedException = ExpectedException.none();
16 12
 

+ 4
- 4
exercises/nth-prime/src/test/java/PrimeCalculatorTest.java Просмотреть файл

@@ -10,14 +10,14 @@ import static org.junit.Assert.*;
10 10
 public class PrimeCalculatorTest {
11 11
     private PrimeCalculator primeCalculator;
12 12
 
13
+    @Rule
14
+    public ExpectedException expectedException = ExpectedException.none();
15
+
13 16
     @Before
14 17
     public void setup() {
15 18
         primeCalculator = new PrimeCalculator();
16 19
     }
17 20
 
18
-    @Rule
19
-    public ExpectedException thrown = ExpectedException.none();
20
-
21 21
     @Test
22 22
     public void testFirstPrime() {
23 23
         assertThat(primeCalculator.nth(1), is(2));
@@ -44,7 +44,7 @@ public class PrimeCalculatorTest {
44 44
     @Ignore("Remove to run test")
45 45
     @Test
46 46
     public void testUndefinedPrime() {
47
-        thrown.expect(IllegalArgumentException.class);
47
+        expectedException.expect(IllegalArgumentException.class);
48 48
         primeCalculator.nth(0);
49 49
     }
50 50
 

+ 3
- 3
exercises/nucleotide-count/src/test/java/NucleotideTest.java Просмотреть файл

@@ -11,8 +11,8 @@ import static org.junit.Assert.*;
11 11
 public class NucleotideTest {
12 12
 
13 13
     @Rule
14
-    public ExpectedException thrown = ExpectedException.none();
15
-    
14
+    public ExpectedException expectedException = ExpectedException.none();
15
+
16 16
     @Test
17 17
     public void testEmptyDnaStringHasNoAdenine() {
18 18
         DNA dna = new DNA("");
@@ -87,7 +87,7 @@ public class NucleotideTest {
87 87
     @Ignore("Remove to run test")
88 88
     @Test
89 89
     public void testValidatesNucleotides() {
90
-        thrown.expect(IllegalArgumentException.class);
90
+        expectedException.expect(IllegalArgumentException.class);
91 91
         DNA dna = new DNA("GACT");
92 92
         dna.count('X');
93 93
     }

+ 0
- 4
exercises/ocr-numbers/src/test/java/OpticalCharacterReaderTest.java Просмотреть файл

@@ -9,10 +9,6 @@ import static org.junit.Assert.assertEquals;
9 9
 
10 10
 public class OpticalCharacterReaderTest {
11 11
 
12
-    /*
13
-     * See https://github.com/junit-team/junit4/wiki/Rules for information on JUnit Rules in general and
14
-     * ExpectedExceptions in particular.
15
-     */
16 12
     @Rule
17 13
     public ExpectedException expectedException = ExpectedException.none();
18 14
 

+ 2
- 2
exercises/pascals-triangle/src/test/java/PascalsTriangleGeneratorTest.java Просмотреть файл

@@ -21,7 +21,7 @@ public class PascalsTriangleGeneratorTest {
21 21
     }
22 22
 
23 23
     @Rule
24
-    public ExpectedException thrown = ExpectedException.none();
24
+    public ExpectedException expectedException = ExpectedException.none();
25 25
 
26 26
     @Test
27 27
     public void testTriangleWithZeroRows() {
@@ -79,7 +79,7 @@ public class PascalsTriangleGeneratorTest {
79 79
     @Ignore("Remove to run test")
80 80
     @Test
81 81
     public void testValidatesNotNegativeRows() {
82
-        thrown.expect(IllegalArgumentException.class);
82
+        expectedException.expect(IllegalArgumentException.class);
83 83
         pascalsTriangleGenerator.generateTriangle(-1);
84 84
     }
85 85
 

+ 0
- 4
exercises/perfect-numbers/src/test/java/NaturalNumberTest.java Просмотреть файл

@@ -10,10 +10,6 @@ import static org.junit.Assert.assertEquals;
10 10
  */
11 11
 public class NaturalNumberTest {
12 12
 
13
-    /*
14
-     * See https://github.com/junit-team/junit4/wiki/Rules for information on JUnit Rules in general and
15
-     * ExpectedExceptions in particular.
16
-     */
17 13
     @Rule
18 14
     public ExpectedException expectedException = ExpectedException.none();
19 15
 

+ 0
- 4
exercises/queen-attack/src/test/java/QueenAttackCalculatorTest.java Просмотреть файл

@@ -8,10 +8,6 @@ import static org.junit.Assert.assertTrue;
8 8
 
9 9
 public class QueenAttackCalculatorTest {
10 10
 
11
-    /*
12
-     * See https://github.com/junit-team/junit4/wiki/Rules for information on JUnit Rules in general and
13
-     * ExpectedExceptions in particular.
14
-     */
15 11
     @Rule
16 12
     public ExpectedException expectedException = ExpectedException.none();
17 13
 

+ 4
- 4
exercises/series/src/test/java/SeriesTest.java Просмотреть файл

@@ -11,10 +11,10 @@ import static org.junit.Assert.assertFalse;
11 11
 import static org.junit.Assert.assertNotNull;
12 12
 
13 13
 public class SeriesTest {
14
-    
14
+
15 15
     @Rule
16
-    public ExpectedException thrown = ExpectedException.none();
17
-    
16
+    public ExpectedException expectedException = ExpectedException.none();
17
+
18 18
     @Test
19 19
     public void hasDigitsShort() {
20 20
         Series series = new Series("01234");
@@ -154,7 +154,7 @@ public class SeriesTest {
154 154
     @Test
155 155
     @Ignore("Remove to run test")
156 156
     public void throwsAnErrorIfNotEnoughDigitsToSlice() {
157
-        thrown.expect(IllegalArgumentException.class);
157
+        expectedException.expect(IllegalArgumentException.class);
158 158
         new Series("01032987583").slices(12);
159 159
     }
160 160
 }

+ 2
- 2
exercises/simple-linked-list/src/test/java/SimpleLinkedListTest.java Просмотреть файл

@@ -11,7 +11,7 @@ import static org.junit.Assert.*;
11 11
 public class SimpleLinkedListTest {
12 12
 
13 13
     @Rule
14
-    public ExpectedException thrown = ExpectedException.none();
14
+    public ExpectedException expectedException = ExpectedException.none();
15 15
 
16 16
     @Test
17 17
     public void aNewListIsEmpty() {
@@ -30,7 +30,7 @@ public class SimpleLinkedListTest {
30 30
     @Ignore("Remove to run test")
31 31
     @Test
32 32
     public void popOnEmptyListWillThrow() {
33
-        thrown.expect(NoSuchElementException.class);
33
+        expectedException.expect(NoSuchElementException.class);
34 34
         SimpleLinkedList list = new SimpleLinkedList();
35 35
         list.pop();
36 36
     }

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

@@ -8,7 +8,7 @@ import static org.junit.Assert.assertEquals;
8 8
 public class TriangleTest {
9 9
 
10 10
     @Rule
11
-    public final ExpectedException thrown = ExpectedException.none();
11
+    public ExpectedException expectedException = ExpectedException.none();
12 12
 
13 13
     @Test
14 14
     public void equilateralTrianglesHaveEqualSides() throws TriangleException {
@@ -92,35 +92,35 @@ public class TriangleTest {
92 92
     @Ignore("Remove to run test")
93 93
     @Test
94 94
     public void trianglesWithNoSizeAreIllegal() throws TriangleException {
95
-        thrown.expect(TriangleException.class);
95
+        expectedException.expect(TriangleException.class);
96 96
         new Triangle(0, 0, 0);
97 97
     }
98 98
 
99 99
     @Ignore("Remove to run test")
100 100
     @Test
101 101
     public void trianglesWithNegativeSidesAreIllegal() throws TriangleException {
102
-        thrown.expect(TriangleException.class);
102
+        expectedException.expect(TriangleException.class);
103 103
         new Triangle(3, 4, -5);
104 104
     }
105 105
 
106 106
     @Ignore("Remove to run test")
107 107
     @Test
108 108
     public void trianglesViolatingTriangleInequalityAreIllegal() throws TriangleException {
109
-        thrown.expect(TriangleException.class);
109
+        expectedException.expect(TriangleException.class);
110 110
         new Triangle(1, 1, 3);
111 111
     }
112 112
 
113 113
     @Ignore("Remove to run test")
114 114
     @Test
115 115
     public void trianglesViolatingTriangleInequalityAreIllegal2() throws TriangleException {
116
-        thrown.expect(TriangleException.class);
116
+        expectedException.expect(TriangleException.class);
117 117
         new Triangle(2, 4, 2);
118 118
     }
119 119
 
120 120
     @Ignore("Remove to run test")
121 121
     @Test
122 122
     public void trianglesViolatingTriangleInequalityAreIllegal3() throws TriangleException {
123
-        thrown.expect(TriangleException.class);
123
+        expectedException.expect(TriangleException.class);
124 124
         new Triangle(7, 3, 2);
125 125
     }
126 126
 }

+ 0
- 4
exercises/wordy/src/test/java/WordProblemSolverTest.java Просмотреть файл

@@ -8,10 +8,6 @@ import static org.junit.Assert.assertEquals;
8 8
 
9 9
 public class WordProblemSolverTest {
10 10
 
11
-    /*
12
-     * See https://github.com/junit-team/junit4/wiki/Rules for information on JUnit Rules in general and
13
-     * ExpectedExceptions in particular.
14
-     */
15 11
     @Rule
16 12
     public ExpectedException expectedException = ExpectedException.none();
17 13