mirror of
https://github.com/smyalygames/kahoot-challenge-2025.git
synced 2026-01-13 15:39:10 +01:00
feat(test): add invalid path test
This commit is contained in:
@@ -1,6 +1,4 @@
|
|||||||
import java.io.File;
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.nio.file.InvalidPathException;
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -22,10 +20,7 @@ public class ReadFile {
|
|||||||
try {
|
try {
|
||||||
// Open the file that was defined
|
// Open the file that was defined
|
||||||
reader = new Scanner(path.toFile());
|
reader = new Scanner(path.toFile());
|
||||||
} catch (InvalidPathException e) {
|
} catch (FileNotFoundException e) {
|
||||||
throw new RuntimeException("Could not find the file: " + e);
|
|
||||||
}
|
|
||||||
catch (FileNotFoundException e) {
|
|
||||||
throw new RuntimeException("Could not open the file: " + e);
|
throw new RuntimeException("Could not open the file: " + e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,14 @@ class ReadFileTest {
|
|||||||
assertThrowsExactly(RuntimeException.class, () -> ReadFile.open(nonExistent));
|
assertThrowsExactly(RuntimeException.class, () -> ReadFile.open(nonExistent));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Testing for an invalid path")
|
||||||
|
void invalidPath() {
|
||||||
|
Path invalid = Path.of("//invalid.txt");
|
||||||
|
|
||||||
|
assertThrowsExactly(RuntimeException.class, () -> ReadFile.open(invalid));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Reading valid file correctly")
|
@DisplayName("Reading valid file correctly")
|
||||||
void openValidFile() throws IOException {
|
void openValidFile() throws IOException {
|
||||||
|
|||||||
Reference in New Issue
Block a user