Move tests to JUnit 5 wherever possible
This commit is contained in:
@@ -16,12 +16,13 @@
|
||||
|
||||
package org.springframework.boot.context.properties.migrator;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.test.system.OutputCaptureRule;
|
||||
import org.springframework.boot.test.system.CapturedOutput;
|
||||
import org.springframework.boot.test.system.OutputCaptureExtension;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@@ -32,14 +33,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class PropertiesMigrationListenerTests {
|
||||
|
||||
@Rule
|
||||
public final OutputCaptureRule output = new OutputCaptureRule();
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
class PropertiesMigrationListenerTests {
|
||||
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void closeContext() {
|
||||
if (this.context != null) {
|
||||
this.context.close();
|
||||
@@ -47,9 +46,9 @@ public class PropertiesMigrationListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sampleReport() {
|
||||
void sampleReport(CapturedOutput capturedOutput) {
|
||||
this.context = createSampleApplication().run("--banner.charset=UTF8");
|
||||
assertThat(this.output.toString()).contains("commandLineArgs").contains("spring.banner.charset")
|
||||
assertThat(capturedOutput).contains("commandLineArgs").contains("spring.banner.charset")
|
||||
.contains("Each configuration key has been temporarily mapped")
|
||||
.doesNotContain("Please refer to the migration guide");
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.configurationmetadata.ConfigurationMetadataRepository;
|
||||
import org.springframework.boot.configurationmetadata.ConfigurationMetadataRepositoryJsonBuilder;
|
||||
@@ -46,18 +46,18 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class PropertiesMigrationReporterTests {
|
||||
class PropertiesMigrationReporterTests {
|
||||
|
||||
private ConfigurableEnvironment environment = new MockEnvironment();
|
||||
|
||||
@Test
|
||||
public void reportIsNullWithNoMatchingKeys() {
|
||||
void reportIsNullWithNoMatchingKeys() {
|
||||
String report = createWarningReport(new SimpleConfigurationMetadataRepository());
|
||||
assertThat(report).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void replacementKeysAreRemapped() throws IOException {
|
||||
void replacementKeysAreRemapped() throws IOException {
|
||||
MutablePropertySources propertySources = this.environment.getPropertySources();
|
||||
PropertySource<?> one = loadPropertySource("one", "config/config-error.properties");
|
||||
PropertySource<?> two = loadPropertySource("two", "config/config-warnings.properties");
|
||||
@@ -70,7 +70,7 @@ public class PropertiesMigrationReporterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void warningReport() throws IOException {
|
||||
void warningReport() throws IOException {
|
||||
this.environment.getPropertySources().addFirst(loadPropertySource("test", "config/config-warnings.properties"));
|
||||
this.environment.getPropertySources().addFirst(loadPropertySource("ignore", "config/config-error.properties"));
|
||||
String report = createWarningReport(loadRepository("metadata/sample-metadata.json"));
|
||||
@@ -81,7 +81,7 @@ public class PropertiesMigrationReporterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void errorReport() throws IOException {
|
||||
void errorReport() throws IOException {
|
||||
this.environment.getPropertySources()
|
||||
.addFirst(loadPropertySource("test1", "config/config-warnings.properties"));
|
||||
this.environment.getPropertySources().addFirst(loadPropertySource("test2", "config/config-error.properties"));
|
||||
@@ -93,7 +93,7 @@ public class PropertiesMigrationReporterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void errorReportNoReplacement() throws IOException {
|
||||
void errorReportNoReplacement() throws IOException {
|
||||
this.environment.getPropertySources()
|
||||
.addFirst(loadPropertySource("first", "config/config-error-no-replacement.properties"));
|
||||
this.environment.getPropertySources().addFirst(loadPropertySource("second", "config/config-error.properties"));
|
||||
@@ -105,7 +105,7 @@ public class PropertiesMigrationReporterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void durationTypeIsHandledTransparently() {
|
||||
void durationTypeIsHandledTransparently() {
|
||||
MutablePropertySources propertySources = this.environment.getPropertySources();
|
||||
Map<String, Object> content = new LinkedHashMap<>();
|
||||
content.put("test.cache-seconds", 50);
|
||||
@@ -124,7 +124,7 @@ public class PropertiesMigrationReporterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void reasonIsProvidedIfPropertyCouldNotBeRenamed() throws IOException {
|
||||
void reasonIsProvidedIfPropertyCouldNotBeRenamed() throws IOException {
|
||||
this.environment.getPropertySources()
|
||||
.addFirst(loadPropertySource("test", "config/config-error-no-compatible-type.properties"));
|
||||
String report = createErrorReport(loadRepository("metadata/type-conversion-metadata.json"));
|
||||
@@ -134,7 +134,7 @@ public class PropertiesMigrationReporterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invalidReplacementHandled() throws IOException {
|
||||
void invalidReplacementHandled() throws IOException {
|
||||
this.environment.getPropertySources()
|
||||
.addFirst(loadPropertySource("first", "config/config-error-invalid-replacement.properties"));
|
||||
String report = createErrorReport(loadRepository("metadata/sample-metadata-invalid-replacement.json"));
|
||||
|
||||
Reference in New Issue
Block a user