Bladeren bron

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

Clean up exception-related hints
FridaTveit 9 jaren geleden
bovenliggende
commit
d4ebbc25d6

+ 0
- 4
exercises/all-your-base/src/test/java/BaseConverterTest.java Bestand weergeven

12
  */
12
  */
13
 public class BaseConverterTest {
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
     @Rule
15
     @Rule
20
     public ExpectedException expectedException = ExpectedException.none();
16
     public ExpectedException expectedException = ExpectedException.none();
21
 
17
 

+ 0
- 4
exercises/change/src/test/java/ChangeCalculatorTest.java Bestand weergeven

10
 
10
 
11
 public class ChangeCalculatorTest {
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
     @Rule
13
     @Rule
18
     public ExpectedException expectedException = ExpectedException.none();
14
     public ExpectedException expectedException = ExpectedException.none();
19
 
15
 

+ 12
- 0
exercises/hamming/HINTS.md Bestand weergeven

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 Bestand weergeven

7
 
7
 
8
 public class LargestSeriesProductCalculatorTest {
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
     @Rule
10
     @Rule
15
     public ExpectedException expectedException = ExpectedException.none();
11
     public ExpectedException expectedException = ExpectedException.none();
16
 
12
 

+ 4
- 4
exercises/nth-prime/src/test/java/PrimeCalculatorTest.java Bestand weergeven

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

+ 3
- 3
exercises/nucleotide-count/src/test/java/NucleotideTest.java Bestand weergeven

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

+ 0
- 4
exercises/ocr-numbers/src/test/java/OpticalCharacterReaderTest.java Bestand weergeven

9
 
9
 
10
 public class OpticalCharacterReaderTest {
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
     @Rule
12
     @Rule
17
     public ExpectedException expectedException = ExpectedException.none();
13
     public ExpectedException expectedException = ExpectedException.none();
18
 
14
 

+ 2
- 2
exercises/pascals-triangle/src/test/java/PascalsTriangleGeneratorTest.java Bestand weergeven

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

+ 0
- 4
exercises/perfect-numbers/src/test/java/NaturalNumberTest.java Bestand weergeven

10
  */
10
  */
11
 public class NaturalNumberTest {
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
     @Rule
13
     @Rule
18
     public ExpectedException expectedException = ExpectedException.none();
14
     public ExpectedException expectedException = ExpectedException.none();
19
 
15
 

+ 0
- 4
exercises/queen-attack/src/test/java/QueenAttackCalculatorTest.java Bestand weergeven

8
 
8
 
9
 public class QueenAttackCalculatorTest {
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
     @Rule
11
     @Rule
16
     public ExpectedException expectedException = ExpectedException.none();
12
     public ExpectedException expectedException = ExpectedException.none();
17
 
13
 

+ 4
- 4
exercises/series/src/test/java/SeriesTest.java Bestand weergeven

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

+ 2
- 2
exercises/simple-linked-list/src/test/java/SimpleLinkedListTest.java Bestand weergeven

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

+ 6
- 6
exercises/triangle/src/test/java/TriangleTest.java Bestand weergeven

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

+ 0
- 4
exercises/wordy/src/test/java/WordProblemSolverTest.java Bestand weergeven

8
 
8
 
9
 public class WordProblemSolverTest {
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
     @Rule
11
     @Rule
16
     public ExpectedException expectedException = ExpectedException.none();
12
     public ExpectedException expectedException = ExpectedException.none();
17
 
13