From f37e5596f0396cfa7df1c637fa7294cb1db06bcf Mon Sep 17 00:00:00 2001 From: sakimotor Date: Mon, 11 Mar 2024 18:04:41 +0100 Subject: [PATCH] CSVTools Tests --- .../gla/project/utils/CSVToolsTest.java | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 src/test/java/fr/u_paris/gla/project/utils/CSVToolsTest.java diff --git a/src/test/java/fr/u_paris/gla/project/utils/CSVToolsTest.java b/src/test/java/fr/u_paris/gla/project/utils/CSVToolsTest.java new file mode 100644 index 0000000..6ab4895 --- /dev/null +++ b/src/test/java/fr/u_paris/gla/project/utils/CSVToolsTest.java @@ -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 test = s -> System.out.println(Arrays.toString(s)); + CSVTools.readCSVFromURL("https://google.fr", + test); + + } + ); + } + + @Test + void readCSVFromURL_valid() { + assertDoesNotThrow(() -> { + Consumer 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 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 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 test = Arrays.stream(t); + CSVTools.writeCSVToFile(".", test); + + }); + } +} \ No newline at end of file