add new is to string test

This commit is contained in:
Loredana Crusoveanu 2018-07-09 23:40:29 +03:00
parent db00197aac
commit 66f2263b98
1 changed files with 15 additions and 0 deletions

View File

@ -14,8 +14,10 @@ import org.slf4j.LoggerFactory;
import java.io.*;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.Scanner;
import java.util.UUID;
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
import static org.hamcrest.Matchers.equalTo;
@ -111,6 +113,19 @@ public class JavaInputStreamToXUnitTest {
assertThat(writer.toString(), equalTo(originalString));
}
@Test
public final void givenUsingTempFile_whenConvertingAnInputStreamToAString_thenCorrect() throws IOException {
final String originalString = randomAlphabetic(DEFAULT_SIZE);
final InputStream inputStream = new ByteArrayInputStream(originalString.getBytes());
// When
Path tempFile = java.nio.file.Files.createTempDirectory("").resolve(UUID.randomUUID().toString() + ".tmp");
java.nio.file.Files.copy(inputStream, tempFile, StandardCopyOption.REPLACE_EXISTING);
String result = new String(java.nio.file.Files.readAllBytes(tempFile));
assertThat(result, equalTo(originalString));
}
// tests - InputStream to byte[]