|
1 | 1 | package fr.formiko.utils;
|
2 | 2 |
|
3 | 3 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
| 4 | +import static org.junit.jupiter.api.Assertions.assertNull; |
4 | 5 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
5 | 6 | import java.io.File;
|
| 7 | +import java.util.List; |
6 | 8 | import java.util.stream.Stream;
|
7 | 9 | import org.junit.jupiter.api.AfterAll;
|
8 | 10 | import org.junit.jupiter.api.BeforeAll;
|
@@ -139,4 +141,44 @@ private static Stream<Arguments> testMoveDirectorySource() {
|
139 | 141 | return Stream.of(
|
140 | 142 | Arguments.of(TEST_PATH + "existingDir/", true, TEST_PATH_TEMPORARY + "moveOfTestResources/", "subDir/existingFile.txt"));
|
141 | 143 | }
|
| 144 | + |
| 145 | + @ParameterizedTest |
| 146 | + @MethodSource("testReadFileSource") |
| 147 | + void testReadFile(String path, boolean shouldWork, String content) { |
| 148 | + if (shouldWork) { |
| 149 | + assertEquals(content, FLUFiles.readFile(path)); |
| 150 | + } else { |
| 151 | + assertNull(FLUFiles.readFile(path)); |
| 152 | + } |
| 153 | + } |
| 154 | + |
| 155 | + private static Stream<Arguments> testReadFileSource() { |
| 156 | + return Stream.of(Arguments.of(TEST_PATH + "existingFile.x", true, "Some content."), |
| 157 | + Arguments.of(TEST_PATH + "unexistingFile.x", false, null), Arguments.of(null, false, null), |
| 158 | + Arguments.of(TEST_PATH + "existingDir/subDir/", false, null), |
| 159 | + Arguments.of(TEST_PATH + "existingDir/subDir/existingFile.txt", true, "ipnzéfl\n" + // |
| 160 | + "zgrebinoa\n" + // |
| 161 | + "rez bzn,\n")); |
| 162 | + } |
| 163 | + |
| 164 | + @ParameterizedTest |
| 165 | + @MethodSource("testReadFileAsListSource") |
| 166 | + void testWriteFile(String path, boolean shouldWork, List<String> content) { |
| 167 | + if (shouldWork) { |
| 168 | + List<String> list = FLUFiles.readFileAsList(path); |
| 169 | + assertEquals(content.size(), list.size()); |
| 170 | + for (int i = 0; i < content.size(); i++) { |
| 171 | + assertEquals(content.get(i), list.get(i)); |
| 172 | + } |
| 173 | + } else { |
| 174 | + assertNull(FLUFiles.readFileAsList(path)); |
| 175 | + } |
| 176 | + } |
| 177 | + |
| 178 | + private static Stream<Arguments> testReadFileAsListSource() { |
| 179 | + return Stream.of(Arguments.of(TEST_PATH + "existingFile.x", true, List.of("Some content.")), |
| 180 | + Arguments.of(TEST_PATH + "unexistingFile.x", false, null), Arguments.of(null, false, null), |
| 181 | + Arguments.of(TEST_PATH + "existingDir/subDir/", false, null), |
| 182 | + Arguments.of(TEST_PATH + "existingDir/subDir/existingFile.txt", true, List.of("ipnzéfl", "zgrebinoa", "rez bzn,"))); |
| 183 | + } |
142 | 184 | }
|
0 commit comments