Merge branch 'master' of https://github.com/ahmedtawila/tutorials
This commit is contained in:
commit
79a4d133c3
|
@ -0,0 +1,3 @@
|
|||
UK
|
||||
US
|
||||
Germany
|
|
@ -14,7 +14,7 @@ import com.baeldung.util.StreamUtils;
|
|||
|
||||
public class FileOutputStreamTest {
|
||||
|
||||
public static final String fileName = "src/main/resources/countries.txt";
|
||||
public static final String fileName = "src/main/resources/countries.properties";
|
||||
|
||||
@Test
|
||||
public void whenAppendToFileUsingFileOutputStream_thenCorrect() throws Exception {
|
||||
|
@ -30,7 +30,6 @@ public class FileOutputStreamTest {
|
|||
@After
|
||||
public void revertFile() throws IOException {
|
||||
PrintWriter writer = new PrintWriter(fileName);
|
||||
writer.print("");
|
||||
writer.print("UK\r\n" + "US\r\n" + "Germany\r\n");
|
||||
writer.close();
|
||||
}
|
|
@ -16,7 +16,7 @@ import com.baeldung.util.StreamUtils;
|
|||
|
||||
public class FileUtilsTest {
|
||||
|
||||
public static final String fileName = "src/main/resources/countries.txt";
|
||||
public static final String fileName = "src/main/resources/countries.properties";
|
||||
|
||||
@Test
|
||||
public void whenAppendToFileUsingFiles_thenCorrect() throws IOException {
|
||||
|
@ -31,7 +31,6 @@ public class FileUtilsTest {
|
|||
@After
|
||||
public void revertFile() throws IOException {
|
||||
PrintWriter writer = new PrintWriter(fileName);
|
||||
writer.print("");
|
||||
writer.print("UK\r\n" + "US\r\n" + "Germany\r\n");
|
||||
writer.close();
|
||||
}
|
|
@ -15,11 +15,10 @@ import com.baeldung.util.StreamUtils;
|
|||
|
||||
public class FileWriterTest {
|
||||
|
||||
public static final String fileName = "src/main/resources/countries.txt";
|
||||
public static final String fileName = "src/main/resources/countries.properties";
|
||||
|
||||
@Test
|
||||
public void whenAppendToFileUsingFileWriter_thenCorrect() throws IOException {
|
||||
String fileName = "src/main/resources/countries.txt";
|
||||
FileWriter fw = new FileWriter(fileName, true);
|
||||
BufferedWriter bw = new BufferedWriter(fw);
|
||||
bw.write("Spain");
|
||||
|
@ -29,13 +28,12 @@ public class FileWriterTest {
|
|||
assertThat(
|
||||
StreamUtils.getStringFromInputStream(
|
||||
new FileInputStream(fileName)))
|
||||
.isEqualTo("UK\r\n" + "US\r\n" + "Germany\r\n" + "Spain\r\n");
|
||||
.isEqualTo("UK\r\n" + "US\r\n" + "Germany\r\n" + "Spain\n");
|
||||
}
|
||||
|
||||
@After
|
||||
public void revertFile() throws IOException {
|
||||
PrintWriter writer = new PrintWriter(fileName);
|
||||
writer.print("");
|
||||
writer.print("UK\r\n" + "US\r\n" + "Germany\r\n");
|
||||
writer.close();
|
||||
}
|
|
@ -16,7 +16,7 @@ import com.baeldung.util.StreamUtils;
|
|||
|
||||
public class FilesTest {
|
||||
|
||||
public static final String fileName = "src/main/resources/countries.txt";
|
||||
public static final String fileName = "src/main/resources/countries.properties";
|
||||
|
||||
@Test
|
||||
public void whenAppendToFileUsingFiles_thenCorrect() throws IOException {
|
||||
|
@ -30,7 +30,6 @@ public class FilesTest {
|
|||
@After
|
||||
public void revertFile() throws IOException {
|
||||
PrintWriter writer = new PrintWriter(fileName);
|
||||
writer.print("");
|
||||
writer.print("UK\r\n" + "US\r\n" + "Germany\r\n");
|
||||
writer.close();
|
||||
}
|
|
@ -8,6 +8,7 @@ import java.io.IOException;
|
|||
import java.io.PrintWriter;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.baeldung.util.StreamUtils;
|
||||
|
@ -18,10 +19,17 @@ import com.google.common.io.Files;
|
|||
|
||||
public class GuavaTest {
|
||||
|
||||
public static final String fileName = "src/main/resources/countries.txt";
|
||||
public static final String fileName = "src/main/resources/countries.properties";
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
PrintWriter writer = new PrintWriter(fileName);
|
||||
writer.print("UK\r\n" + "US\r\n" + "Germany\r\n");
|
||||
writer.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAppendToFileUsingFileWriter_thenCorrect() throws IOException {
|
||||
public void whenAppendToFileUsingGuava_thenCorrect() throws IOException {
|
||||
File file = new File(fileName);
|
||||
CharSink chs = Files.asCharSink(file, Charsets.UTF_8, FileWriteMode.APPEND);
|
||||
chs.write("Spain\r\n");
|
||||
|
@ -34,7 +42,6 @@ public class GuavaTest {
|
|||
@After
|
||||
public void revertFile() throws IOException {
|
||||
PrintWriter writer = new PrintWriter(fileName);
|
||||
writer.print("");
|
||||
writer.print("UK\r\n" + "US\r\n" + "Germany\r\n");
|
||||
writer.close();
|
||||
}
|
Loading…
Reference in New Issue