File tree Expand file tree Collapse file tree 2 files changed +19
-8
lines changed
src/test/java/org/baeldung/java/io Expand file tree Collapse file tree 2 files changed +19
-8
lines changed Original file line number Diff line number Diff line change 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 >
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
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments