BAEL-5767: Writing an ArrayList of Strings into a Text File (#12783)
* Deep vs Shallow copy of an object in java * update indentaions * Create a BMI Caclualtor in Java * Create a BMI Caclualtor in Java * Delete unused packages * BAEL-5708: Create a BMI Calculator in Java * BAEL-5708: Create a BMI Calculator in Java * BAEL-5767:Writing an ArrayList of Strings into a Text File * BAEL-5767:Writing an ArrayList of Strings into a Text File * Deleting files from core-java-io * BAEL-5767: Writing an ArrayList of Strings into a Text File * Removed files from core-java-11-2 * BAEL-5767:Writing an ArrayList of Strings into a Text File * BAEL-5767:Writing an ArrayList of Strings into a Text File * BAEL-5767:Writing an ArrayList of Strings into a Text File
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package com.baeldung.filewriter;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class BufferedWriterUnitTest {
|
||||
|
||||
private static final List<String> stringList = Arrays.asList("Hello", "World");
|
||||
|
||||
@Test
|
||||
public void givenUsingBufferedWriter_whenStringList_thenGetTextFile() throws IOException {
|
||||
String fileName = BufferedWriterExample.generateFileFromStringList(stringList);
|
||||
long count = Files.lines(Paths.get(fileName)).count();
|
||||
assertTrue("No. of lines in file should be equal to no. of Strings in List", ((int) count) == stringList.size());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.baeldung.filewriter;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
|
||||
public class FileWriteStringUnitTest {
|
||||
|
||||
private static final List<String> stringList = Arrays.asList("Hello", "World");
|
||||
|
||||
@Test
|
||||
public void givenUsingFileWriteString_whenStringList_thenGetTextFile() throws IOException {
|
||||
String fileName = FileWriteStringExample.generateFileFromStringList(stringList);
|
||||
long count = Files.lines(Paths.get(fileName)).count();
|
||||
assertTrue("No. of lines in file should be equal to no. of Strings in List", ((int) count) == stringList.size());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.baeldung.filewriter;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class FileWriterUnitTest {
|
||||
|
||||
private static final List<String> stringList = Arrays.asList("Hello", "World");
|
||||
|
||||
@Test
|
||||
public void givenUsingFileWriter_whenStringList_thenGetTextFile() throws IOException {
|
||||
String fileName = FileWriterExample.generateFileFromStringList(stringList);
|
||||
long count = Files.lines(Paths.get(fileName)).count();
|
||||
assertTrue("No. of lines in file should be equal to no. of Strings in List", ((int) count) == stringList.size());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
Hello
|
||||
World
|
||||
Reference in New Issue
Block a user