BAEL-7131 version 3 - code review comments.
This commit is contained in:
parent
8aea75fd05
commit
94fceedf7c
|
@ -13,6 +13,7 @@ import java.util.List;
|
|||
import org.junit.Assert;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
public class InputStreamTest {
|
||||
@Test
|
||||
public void givenAString_whenWrittenToFileInputStream_thenShouldMatchWhenRead(@TempDir Path tempDir) throws IOException {
|
||||
|
@ -24,6 +25,28 @@ public class InputStreamTest {
|
|||
Assert.assertTrue(readString(inputStream).contains(lines.get(0)));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAString_whenWrittenToFileInputStreamWithStringConstructor_thenShouldMatchWhenRead(@TempDir Path tempDir) throws IOException {
|
||||
Path sampleOut = tempDir.resolve("sample-out.txt");
|
||||
String expectedText = "Hello. Hi.";
|
||||
List<String> lines = Arrays.asList(expectedText);
|
||||
Files.write(sampleOut, lines);
|
||||
String fileAbsolutePath = sampleOut.toFile()
|
||||
.getAbsolutePath();
|
||||
try (FileInputStream fis = new FileInputStream(fileAbsolutePath)) {
|
||||
int content;
|
||||
int availabeBytes = fis.available();
|
||||
Assert.assertTrue(availabeBytes > 0);
|
||||
StringBuilder actualReadText = new StringBuilder();
|
||||
while ((content = fis.read()) != -1) {
|
||||
actualReadText.append((char) content);
|
||||
}
|
||||
Assert.assertTrue(actualReadText.toString()
|
||||
.contains(expectedText));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAString_whenWrittenToByteArrayInputStream_thenShouldMatchWhenRead() throws IOException {
|
||||
byte[] byteArray = { 104, 101, 108, 108, 111 };
|
||||
|
@ -32,6 +55,7 @@ public class InputStreamTest {
|
|||
Assert.assertEquals("hello", expected);
|
||||
}
|
||||
}
|
||||
|
||||
private static String readString(InputStream inputStream) throws IOException {
|
||||
int c;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
|
|
@ -13,6 +13,7 @@ import java.util.List;
|
|||
import org.junit.Assert;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
public class InputStreamReaderTest {
|
||||
@Test
|
||||
public void givenAStringWrittenToAFile_whenReadByInputStreamReader_thenShouldMatchWhenRead(@TempDir Path tempDir) throws IOException {
|
||||
|
|
Loading…
Reference in New Issue