Skip to content

Commit bf71b34

Browse files
lor6pivovarit
authored andcommitted
baos example (eugenp#1858)
1 parent 286c255 commit bf71b34

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

core-java/pom.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,6 @@
140140
<scope>test</scope>
141141
</dependency>
142142

143-
<dependency>
144-
<groupId>org.testng</groupId>
145-
<artifactId>testng</artifactId>
146-
<version>${testng.version}</version>
147-
<scope>test</scope>
148-
</dependency>
149-
150143
<dependency>
151144
<groupId>org.mockito</groupId>
152145
<artifactId>mockito-core</artifactId>
@@ -387,7 +380,6 @@
387380
<org.hamcrest.version>1.3</org.hamcrest.version>
388381
<junit.version>4.12</junit.version>
389382
<mockito.version>1.10.19</mockito.version>
390-
<testng.version>6.10</testng.version>
391383
<assertj.version>3.6.1</assertj.version>
392384
<avaitility.version>1.7.0</avaitility.version>
393385

core-java/src/test/java/org/baeldung/java/io/JavaInputStreamToXUnitTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,5 +210,24 @@ public final void whenConvertingInputStreamToFile_thenCorrect4() throws IOExcept
210210

211211
FileUtils.copyInputStreamToFile(initialStream, targetFile);
212212
}
213+
214+
@Test
215+
public final void givenUsingPlainJava_whenConvertingAnInputStreamToString_thenCorrect() throws IOException {
216+
String originalString = randomAlphabetic(8);
217+
InputStream inputStream = new ByteArrayInputStream(originalString.getBytes());
218+
219+
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
220+
int nRead;
221+
byte[] data = new byte[1024];
222+
while ((nRead = inputStream.read(data, 0, data.length)) != -1) {
223+
buffer.write(data, 0, nRead);
224+
}
225+
226+
buffer.flush();
227+
byte[] byteArray = buffer.toByteArray();
228+
229+
String text = new String(byteArray, StandardCharsets.UTF_8);
230+
assertThat(text, equalTo(originalString));
231+
}
213232

214233
}

0 commit comments

Comments
 (0)