|
| 1 | +package com.baeldung.stream; |
| 2 | + |
| 3 | +import static org.junit.Assert.assertTrue; |
| 4 | + |
| 5 | +import java.io.File; |
| 6 | +import java.io.IOException; |
| 7 | + |
| 8 | +import org.junit.Before; |
| 9 | +import org.junit.Test; |
| 10 | + |
| 11 | +public class OutputStreamExamplesTest { |
| 12 | + |
| 13 | + StringBuilder filePath = new StringBuilder(); |
| 14 | + |
| 15 | + @Before |
| 16 | + public void init() { |
| 17 | + filePath.append("src"); |
| 18 | + filePath.append(File.separator); |
| 19 | + filePath.append("test"); |
| 20 | + filePath.append(File.separator); |
| 21 | + filePath.append("resources"); |
| 22 | + filePath.append(File.separator); |
| 23 | + filePath.append("output_file.txt"); |
| 24 | + } |
| 25 | + |
| 26 | + @Test |
| 27 | + public void givenOutputStream_whenWriteSingleByteCalled_thenOutputCreated() throws IOException { |
| 28 | + |
| 29 | + final File file = new File(filePath.toString()); |
| 30 | + OutputStreamExamples examples = new OutputStreamExamples(); |
| 31 | + examples.fileOutputStreamByteSingle(filePath.toString(), "Hello World!"); |
| 32 | + assertTrue(file.exists()); |
| 33 | + file.delete(); |
| 34 | + } |
| 35 | + |
| 36 | + @Test |
| 37 | + public void givenOutputStream_whenWriteByteSequenceCalled_thenOutputCreated() throws IOException { |
| 38 | + |
| 39 | + final File file = new File(filePath.toString()); |
| 40 | + OutputStreamExamples examples = new OutputStreamExamples(); |
| 41 | + examples.fileOutputStreamByteSequence(filePath.toString(), "Hello World!"); |
| 42 | + assertTrue(file.exists()); |
| 43 | + file.delete(); |
| 44 | + } |
| 45 | + |
| 46 | + @Test |
| 47 | + public void givenOutputStream_whenWriteByteSubSequenceCalled_thenOutputCreated() throws IOException { |
| 48 | + |
| 49 | + final File file = new File(filePath.toString()); |
| 50 | + OutputStreamExamples examples = new OutputStreamExamples(); |
| 51 | + examples.fileOutputStreamByteSubSequence(filePath.toString(), "Hello World!"); |
| 52 | + assertTrue(file.exists()); |
| 53 | + file.delete(); |
| 54 | + } |
| 55 | + |
| 56 | + @Test |
| 57 | + public void givenBufferedOutputStream_whenCalled_thenOutputCreated() throws IOException { |
| 58 | + |
| 59 | + final File file = new File(filePath.toString()); |
| 60 | + OutputStreamExamples examples = new OutputStreamExamples(); |
| 61 | + examples.bufferedOutputStream(filePath.toString(), "Hello", "World!"); |
| 62 | + assertTrue(file.exists()); |
| 63 | + file.delete(); |
| 64 | + } |
| 65 | + |
| 66 | + @Test |
| 67 | + public void givenOutputStreamWriter_whenCalled_thenOutputCreated() throws IOException { |
| 68 | + |
| 69 | + final File file = new File(filePath.toString()); |
| 70 | + OutputStreamExamples examples = new OutputStreamExamples(); |
| 71 | + examples.outputStreamWriter(filePath.toString(), "Hello World!"); |
| 72 | + assertTrue(file.exists()); |
| 73 | + file.delete(); |
| 74 | + } |
| 75 | + |
| 76 | +} |
0 commit comments