File tree Expand file tree Collapse file tree 4 files changed +11
-11
lines changed Expand file tree Collapse file tree 4 files changed +11
-11
lines changed Original file line number Diff line number Diff line change @@ -27,11 +27,11 @@ FootballMatchReports.onField(10);
27
27
// => "striker"
28
28
```
29
29
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
31
31
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.
33
33
34
34
``` java
35
35
FootballMatchReports . onField(13 );
36
- // => Throw IllegalArgumentException
36
+ // => "invalid"
37
37
```
Original file line number Diff line number Diff line change 2
2
"authors" : [
3
3
" Azumix"
4
4
],
5
+ "contributors" : [
6
+ " AlvesJorge"
7
+ ],
5
8
"files" : {
6
9
"solution" : [
7
10
" src/main/java/FootballMatchReports.java"
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ public static String onField(int shirtNum) {
30
30
playerDescription = "striker" ;
31
31
break ;
32
32
default :
33
- throw new IllegalArgumentException () ;
33
+ playerDescription = "invalid" ;
34
34
}
35
35
return playerDescription ;
36
36
}
Original file line number Diff line number Diff line change 3
3
import org .junit .jupiter .api .Test ;
4
4
5
5
import static org .assertj .core .api .Assertions .assertThat ;
6
- import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
7
6
8
7
public class FootballMatchReportsTest {
9
8
@@ -68,17 +67,15 @@ public void test_right_wing() {
68
67
69
68
@ Test
70
69
@ 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" )
72
71
public void test_exception () {
73
- assertThatExceptionOfType (IllegalArgumentException .class )
74
- .isThrownBy (() -> FootballMatchReports .onField (13 ));
72
+ assertThat (FootballMatchReports .onField (13 )).isEqualTo ("invalid" );
75
73
}
76
74
77
75
@ Test
78
76
@ 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" )
80
78
public void test_exception_negative_number () {
81
- assertThatExceptionOfType (IllegalArgumentException .class )
82
- .isThrownBy (() -> FootballMatchReports .onField (-1 ));
79
+ assertThat (FootballMatchReports .onField (-1 )).isEqualTo ("invalid" );
83
80
}
84
81
}
You can’t perform that action at this time.
0 commit comments