Close streams in tests

This commit ensures that file streams are properly closed in tests.
This seems to cause issues on Windows as the OS cannot delete temp
folders.

This is similar to spring-io/initializr#862

See gh-23507
This commit is contained in:
Brian Clozel 2019-08-23 12:56:47 +02:00
parent 8e4f2c89ff
commit b96cbb4e65
1 changed files with 9 additions and 8 deletions

View File

@ -244,17 +244,18 @@ class CandidateComponentsIndexerTests {
} }
private CandidateComponentsMetadata readGeneratedMetadata(File outputLocation) { private CandidateComponentsMetadata readGeneratedMetadata(File outputLocation) {
try { File metadataFile = new File(outputLocation, MetadataStore.METADATA_PATH);
File metadataFile = new File(outputLocation, MetadataStore.METADATA_PATH); if (metadataFile.isFile()) {
if (metadataFile.isFile()) { try (FileInputStream fileInputStream = new FileInputStream(metadataFile)) {
return PropertiesMarshaller.read(new FileInputStream(metadataFile)); CandidateComponentsMetadata metadata = PropertiesMarshaller.read(fileInputStream);
return metadata;
} }
else { catch (IOException ex) {
return new CandidateComponentsMetadata(); throw new IllegalStateException("Failed to read metadata from disk", ex);
} }
} }
catch (IOException ex) { else {
throw new IllegalStateException("Failed to read metadata from disk", ex); return new CandidateComponentsMetadata();
} }
} }