feat(test): add tests for throws in ReadFile

This commit is contained in:
Anthony Berg 2024-10-16 23:22:11 +02:00
parent a2ab2b3539
commit b8b9d50541

View 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"));
}
}
}