Fix test failures on Windows

Since the move to JUnit 5, a number of tests were failing on Windows.
The majority were failing due to open file handles preventing the
clean up of the tests' temporary directory. This commit addresses
these failures by updating the tests to close JarFiles, InputStreams,
OutputStreams etc.

A change has also been made to CachingOperationInvokerTests to make
a flakey test more robust. Due to System.currentTimeMillis() being
less precise on Windows than it is on *nix platforms, the test could
fail as it would not sleep for long enough for the TTL period to have
expired.
This commit is contained in:
Andy Wilkinson
2019-06-10 09:24:06 +01:00
parent c56fbf8c3d
commit cffc870fd6
22 changed files with 435 additions and 209 deletions

View File

@@ -19,6 +19,7 @@ package org.springframework.boot.configurationprocessor.test;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedSourceVersion;
@@ -96,7 +97,9 @@ public class TestConfigurationMetadataAnnotationProcessor extends ConfigurationM
try {
File metadataFile = new File(this.outputLocation, "META-INF/spring-configuration-metadata.json");
if (metadataFile.isFile()) {
this.metadata = new JsonMarshaller().read(new FileInputStream(metadataFile));
try (InputStream input = new FileInputStream(metadataFile)) {
this.metadata = new JsonMarshaller().read(input);
}
}
else {
this.metadata = new ConfigurationMetadata();