BAEL-3215: Use try-with-resource in FileReader demo (#7732)

- To simplify the demo, change is required in the unit-tests
 that currently uses close() method instead of try-with-resource
This commit is contained in:
Tapan Avasthi 2019-09-07 00:43:24 +05:30 committed by maibin
parent d147cabfd8
commit 1fc511ba7a

View File

@ -17,15 +17,9 @@ public class FileReaderExampleUnitTest {
public void givenFileReader_whenReadAllCharacters_thenReturnsContent() throws IOException {
String expectedText = "Hello, World!";
File file = new File(FILE_PATH);
FileReader fileReader = null;
try {
fileReader = new FileReader(file);
try (FileReader fileReader = new FileReader(file)) {
String content = FileReaderExample.readAllCharactersOneByOne(fileReader);
Assert.assertEquals(expectedText, content);
} finally {
if (fileReader != null) {
fileReader.close();
}
}
}
@ -33,15 +27,9 @@ public class FileReaderExampleUnitTest {
public void givenFileReader_whenReadMultipleCharacters_thenReturnsContent() throws IOException {
String expectedText = "Hello";
File file = new File(FILE_PATH);
FileReader fileReader = null;
try {
fileReader = new FileReader(file);
try (FileReader fileReader = new FileReader(file)) {
String content = FileReaderExample.readMultipleCharacters(fileReader, 5);
Assert.assertEquals(expectedText, content);
} finally {
if (fileReader != null) {
fileReader.close();
}
}
}