Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up exception-related hints #672

Merged
merged 1 commit into from
Jul 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions exercises/all-your-base/src/test/java/BaseConverterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
*/
public class BaseConverterTest {

/*
* See https://github.com/junit-team/junit4/wiki/Rules for information on JUnit Rules in general and
* ExpectedExceptions in particular.
*/
@Rule
public ExpectedException expectedException = ExpectedException.none();

Expand Down
4 changes: 0 additions & 4 deletions exercises/change/src/test/java/ChangeCalculatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@

public class ChangeCalculatorTest {

/*
* See https://github.com/junit-team/junit4/wiki/Rules for information on JUnit Rules in general and
* ExpectedExceptions in particular.
*/
@Rule
public ExpectedException expectedException = ExpectedException.none();

Expand Down
12 changes: 12 additions & 0 deletions exercises/hamming/HINTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## Hints

This is the first exercise with tests that require you to throw an
[`Exception`](https://docs.oracle.com/javase/8/docs/api/java/lang/Exception.html). `Exception`s are typically thrown to
indicate that a program has encountered an unexpected input or state.

We use JUnit's [`ExpectedException`](http://junit.org/junit4/javadoc/4.12/org/junit/rules/ExpectedException.html)
[rule](https://github.com/junit-team/junit4/wiki/rules) throughout the track to verify that the exceptions you throw
are:

1. instances of a specified Java type;
2. (optionally) initialized with a specified message.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@

public class LargestSeriesProductCalculatorTest {

/*
* See https://github.com/junit-team/junit4/wiki/Rules for information on JUnit Rules in general and
* ExpectedExceptions in particular.
*/
@Rule
public ExpectedException expectedException = ExpectedException.none();

Expand Down
8 changes: 4 additions & 4 deletions exercises/nth-prime/src/test/java/PrimeCalculatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
public class PrimeCalculatorTest {
private PrimeCalculator primeCalculator;

@Rule
public ExpectedException expectedException = ExpectedException.none();

@Before
public void setup() {
primeCalculator = new PrimeCalculator();
}

@Rule
public ExpectedException thrown = ExpectedException.none();

@Test
public void testFirstPrime() {
assertThat(primeCalculator.nth(1), is(2));
Expand All @@ -44,7 +44,7 @@ public void testBigPrime() {
@Ignore("Remove to run test")
@Test
public void testUndefinedPrime() {
thrown.expect(IllegalArgumentException.class);
expectedException.expect(IllegalArgumentException.class);
primeCalculator.nth(0);
}

Expand Down
6 changes: 3 additions & 3 deletions exercises/nucleotide-count/src/test/java/NucleotideTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
public class NucleotideTest {

@Rule
public ExpectedException thrown = ExpectedException.none();
public ExpectedException expectedException = ExpectedException.none();

@Test
public void testEmptyDnaStringHasNoAdenine() {
DNA dna = new DNA("");
Expand Down Expand Up @@ -87,7 +87,7 @@ public void testDnaCountsDoNotChangeAfterCountingAdenine() {
@Ignore("Remove to run test")
@Test
public void testValidatesNucleotides() {
thrown.expect(IllegalArgumentException.class);
expectedException.expect(IllegalArgumentException.class);
DNA dna = new DNA("GACT");
dna.count('X');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@

public class OpticalCharacterReaderTest {

/*
* See https://github.com/junit-team/junit4/wiki/Rules for information on JUnit Rules in general and
* ExpectedExceptions in particular.
*/
@Rule
public ExpectedException expectedException = ExpectedException.none();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void setUp() {
}

@Rule
public ExpectedException thrown = ExpectedException.none();
public ExpectedException expectedException = ExpectedException.none();

@Test
public void testTriangleWithZeroRows() {
Expand Down Expand Up @@ -79,7 +79,7 @@ public void testTriangleWithFourRows() {
@Ignore("Remove to run test")
@Test
public void testValidatesNotNegativeRows() {
thrown.expect(IllegalArgumentException.class);
expectedException.expect(IllegalArgumentException.class);
pascalsTriangleGenerator.generateTriangle(-1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
*/
public class NaturalNumberTest {

/*
* See https://github.com/junit-team/junit4/wiki/Rules for information on JUnit Rules in general and
* ExpectedExceptions in particular.
*/
@Rule
public ExpectedException expectedException = ExpectedException.none();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@

public class QueenAttackCalculatorTest {

/*
* See https://github.com/junit-team/junit4/wiki/Rules for information on JUnit Rules in general and
* ExpectedExceptions in particular.
*/
@Rule
public ExpectedException expectedException = ExpectedException.none();

Expand Down
8 changes: 4 additions & 4 deletions exercises/series/src/test/java/SeriesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
import static org.junit.Assert.assertNotNull;

public class SeriesTest {

@Rule
public ExpectedException thrown = ExpectedException.none();
public ExpectedException expectedException = ExpectedException.none();

@Test
public void hasDigitsShort() {
Series series = new Series("01234");
Expand Down Expand Up @@ -154,7 +154,7 @@ public void canSliceByFive() {
@Test
@Ignore("Remove to run test")
public void throwsAnErrorIfNotEnoughDigitsToSlice() {
thrown.expect(IllegalArgumentException.class);
expectedException.expect(IllegalArgumentException.class);
new Series("01032987583").slices(12);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public class SimpleLinkedListTest {

@Rule
public ExpectedException thrown = ExpectedException.none();
public ExpectedException expectedException = ExpectedException.none();

@Test
public void aNewListIsEmpty() {
Expand All @@ -30,7 +30,7 @@ public void canCreateFromArray() {
@Ignore("Remove to run test")
@Test
public void popOnEmptyListWillThrow() {
thrown.expect(NoSuchElementException.class);
expectedException.expect(NoSuchElementException.class);
SimpleLinkedList list = new SimpleLinkedList();
list.pop();
}
Expand Down
12 changes: 6 additions & 6 deletions exercises/triangle/src/test/java/TriangleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
public class TriangleTest {

@Rule
public final ExpectedException thrown = ExpectedException.none();
public ExpectedException expectedException = ExpectedException.none();

@Test
public void equilateralTrianglesHaveEqualSides() throws TriangleException {
Expand Down Expand Up @@ -92,35 +92,35 @@ public void verySmallTrianglesAreLegal() throws TriangleException {
@Ignore("Remove to run test")
@Test
public void trianglesWithNoSizeAreIllegal() throws TriangleException {
thrown.expect(TriangleException.class);
expectedException.expect(TriangleException.class);
new Triangle(0, 0, 0);
}

@Ignore("Remove to run test")
@Test
public void trianglesWithNegativeSidesAreIllegal() throws TriangleException {
thrown.expect(TriangleException.class);
expectedException.expect(TriangleException.class);
new Triangle(3, 4, -5);
}

@Ignore("Remove to run test")
@Test
public void trianglesViolatingTriangleInequalityAreIllegal() throws TriangleException {
thrown.expect(TriangleException.class);
expectedException.expect(TriangleException.class);
new Triangle(1, 1, 3);
}

@Ignore("Remove to run test")
@Test
public void trianglesViolatingTriangleInequalityAreIllegal2() throws TriangleException {
thrown.expect(TriangleException.class);
expectedException.expect(TriangleException.class);
new Triangle(2, 4, 2);
}

@Ignore("Remove to run test")
@Test
public void trianglesViolatingTriangleInequalityAreIllegal3() throws TriangleException {
thrown.expect(TriangleException.class);
expectedException.expect(TriangleException.class);
new Triangle(7, 3, 2);
}
}
4 changes: 0 additions & 4 deletions exercises/wordy/src/test/java/WordProblemSolverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@

public class WordProblemSolverTest {

/*
* See https://github.com/junit-team/junit4/wiki/Rules for information on JUnit Rules in general and
* ExpectedExceptions in particular.
*/
@Rule
public ExpectedException expectedException = ExpectedException.none();

Expand Down