From 5a6eaeb1d23dae06260e3caad17b8894828c9f7e Mon Sep 17 00:00:00 2001 From: pivovarit Date: Sun, 15 Jan 2017 09:27:07 +0100 Subject: [PATCH] Refactor InputStreamToFile examples --- .../java/io/JavaInputStreamToXUnitTest.java | 54 ++++++++----------- 1 file changed, 21 insertions(+), 33 deletions(-) diff --git a/core-java/src/test/java/org/baeldung/java/io/JavaInputStreamToXUnitTest.java b/core-java/src/test/java/org/baeldung/java/io/JavaInputStreamToXUnitTest.java index 1a6ac5f8ce..6d6d4d9c9b 100644 --- a/core-java/src/test/java/org/baeldung/java/io/JavaInputStreamToXUnitTest.java +++ b/core-java/src/test/java/org/baeldung/java/io/JavaInputStreamToXUnitTest.java @@ -1,38 +1,26 @@ package org.baeldung.java.io; -import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; -import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; - -import java.io.BufferedReader; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.io.Reader; -import java.io.StringWriter; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.nio.file.StandardCopyOption; -import java.util.Scanner; - -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.IOUtils; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.google.common.base.Charsets; import com.google.common.io.ByteSource; import com.google.common.io.ByteStreams; import com.google.common.io.CharStreams; import com.google.common.io.Files; +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.IOUtils; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.*; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.file.StandardCopyOption; +import java.util.Scanner; + +import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; +import static org.hamcrest.Matchers.equalTo; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; @SuppressWarnings("unused") public class JavaInputStreamToXUnitTest { @@ -163,7 +151,7 @@ public class JavaInputStreamToXUnitTest { // tests - InputStream to File @Test - public final void givenUsingPlainJava_whenConvertingAnFullInputStreamToAFile_thenCorrect() throws IOException { + public final void whenConvertingToFile_thenCorrect() throws IOException { final InputStream initialStream = new FileInputStream(new File("src/main/resources/sample.txt")); final byte[] buffer = new byte[initialStream.available()]; initialStream.read(buffer); @@ -177,7 +165,7 @@ public class JavaInputStreamToXUnitTest { } @Test - public final void givenUsingPlainJava_whenConvertingAnInProgressInputStreamToAFile_thenCorrect() throws IOException { + public final void whenConvertingInProgressToFile_thenCorrect() throws IOException { final InputStream initialStream = new FileInputStream(new File("src/main/resources/sample.txt")); final File targetFile = new File("src/main/resources/targetFile.tmp"); final OutputStream outStream = new FileOutputStream(targetFile); @@ -193,7 +181,7 @@ public class JavaInputStreamToXUnitTest { } @Test - public final void givenUsingPlainJava8_whenConvertingAnInProgressInputStreamToAFile_thenCorrect() throws IOException { + public final void whenConvertingAnInProgressInputStreamToFile_thenCorrect2() throws IOException { final InputStream initialStream = new FileInputStream(new File("src/main/resources/sample.txt")); final File targetFile = new File("src/main/resources/targetFile.tmp"); @@ -203,7 +191,7 @@ public class JavaInputStreamToXUnitTest { } @Test - public final void givenUsingGuava_whenConvertingAnInputStreamToAFile_thenCorrect() throws IOException { + public final void whenConvertingInputStreamToFile_thenCorrect3() throws IOException { final InputStream initialStream = new FileInputStream(new File("src/main/resources/sample.txt")); final byte[] buffer = new byte[initialStream.available()]; initialStream.read(buffer); @@ -215,7 +203,7 @@ public class JavaInputStreamToXUnitTest { } @Test - public final void givenUsingCommonsIO_whenConvertingAnInputStreamToAFile_thenCorrect() throws IOException { + public final void whenConvertingInputStreamToFile_thenCorrect4() throws IOException { final InputStream initialStream = FileUtils.openInputStream(new File("src/main/resources/sample.txt")); final File targetFile = new File("src/main/resources/targetFile.tmp");