Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ FootballMatchReports.onField(10);
// => "striker"
```

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

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

```java
FootballMatchReports.onField(13);
// => Throw IllegalArgumentException
// => "invalid"
```
3 changes: 3 additions & 0 deletions exercises/concept/football-match-reports/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"authors": [
"Azumix"
],
"contributors": [
"AlvesJorge"
],
"files": {
"solution": [
"src/main/java/FootballMatchReports.java"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static String onField(int shirtNum) {
playerDescription = "striker";
break;
default:
throw new IllegalArgumentException();
playerDescription = "invalid";
}
return playerDescription;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

public class FootballMatchReportsTest {

Expand Down Expand Up @@ -68,17 +67,15 @@ public void test_right_wing() {

@Test
@Tag("task:2")
@DisplayName("The onField method throws IllegalArgumentException for unknown shirt number")
@DisplayName("The onField method returns 'invalid' for invalid shirt number")
public void test_exception() {
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> FootballMatchReports.onField(13));
assertThat(FootballMatchReports.onField(13)).isEqualTo("invalid");
}

@Test
@Tag("task:2")
@DisplayName("The onField method throws IllegalArgumentException for negative shirt number")
@DisplayName("The onField method returns 'invalid' for negative shirt number")
public void test_exception_negative_number() {
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> FootballMatchReports.onField(-1));
assertThat(FootballMatchReports.onField(-1)).isEqualTo("invalid");
}
}