Skip to content

Commit 8546141

Browse files
committed
fix exceptions tests
1 parent 53d9f14 commit 8546141

2 files changed

Lines changed: 13 additions & 9 deletions

File tree

‎core-java/src/main/java/com/baeldung/exceptionhandling/Exceptions.java‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ public static List<Player> getPlayers() throws IOException {
2525
}
2626

2727
public List<Player> loadAllPlayers(String playersFile) throws IOException{
28-
throw new IOException();
28+
try {
29+
throw new IOException();
30+
} catch(IOException ex) {
31+
throw new IllegalStateException();
32+
}
2933
}
3034

3135
public int getPlayerScoreThrows(String playerFile) throws FileNotFoundException {
@@ -160,7 +164,13 @@ public List<Player> loadAllPlayers(String playersFile) { //can't add "throws My
160164
}
161165

162166
public void throwAsGotoAntiPattern() throws MyException {
163-
throw new MyException();
167+
try {
168+
// bunch of code
169+
throw new MyException();
170+
// second bunch of code
171+
} catch ( MyException e ) {
172+
// third bunch of code
173+
}
164174
}
165175

166176
public int getPlayerScoreSwallowingExceptionAntiPattern(String playerFile) {

‎core-java/src/test/java/com/baeldung/exceptionhandling/ExceptionsUnitTest.java‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public void getPlayers() {
2121
@Test
2222
public void loadAllPlayers() {
2323
assertThatThrownBy(() -> exceptions.loadAllPlayers(""))
24-
.isInstanceOf(IOException.class);
24+
.isInstanceOf(IllegalStateException.class);
2525
}
2626

2727
@Test
@@ -72,12 +72,6 @@ public void loadAllPlayersThrowable() {
7272
.isInstanceOf(NullPointerException.class);
7373
}
7474

75-
@Test
76-
public void throwAsGotoAntiPattern() {
77-
assertThatThrownBy(() -> exceptions.throwAsGotoAntiPattern())
78-
.isInstanceOf(MyException.class);
79-
}
80-
8175
@Test
8276
public void getPlayerScoreSwallowingExceptionAntiPatternAlternative2() {
8377
assertThatThrownBy(() -> exceptions.getPlayerScoreSwallowingExceptionAntiPatternAlternative2(""))

0 commit comments

Comments
 (0)