Skip to content

Commit c2165cb

Browse files
authored
Remove exceptions from Football Match Reports exercise (#3020)
Exceptions is a separate concept and it has a dependency on switch, which is covered in Football Match Reports. Removing exception reduces the number of dependencies that Football Match Reports has and breaks this dependency cycle. Adding this to prevent rerun over existing community solutions [no important files changed]
1 parent 9e7e8ba commit c2165cb

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

exercises/concept/football-match-reports/.docs/instructions.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ FootballMatchReports.onField(10);
2727
// => "striker"
2828
```
2929

30-
## 2. Raise an alert if an unknown shirt number is encountered
30+
## 2. Output "invalid" if the shirt number is not part of the official list
3131

32-
Modify the `FootballMatchReports.onField()` method to throw an `IllegalArgumentException` when a shirt number outside the range 1-11 is processed.
32+
Modify the `FootballMatchReports.onField()` method to return 'invalid' when a shirt number outside the range 1-11 is processed.
3333

3434
```java
3535
FootballMatchReports.onField(13);
36-
// => Throw IllegalArgumentException
36+
// => "invalid"
3737
```

exercises/concept/football-match-reports/.meta/config.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
"authors": [
33
"Azumix"
44
],
5+
"contributors": [
6+
"AlvesJorge"
7+
],
58
"files": {
69
"solution": [
710
"src/main/java/FootballMatchReports.java"

exercises/concept/football-match-reports/.meta/src/reference/java/FootballMatchReports.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static String onField(int shirtNum) {
3030
playerDescription = "striker";
3131
break;
3232
default:
33-
throw new IllegalArgumentException();
33+
playerDescription = "invalid";
3434
}
3535
return playerDescription;
3636
}

exercises/concept/football-match-reports/src/test/java/FootballMatchReportsTest.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import org.junit.jupiter.api.Test;
44

55
import static org.assertj.core.api.Assertions.assertThat;
6-
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
76

87
public class FootballMatchReportsTest {
98

@@ -68,17 +67,15 @@ public void test_right_wing() {
6867

6968
@Test
7069
@Tag("task:2")
71-
@DisplayName("The onField method throws IllegalArgumentException for unknown shirt number")
70+
@DisplayName("The onField method returns 'invalid' for invalid shirt number")
7271
public void test_exception() {
73-
assertThatExceptionOfType(IllegalArgumentException.class)
74-
.isThrownBy(() -> FootballMatchReports.onField(13));
72+
assertThat(FootballMatchReports.onField(13)).isEqualTo("invalid");
7573
}
7674

7775
@Test
7876
@Tag("task:2")
79-
@DisplayName("The onField method throws IllegalArgumentException for negative shirt number")
77+
@DisplayName("The onField method returns 'invalid' for negative shirt number")
8078
public void test_exception_negative_number() {
81-
assertThatExceptionOfType(IllegalArgumentException.class)
82-
.isThrownBy(() -> FootballMatchReports.onField(-1));
79+
assertThat(FootballMatchReports.onField(-1)).isEqualTo("invalid");
8380
}
8481
}

0 commit comments

Comments
 (0)