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:
		
							parent
							
								
									d147cabfd8
								
							
						
					
					
						commit
						1fc511ba7a
					
				| @ -17,15 +17,9 @@ public class FileReaderExampleUnitTest { | |||||||
|     public void givenFileReader_whenReadAllCharacters_thenReturnsContent() throws IOException { |     public void givenFileReader_whenReadAllCharacters_thenReturnsContent() throws IOException { | ||||||
|         String expectedText = "Hello, World!"; |         String expectedText = "Hello, World!"; | ||||||
|         File file = new File(FILE_PATH); |         File file = new File(FILE_PATH); | ||||||
|         FileReader fileReader = null; |         try (FileReader fileReader = new FileReader(file)) { | ||||||
|         try { |  | ||||||
|             fileReader = new FileReader(file); |  | ||||||
|             String content = FileReaderExample.readAllCharactersOneByOne(fileReader); |             String content = FileReaderExample.readAllCharactersOneByOne(fileReader); | ||||||
|             Assert.assertEquals(expectedText, content); |             Assert.assertEquals(expectedText, content); | ||||||
|         } finally { |  | ||||||
|             if (fileReader != null) { |  | ||||||
|                 fileReader.close(); |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -33,15 +27,9 @@ public class FileReaderExampleUnitTest { | |||||||
|     public void givenFileReader_whenReadMultipleCharacters_thenReturnsContent() throws IOException { |     public void givenFileReader_whenReadMultipleCharacters_thenReturnsContent() throws IOException { | ||||||
|         String expectedText = "Hello"; |         String expectedText = "Hello"; | ||||||
|         File file = new File(FILE_PATH); |         File file = new File(FILE_PATH); | ||||||
|         FileReader fileReader = null; |         try (FileReader fileReader = new FileReader(file)) { | ||||||
|         try { |  | ||||||
|             fileReader = new FileReader(file); |  | ||||||
|             String content = FileReaderExample.readMultipleCharacters(fileReader, 5); |             String content = FileReaderExample.readMultipleCharacters(fileReader, 5); | ||||||
|             Assert.assertEquals(expectedText, content); |             Assert.assertEquals(expectedText, content); | ||||||
|         } finally { |  | ||||||
|             if (fileReader != null) { |  | ||||||
|                 fileReader.close(); |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user