BAEL-7131 version 7
This commit is contained in:
parent
e6d37b867c
commit
ed1e58c45e
@ -21,7 +21,7 @@ import org.junit.Assert;
|
|||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.io.TempDir;
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
public class InputStreamUnitTest {
|
public class InputStreamUnitTest {
|
||||||
@Test //givenAStringWrittenToAFile_whenReadByX_thenY
|
@Test
|
||||||
public void givenAStringWrittenToFile_whenReadWithFileInputStream_thenItShouldExitsInTheInputStream(@TempDir Path tempDir) throws IOException {
|
public void givenAStringWrittenToFile_whenReadWithFileInputStream_thenItShouldExitsInTheInputStream(@TempDir Path tempDir) throws IOException {
|
||||||
Path sampleOut = tempDir.resolve("sample-out.txt");
|
Path sampleOut = tempDir.resolve("sample-out.txt");
|
||||||
List<String> lines = Arrays.asList("Hello. This is just a test. Good bye.");
|
List<String> lines = Arrays.asList("Hello. This is just a test. Good bye.");
|
||||||
@ -60,19 +60,18 @@ public class InputStreamUnitTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void givenKeyValuePairsWrittenInAFile_whenPassedInOutputStreams_thenThePairsShouldExistsInObjectInputStreams(
|
public void givenKeyValuePairsWrittenInAFile_whenPassedInOutputStreams_thenThePairsShouldExistsInObjectInputStreams(@TempDir Path tempDir) throws IOException, ClassNotFoundException {
|
||||||
@TempDir Path tempDir) throws IOException, ClassNotFoundException {
|
|
||||||
Path sampleOut = tempDir.resolve("sample-out.txt");
|
Path sampleOut = tempDir.resolve("sample-out.txt");
|
||||||
File fileText = sampleOut.toFile();
|
File textFile = sampleOut.toFile();
|
||||||
//Serialize a Hashmap then write it into a file.
|
//Serialize a Hashmap then write it into a file.
|
||||||
Map<String, String> kv = new HashMap<>();
|
Map<String, String> kv = new HashMap<>();
|
||||||
try (ObjectOutputStream objectOutStream = new ObjectOutputStream(new FileOutputStream(fileText))) {
|
try (ObjectOutputStream objectOutStream = new ObjectOutputStream(new FileOutputStream(textFile))) {
|
||||||
kv.put("baseURL", "baeldung.com");
|
kv.put("baseURL", "baeldung.com");
|
||||||
kv.put("apiKey", "this_is_a_test_key");
|
kv.put("apiKey", "this_is_a_test_key");
|
||||||
objectOutStream.writeObject(kv);
|
objectOutStream.writeObject(kv);
|
||||||
}
|
}
|
||||||
//Deserialize the contents of a file then transform it back into a Hashmap
|
//Deserialize the contents of a file then transform it back into a Hashmap
|
||||||
try (ObjectInputStream input = new ObjectInputStream(new FileInputStream(fileText))) {
|
try (ObjectInputStream input = new ObjectInputStream(new FileInputStream(textFile))) {
|
||||||
HashMap<String, String> inputKv = (HashMap<String, String>) input.readObject();
|
HashMap<String, String> inputKv = (HashMap<String, String>) input.readObject();
|
||||||
assertThat(kv.get("baseURL")).isEqualTo( inputKv.get("baseURL"));
|
assertThat(kv.get("baseURL")).isEqualTo( inputKv.get("baseURL"));
|
||||||
assertThat(kv.get("apiKey")).isEqualTo( inputKv.get("apiKey"));
|
assertThat(kv.get("apiKey")).isEqualTo( inputKv.get("apiKey"));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user