mirror of
https://github.com/smyalygames/kahoot-challenge-2025.git
synced 2025-05-18 15:04:14 +02:00
feat(test): add invalid path test
This commit is contained in:
parent
c60ac6227c
commit
09404b84d0
@ -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 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user