BAEL-7131 version 3 - code review comments.

This commit is contained in:
adalagandev 2024-02-11 19:11:39 +01:00
parent 8aea75fd05
commit 94fceedf7c
2 changed files with 25 additions and 0 deletions

View File

@ -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();

View File

@ -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 {