CSVTools Tests

This commit is contained in:
sakimotor 2024-03-11 18:04:41 +01:00
parent 4db502c8ca
commit f37e5596f0

View file

@ -0,0 +1,76 @@
package fr.u_paris.gla.project.utils;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.util.Arrays;
import java.util.function.Consumer;
import java.util.stream.Stream;
import static org.junit.jupiter.api.Assertions.*;
class CSVToolsTest {
@Test
void readCSVFromURL_invalid() {
assertThrowsExactly(IOException.class,() -> {
Consumer<String[]> test = s -> System.out.println(Arrays.toString(s));
CSVTools.readCSVFromURL("https://google.fr",
test);
}
);
}
@Test
void readCSVFromURL_valid() {
assertDoesNotThrow(() -> {
Consumer<String[]> test = s -> System.out.println(Arrays.toString(s));
CSVTools.readCSVFromURL("https://people.sc.fsu.edu/~jburkardt/data/csv/addresses.csv",
test);
}
);
}
@Test
void writeCSVToFile() {
assertDoesNotThrow(() -> {
String[] stuff = {"jsqdsqdsqsqffdfgzava", "pfezegrrbeebn", "dfbsduifzegbczi", "sdfsdfcy"};
String[][] t = {stuff, stuff};
Stream<String[]> test = Arrays.stream(t);
CSVTools.writeCSVToFile("test.csv", test);
});
}
@Test
void writeCSVToFile_specialName() {
assertDoesNotThrow(() -> {
String[] stuff = {"jsqdsqdsqsqffdfgzava", "pfezegrrbeebn", "dfbsduifzegbczi", "sdfsdfcy"};
String[][] t = {stuff, stuff};
Stream<String[]> test = Arrays.stream(t);
CSVTools.writeCSVToFile("éè'-'_-éè_à.csv", test);
});
}
@Test
void writeCSVToFile_invalidName() {
assertThrows( IOException.class ,() -> {
String[] stuff = {"jsqdsqdsqsqffdfgzava", "pfezegrrbeebn", "dfbsduifzegbczi", "sdfsdfcy"};
String[][] t = {stuff, stuff};
Stream<String[]> test = Arrays.stream(t);
CSVTools.writeCSVToFile(".", test);
});
}
}