@@ -201,4 +201,56 @@ private static Stream<Arguments> testReadFileFromWebSource() { return Stream.of(
201
201
"message": "100%",
202
202
"color": "00FF00"
203
203
}""" ), Arguments .of (null , false , null ), Arguments .of ("h://unexisting.url" , false , null )); }
204
+
205
+ @ ParameterizedTest
206
+ @ MethodSource ("testWriteFileSource" )
207
+ void testWriteFile (String path , boolean shouldWork , String content ) {
208
+ assertEquals (shouldWork , FLUFiles .writeFile (path , content ));
209
+ if (shouldWork ) {
210
+ assertEquals (content , FLUFiles .readFile (path ));
211
+ assertEquals (true , FLUFiles .delete (path ));
212
+ }
213
+ }
214
+
215
+ private static Stream <Arguments > testWriteFileSource () {
216
+ return Stream .of (Arguments .of (TEST_PATH_TEMPORARY + "testWriteFile1.txt" , true , "Some content." ),
217
+ Arguments .of (TEST_PATH_TEMPORARY + "testWriteFile2.txt" , true , "Some content." ),
218
+ Arguments .of (TEST_PATH_TEMPORARY + "éà@--" , true , "Some content." ), Arguments .of (null , false , "Some vyzemjzefze" ),
219
+ Arguments .of (TEST_PATH_TEMPORARY + "DIR/2/out.in" , true , "Some content" ),
220
+ Arguments .of (TEST_PATH_TEMPORARY + "existingFile2" , true , "Some content" ));
221
+ }
222
+
223
+ @ ParameterizedTest
224
+ @ MethodSource ("testAppendToFileSource" )
225
+ void testAppendToFile (String path , boolean shouldWork , String contentToWrite , String expectedContent ) {
226
+ assertEquals (shouldWork , FLUFiles .appendToFile (path , contentToWrite ));
227
+ if (shouldWork ) {
228
+ assertEquals (expectedContent , FLUFiles .readFile (path ));
229
+ assertEquals (true , FLUFiles .delete (path ));
230
+ }
231
+ }
232
+
233
+ private static Stream <Arguments > testAppendToFileSource () {
234
+ return Stream .of (Arguments .of (TEST_PATH_TEMPORARY + "testAppendToFile1.txt" , true , "Some content." , "Some content." ),
235
+ Arguments .of (TEST_PATH_TEMPORARY + "testAppendToFile2.txt" , true , "Some content." , "Some content." ),
236
+ Arguments .of (TEST_PATH_TEMPORARY + "éà@--" , true , "Some content." , "Some content." ),
237
+ Arguments .of (null , false , "Some vyzemjzefze" , "" ));
238
+ }
239
+
240
+ @ ParameterizedTest
241
+ @ MethodSource ("testAppendToExistingFileFileSource" )
242
+ void testAppendToExistingFile (String path , boolean shouldWork , String contentToWrite , String expectedContent , String copyPath ) {
243
+ assertEquals (true , FLUFiles .copy (path , copyPath ));
244
+ assertEquals (shouldWork , FLUFiles .appendToFile (copyPath , contentToWrite ));
245
+ if (shouldWork ) {
246
+ assertEquals (expectedContent , FLUFiles .readFile (copyPath ));
247
+ }
248
+ }
249
+
250
+ private static Stream <Arguments > testAppendToExistingFileFileSource () {
251
+ return Stream .of (
252
+ Arguments .of (TEST_PATH + "existingFile3" , true , "Some content" , "ABCSome content" , TEST_PATH_TEMPORARY + "existingFile3" ),
253
+ Arguments .of (TEST_PATH + "existingFile4" , true , "Some content" , "ABC\n Some content" ,
254
+ TEST_PATH_TEMPORARY + "existingFile4" ));
255
+ }
204
256
}
0 commit comments