Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 "unknown" 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 'unknown' when a shirt number outside the range 1-11 is processed.

```java
FootballMatchReports.onField(13);
// => Throw IllegalArgumentException
// => "unknown"
```
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 'unknown' for unknown shirt number")
public void test_exception() {
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> FootballMatchReports.onField(13));
assertThat(FootballMatchReports.onField(13)).isEqualTo("unknown");
}

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