mirror of
https://github.com/smyalygames/kahoot-challenge-2025.git
synced 2025-05-18 13:24:14 +02:00
feat(test): add tests for throws in ReadFile
This commit is contained in:
parent
a2ab2b3539
commit
b8b9d50541
49
app/src/test/java/ReadFileTest.java
Normal file
49
app/src/test/java/ReadFileTest.java
Normal file
@ -0,0 +1,49 @@
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@DisplayName("ReadFile class functions test")
|
||||
class ReadFileTest {
|
||||
|
||||
@TempDir
|
||||
static Path tempDir;
|
||||
|
||||
@Nested
|
||||
@DisplayName("Testing ReadFile `open()` function")
|
||||
class OpenTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("Empty file name in `filename` parameter")
|
||||
void emptyFileName() {
|
||||
assertThrowsExactly(IllegalArgumentException.class, () -> ReadFile.open(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Empty file name in `filename` parameter")
|
||||
void invalidFileExtension() throws IOException {
|
||||
// Create files with wrong file extensions
|
||||
Files.createFile(tempDir.resolve("emails.csv"));
|
||||
Files.createFile(tempDir.resolve("emails"));
|
||||
Files.createFile(tempDir.resolve("emails.xlsx"));
|
||||
Files.createFile(tempDir.resolve("emails.db"));
|
||||
|
||||
assertThrowsExactly(IllegalArgumentException.class, () -> ReadFile.open("emails.csv"));
|
||||
assertThrowsExactly(IllegalArgumentException.class, () -> ReadFile.open("emails"));
|
||||
assertThrowsExactly(IllegalArgumentException.class, () -> ReadFile.open("emails.xlsx"));
|
||||
assertThrowsExactly(IllegalArgumentException.class, () -> ReadFile.open("emails.db"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Trying to open non-existent file")
|
||||
void nonExistentFile() {
|
||||
assertThrowsExactly(RuntimeException.class, () -> ReadFile.open("doesNotExist.txt"));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user