Adding files for Exception Handling article (#4507)

* Adding files for Exception Handling article

* Updating files

* Test folder

* testing renaming

* Formatting and Naming Conventions

This commit reworks the code for the Intro to Exception Handling
article, ensuring that packages and classes are formatted and named
according to site standards.
This commit is contained in:
DavidLandup
2018-08-01 19:59:16 +02:00
committed by Josh Cummings
parent 815f655f36
commit 0b642f91e0
7 changed files with 342 additions and 0 deletions
@@ -0,0 +1,86 @@
package com.baeldung.exceptionhandling;
import org.junit.Test;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.NoSuchFileException;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
public class ExceptionsUnitTest {
Exceptions exceptions = new Exceptions();
@Test
public void getPlayers() {
assertThatThrownBy(() -> exceptions.getPlayers())
.isInstanceOf(NoSuchFileException.class);
}
@Test
public void loadAllPlayers() {
assertThatThrownBy(() -> exceptions.loadAllPlayers(""))
.isInstanceOf(IOException.class);
}
@Test
public void getPlayerScoreThrows() {
assertThatThrownBy(() -> exceptions.getPlayerScoreThrows(""))
.isInstanceOf(FileNotFoundException.class);
}
@Test
public void getPlayerScoreTryCatch() {
assertThatThrownBy(() -> exceptions.getPlayerScoreTryCatch(""))
.isInstanceOf(IllegalArgumentException.class);
}
@Test
public void getPlayerScoreFinally() {
assertThatThrownBy(() -> exceptions.getPlayerScoreFinally(""))
.isInstanceOf(FileNotFoundException.class);
}
@Test
public void loadAllPlayersThrowingChecked() {
assertThatThrownBy(() -> exceptions.loadAllPlayersThrowingChecked(""))
.isInstanceOf(TimeoutException.class);
}
@Test
public void loadAllPlayersThrowingUnchecked() {
assertThatThrownBy(() -> exceptions.loadAllPlayersThrowingUnchecked(""))
.isInstanceOf(IllegalArgumentException.class);
}
@Test
public void loadAllPlayersWrapping() {
assertThatThrownBy(() -> exceptions.loadAllPlayersWrapping(""))
.isInstanceOf(IOException.class);
}
@Test
public void loadAllPlayersRethrowing() {
assertThatThrownBy(() -> exceptions.loadAllPlayersRethrowing(""))
.isInstanceOf(PlayerLoadException.class);
}
@Test
public void loadAllPlayersThrowable() {
assertThatThrownBy(() -> exceptions.loadAllPlayersThrowable(""))
.isInstanceOf(NullPointerException.class);
}
@Test
public void throwAsGotoAntiPattern() {
assertThatThrownBy(() -> exceptions.throwAsGotoAntiPattern())
.isInstanceOf(MyException.class);
}
@Test
public void getPlayerScoreSwallowingExceptionAntiPatternAlternative2() {
assertThatThrownBy(() -> exceptions.getPlayerScoreSwallowingExceptionAntiPatternAlternative2(""))
.isInstanceOf(PlayerScoreException.class);
}
}