diff --git a/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamUnitTest.java b/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamUnitTest.java index 6ad3c03d8b..e45e406f75 100644 --- a/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamUnitTest.java +++ b/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/inputstream/InputStreamUnitTest.java @@ -5,17 +5,12 @@ import static org.assertj.core.api.Assertions.assertThat; import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; import java.nio.file.Files; import java.nio.file.Path; import java.util.Arrays; -import java.util.HashMap; import java.util.List; -import java.util.Map; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; @@ -32,21 +27,6 @@ public class InputStreamUnitTest { } } - @Test - public void givenAStringWrittenToFile_whenReadWithFileInputStreamWithStringConstructor_thenItShouldExitsInTheInputStream(@TempDir Path tempDir) throws IOException { - Path sampleOut = tempDir.resolve("sample-out.txt"); - String expectedText = "Hello. Hi."; - List lines = Arrays.asList(expectedText); - Files.write(sampleOut, lines); - String fileAbsolutePath = sampleOut.toFile() - .getAbsolutePath(); - try (FileInputStream fis = new FileInputStream(fileAbsolutePath)) { - int availableBytes = fis.available(); - assertThat(availableBytes).isGreaterThan(0); - assertThat(readString(fis)).contains(expectedText); - } - } - @Test public void givenAByteArray_whenReadWithByteArrayInputStream_thenTheStringValueOfTheByteArrayShouldMatchTheExpectedString() throws IOException { byte[] byteArray = { 104, 101, 108, 108, 111 }; @@ -55,25 +35,6 @@ public class InputStreamUnitTest { } } - @Test - public void givenKeyValuePairsWrittenInAFile_whenPassedInOutputStreams_thenThePairsShouldExistsInObjectInputStreams(@TempDir Path tempDir) throws IOException, ClassNotFoundException { - Path sampleOut = tempDir.resolve("sample-out.txt"); - File textFile = sampleOut.toFile(); - //Serialize a Hashmap then write it into a file. - Map kv = new HashMap<>(); - try (ObjectOutputStream objectOutStream = new ObjectOutputStream(new FileOutputStream(textFile))) { - kv.put("baseURL", "baeldung.com"); - kv.put("apiKey", "this_is_a_test_key"); - objectOutStream.writeObject(kv); - } - //Deserialize the contents of a file then transform it back into a Hashmap - try (ObjectInputStream input = new ObjectInputStream(new FileInputStream(textFile))) { - HashMap inputKv = (HashMap) input.readObject(); - assertThat(kv.get("baseURL")).isEqualTo(inputKv.get("baseURL")); - assertThat(kv.get("apiKey")).isEqualTo(inputKv.get("apiKey")); - } - } - private static String readString(InputStream inputStream) throws IOException { int c; StringBuilder sb = new StringBuilder();