mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Polish output capture names
This commit is contained in:
parent
cdf43a7489
commit
c3816bfe7b
@ -124,23 +124,23 @@ class PrometheusMetricsExportAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void withPushGatewayEnabled(CapturedOutput capturedOutput) {
|
||||
void withPushGatewayEnabled(CapturedOutput output) {
|
||||
this.contextRunner.withConfiguration(AutoConfigurations.of(ManagementContextAutoConfiguration.class))
|
||||
.withPropertyValues("management.metrics.export.prometheus.pushgateway.enabled=true")
|
||||
.withUserConfiguration(BaseConfiguration.class).run((context) -> {
|
||||
assertThat(capturedOutput).doesNotContain("Invalid PushGateway base url");
|
||||
assertThat(output).doesNotContain("Invalid PushGateway base url");
|
||||
hasGatewayURL(context, "http://localhost:9091/metrics/job/");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
void withCustomLegacyPushGatewayURL(CapturedOutput capturedOutput) {
|
||||
void withCustomLegacyPushGatewayURL(CapturedOutput output) {
|
||||
this.contextRunner.withConfiguration(AutoConfigurations.of(ManagementContextAutoConfiguration.class))
|
||||
.withPropertyValues("management.metrics.export.prometheus.pushgateway.enabled=true",
|
||||
"management.metrics.export.prometheus.pushgateway.base-url=localhost:9090")
|
||||
.withUserConfiguration(BaseConfiguration.class).run((context) -> {
|
||||
assertThat(capturedOutput).contains("Invalid PushGateway base url").contains("localhost:9090");
|
||||
assertThat(output).contains("Invalid PushGateway base url").contains("localhost:9090");
|
||||
hasGatewayURL(context, "http://localhost:9090/metrics/job/");
|
||||
});
|
||||
}
|
||||
|
@ -75,21 +75,21 @@ class RestTemplateMetricsConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void afterMaxUrisReachedFurtherUrisAreDenied(CapturedOutput capturedOutput) {
|
||||
void afterMaxUrisReachedFurtherUrisAreDenied(CapturedOutput output) {
|
||||
this.contextRunner.withPropertyValues("management.metrics.web.client.max-uri-tags=2").run((context) -> {
|
||||
MeterRegistry registry = getInitializedMeterRegistry(context);
|
||||
assertThat(registry.get("http.client.requests").meters()).hasSize(2);
|
||||
assertThat(capturedOutput).contains("Reached the maximum number of URI tags for 'http.client.requests'.")
|
||||
assertThat(output).contains("Reached the maximum number of URI tags for 'http.client.requests'.")
|
||||
.contains("Are you using 'uriVariables'?");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotDenyNorLogIfMaxUrisIsNotReached(CapturedOutput capturedOutput) {
|
||||
void shouldNotDenyNorLogIfMaxUrisIsNotReached(CapturedOutput output) {
|
||||
this.contextRunner.withPropertyValues("management.metrics.web.client.max-uri-tags=5").run((context) -> {
|
||||
MeterRegistry registry = getInitializedMeterRegistry(context);
|
||||
assertThat(registry.get("http.client.requests").meters()).hasSize(3);
|
||||
assertThat(capturedOutput)
|
||||
assertThat(output)
|
||||
.doesNotContain("Reached the maximum number of URI tags for 'http.client.requests'.")
|
||||
.doesNotContain("Are you using 'uriVariables'?");
|
||||
});
|
||||
|
@ -74,21 +74,21 @@ class WebClientMetricsConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void afterMaxUrisReachedFurtherUrisAreDenied(CapturedOutput capturedOutput) {
|
||||
void afterMaxUrisReachedFurtherUrisAreDenied(CapturedOutput output) {
|
||||
this.contextRunner.withPropertyValues("management.metrics.web.client.max-uri-tags=2").run((context) -> {
|
||||
MeterRegistry registry = getInitializedMeterRegistry(context);
|
||||
assertThat(registry.get("http.client.requests").meters()).hasSize(2);
|
||||
assertThat(capturedOutput).contains("Reached the maximum number of URI tags for 'http.client.requests'.")
|
||||
assertThat(output).contains("Reached the maximum number of URI tags for 'http.client.requests'.")
|
||||
.contains("Are you using 'uriVariables'?");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotDenyNorLogIfMaxUrisIsNotReached(CapturedOutput capturedOutput) {
|
||||
void shouldNotDenyNorLogIfMaxUrisIsNotReached(CapturedOutput output) {
|
||||
this.contextRunner.withPropertyValues("management.metrics.web.client.max-uri-tags=5").run((context) -> {
|
||||
MeterRegistry registry = getInitializedMeterRegistry(context);
|
||||
assertThat(registry.get("http.client.requests").meters()).hasSize(3);
|
||||
assertThat(capturedOutput)
|
||||
assertThat(output)
|
||||
.doesNotContain("Reached the maximum number of URI tags for 'http.client.requests'.")
|
||||
.doesNotContain("Are you using 'uriVariables'?");
|
||||
});
|
||||
|
@ -66,25 +66,24 @@ class WebFluxMetricsAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void afterMaxUrisReachedFurtherUrisAreDenied(CapturedOutput capturedOutput) {
|
||||
void afterMaxUrisReachedFurtherUrisAreDenied(CapturedOutput output) {
|
||||
this.contextRunner.withConfiguration(AutoConfigurations.of(WebFluxAutoConfiguration.class))
|
||||
.withUserConfiguration(TestController.class)
|
||||
.withPropertyValues("management.metrics.web.server.max-uri-tags=2").run((context) -> {
|
||||
MeterRegistry registry = getInitializedMeterRegistry(context);
|
||||
assertThat(registry.get("http.server.requests").meters()).hasSize(2);
|
||||
assertThat(capturedOutput)
|
||||
.contains("Reached the maximum number of URI tags " + "for 'http.server.requests'");
|
||||
assertThat(output).contains("Reached the maximum number of URI tags for 'http.server.requests'");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotDenyNorLogIfMaxUrisIsNotReached(CapturedOutput capturedOutput) {
|
||||
void shouldNotDenyNorLogIfMaxUrisIsNotReached(CapturedOutput output) {
|
||||
this.contextRunner.withConfiguration(AutoConfigurations.of(WebFluxAutoConfiguration.class))
|
||||
.withUserConfiguration(TestController.class)
|
||||
.withPropertyValues("management.metrics.web.server.max-uri-tags=5").run((context) -> {
|
||||
MeterRegistry registry = getInitializedMeterRegistry(context);
|
||||
assertThat(registry.get("http.server.requests").meters()).hasSize(3);
|
||||
assertThat(capturedOutput)
|
||||
assertThat(output)
|
||||
.doesNotContain("Reached the maximum number of URI tags for 'http.server.requests'");
|
||||
});
|
||||
}
|
||||
|
@ -104,25 +104,24 @@ class WebMvcMetricsAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void afterMaxUrisReachedFurtherUrisAreDenied(CapturedOutput capturedOutput) {
|
||||
void afterMaxUrisReachedFurtherUrisAreDenied(CapturedOutput output) {
|
||||
this.contextRunner.withUserConfiguration(TestController.class)
|
||||
.withConfiguration(AutoConfigurations.of(MetricsAutoConfiguration.class, WebMvcAutoConfiguration.class))
|
||||
.withPropertyValues("management.metrics.web.server.max-uri-tags=2").run((context) -> {
|
||||
MeterRegistry registry = getInitializedMeterRegistry(context);
|
||||
assertThat(registry.get("http.server.requests").meters()).hasSize(2);
|
||||
assertThat(capturedOutput)
|
||||
.contains("Reached the maximum number of URI tags " + "for 'http.server.requests'");
|
||||
assertThat(output).contains("Reached the maximum number of URI tags for 'http.server.requests'");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotDenyNorLogIfMaxUrisIsNotReached(CapturedOutput capturedOutput) {
|
||||
void shouldNotDenyNorLogIfMaxUrisIsNotReached(CapturedOutput output) {
|
||||
this.contextRunner.withUserConfiguration(TestController.class)
|
||||
.withConfiguration(AutoConfigurations.of(MetricsAutoConfiguration.class, WebMvcAutoConfiguration.class))
|
||||
.withPropertyValues("management.metrics.web.server.max-uri-tags=5").run((context) -> {
|
||||
MeterRegistry registry = getInitializedMeterRegistry(context);
|
||||
assertThat(registry.get("http.server.requests").meters()).hasSize(3);
|
||||
assertThat(capturedOutput)
|
||||
assertThat(output)
|
||||
.doesNotContain("Reached the maximum number of URI tags " + "for 'http.server.requests'");
|
||||
});
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
class ManagementContextAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
void childManagementContextShouldStartForEmbeddedServer(CapturedOutput capturedOutput) {
|
||||
void childManagementContextShouldStartForEmbeddedServer(CapturedOutput output) {
|
||||
WebApplicationContextRunner contextRunner = new WebApplicationContextRunner(
|
||||
AnnotationConfigServletWebServerApplicationContext::new)
|
||||
.withConfiguration(AutoConfigurations.of(ManagementContextAutoConfiguration.class,
|
||||
@ -51,7 +51,7 @@ class ManagementContextAutoConfigurationTests {
|
||||
ServletManagementContextAutoConfiguration.class, WebEndpointAutoConfiguration.class,
|
||||
EndpointAutoConfiguration.class));
|
||||
contextRunner.withPropertyValues("server.port=0", "management.server.port=0")
|
||||
.run((context) -> assertThat(tomcatStartedOccurencesIn(capturedOutput)).isEqualTo(2));
|
||||
.run((context) -> assertThat(tomcatStartedOccurencesIn(output)).isEqualTo(2));
|
||||
}
|
||||
|
||||
private int tomcatStartedOccurencesIn(CharSequence output) {
|
||||
|
@ -85,10 +85,10 @@ class EndpointIdTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void ofWhenContainsDeprecatedCharsLogsWarning(CapturedOutput capturedOutput) {
|
||||
void ofWhenContainsDeprecatedCharsLogsWarning(CapturedOutput output) {
|
||||
EndpointId.resetLoggedWarnings();
|
||||
EndpointId.of("foo-bar");
|
||||
assertThat(capturedOutput.toString())
|
||||
assertThat(output)
|
||||
.contains("Endpoint ID 'foo-bar' contains invalid characters, please migrate to a valid format");
|
||||
}
|
||||
|
||||
|
@ -55,30 +55,30 @@ public class FreeMarkerAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void nonExistentTemplateLocation(CapturedOutput capturedOutput) {
|
||||
void nonExistentTemplateLocation(CapturedOutput output) {
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.freemarker.templateLoaderPath:"
|
||||
+ "classpath:/does-not-exist/,classpath:/also-does-not-exist")
|
||||
.run((context) -> assertThat(capturedOutput).contains("Cannot find template location"));
|
||||
.run((context) -> assertThat(output).contains("Cannot find template location"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void emptyTemplateLocation(CapturedOutput capturedOutput) {
|
||||
void emptyTemplateLocation(CapturedOutput output) {
|
||||
File emptyDirectory = new File(this.buildOutput.getTestResourcesLocation(), "empty-templates/empty-directory");
|
||||
emptyDirectory.mkdirs();
|
||||
this.contextRunner
|
||||
.withPropertyValues(
|
||||
"spring.freemarker.templateLoaderPath:" + "classpath:/empty-templates/empty-directory/")
|
||||
.run((context) -> assertThat(capturedOutput).doesNotContain("Cannot find template location"));
|
||||
.run((context) -> assertThat(output).doesNotContain("Cannot find template location"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void nonExistentLocationAndEmptyLocation(CapturedOutput capturedOutput) {
|
||||
void nonExistentLocationAndEmptyLocation(CapturedOutput output) {
|
||||
new File(this.buildOutput.getTestResourcesLocation(), "empty-templates/empty-directory").mkdirs();
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.freemarker.templateLoaderPath:"
|
||||
+ "classpath:/does-not-exist/,classpath:/empty-templates/empty-directory/")
|
||||
.run((context) -> assertThat(capturedOutput).doesNotContain("Cannot find template location"));
|
||||
.run((context) -> assertThat(output).doesNotContain("Cannot find template location"));
|
||||
}
|
||||
|
||||
public static class DataModel {
|
||||
|
@ -125,12 +125,12 @@ class H2ConsoleAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
void dataSourceUrlIsLoggedWhenAvailable(CapturedOutput capturedOutput) throws BeansException, SQLException {
|
||||
void dataSourceUrlIsLoggedWhenAvailable(CapturedOutput output) throws BeansException, SQLException {
|
||||
this.context.register(DataSourceAutoConfiguration.class, H2ConsoleAutoConfiguration.class);
|
||||
TestPropertyValues.of("spring.h2.console.enabled:true").applyTo(this.context);
|
||||
this.context.refresh();
|
||||
try (Connection connection = this.context.getBean(DataSource.class).getConnection()) {
|
||||
assertThat(capturedOutput).contains("Database available at '" + connection.getMetaData().getURL() + "'");
|
||||
assertThat(output).contains("Database available at '" + connection.getMetaData().getURL() + "'");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,47 +59,47 @@ class ConditionEvaluationReportLoggingListenerTests {
|
||||
private ConditionEvaluationReportLoggingListener initializer = new ConditionEvaluationReportLoggingListener();
|
||||
|
||||
@Test
|
||||
void logsDebugOnContextRefresh(CapturedOutput capturedOutput) {
|
||||
void logsDebugOnContextRefresh(CapturedOutput output) {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
this.initializer.initialize(context);
|
||||
context.register(Config.class);
|
||||
context.refresh();
|
||||
withDebugLogging(() -> this.initializer.onApplicationEvent(new ContextRefreshedEvent(context)));
|
||||
assertThat(capturedOutput).contains("CONDITIONS EVALUATION REPORT");
|
||||
assertThat(output).contains("CONDITIONS EVALUATION REPORT");
|
||||
}
|
||||
|
||||
@Test
|
||||
void logsDebugOnError(CapturedOutput capturedOutput) {
|
||||
void logsDebugOnError(CapturedOutput output) {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
this.initializer.initialize(context);
|
||||
context.register(ErrorConfig.class);
|
||||
assertThatExceptionOfType(Exception.class).isThrownBy(context::refresh)
|
||||
.satisfies((ex) -> withDebugLogging(() -> this.initializer.onApplicationEvent(
|
||||
new ApplicationFailedEvent(new SpringApplication(), new String[0], context, ex))));
|
||||
assertThat(capturedOutput).contains("CONDITIONS EVALUATION REPORT");
|
||||
assertThat(output).contains("CONDITIONS EVALUATION REPORT");
|
||||
}
|
||||
|
||||
@Test
|
||||
void logsInfoOnErrorIfDebugDisabled(CapturedOutput capturedOutput) {
|
||||
void logsInfoOnErrorIfDebugDisabled(CapturedOutput output) {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
this.initializer.initialize(context);
|
||||
context.register(ErrorConfig.class);
|
||||
assertThatExceptionOfType(Exception.class).isThrownBy(context::refresh).satisfies((ex) -> this.initializer
|
||||
.onApplicationEvent(new ApplicationFailedEvent(new SpringApplication(), new String[0], context, ex)));
|
||||
assertThat(capturedOutput)
|
||||
assertThat(output)
|
||||
.contains("Error starting" + " ApplicationContext. To display the conditions report re-run"
|
||||
+ " your application with 'debug' enabled.");
|
||||
}
|
||||
|
||||
@Test
|
||||
void logsOutput(CapturedOutput capturedOutput) {
|
||||
void logsOutput(CapturedOutput output) {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
this.initializer.initialize(context);
|
||||
context.register(Config.class);
|
||||
ConditionEvaluationReport.get(context.getBeanFactory()).recordExclusions(Arrays.asList("com.foo.Bar"));
|
||||
context.refresh();
|
||||
withDebugLogging(() -> this.initializer.onApplicationEvent(new ContextRefreshedEvent(context)));
|
||||
assertThat(capturedOutput).contains("not a servlet web application (OnWebApplicationCondition)");
|
||||
assertThat(output).contains("not a servlet web application (OnWebApplicationCondition)");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -122,7 +122,7 @@ class ConditionEvaluationReportLoggingListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void listenerWithInfoLevelShouldLogAtInfo(CapturedOutput capturedOutput) {
|
||||
void listenerWithInfoLevelShouldLogAtInfo(CapturedOutput output) {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
ConditionEvaluationReportLoggingListener initializer = new ConditionEvaluationReportLoggingListener(
|
||||
LogLevel.INFO);
|
||||
@ -130,7 +130,7 @@ class ConditionEvaluationReportLoggingListenerTests {
|
||||
context.register(Config.class);
|
||||
context.refresh();
|
||||
initializer.onApplicationEvent(new ContextRefreshedEvent(context));
|
||||
assertThat(capturedOutput).contains("CONDITIONS EVALUATION REPORT");
|
||||
assertThat(output).contains("CONDITIONS EVALUATION REPORT");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -141,10 +141,10 @@ class ConditionEvaluationReportLoggingListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void noErrorIfNotInitialized(CapturedOutput capturedOutput) {
|
||||
void noErrorIfNotInitialized(CapturedOutput output) {
|
||||
this.initializer.onApplicationEvent(new ApplicationFailedEvent(new SpringApplication(), new String[0], null,
|
||||
new RuntimeException("Planned")));
|
||||
assertThat(capturedOutput).contains("Unable to provide the conditions report");
|
||||
assertThat(output).contains("Unable to provide the conditions report");
|
||||
}
|
||||
|
||||
private void withDebugLogging(Runnable runnable) {
|
||||
|
@ -154,7 +154,7 @@ class QuartzAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void withConfiguredJobAndTrigger(CapturedOutput capturedOutput) {
|
||||
void withConfiguredJobAndTrigger(CapturedOutput output) {
|
||||
this.contextRunner.withUserConfiguration(QuartzFullConfiguration.class)
|
||||
.withPropertyValues("test-name=withConfiguredJobAndTrigger").run((context) -> {
|
||||
assertThat(context).hasSingleBean(Scheduler.class);
|
||||
@ -162,7 +162,7 @@ class QuartzAutoConfigurationTests {
|
||||
assertThat(scheduler.getJobDetail(JobKey.jobKey("fooJob"))).isNotNull();
|
||||
assertThat(scheduler.getTrigger(TriggerKey.triggerKey("fooTrigger"))).isNotNull();
|
||||
Thread.sleep(1000L);
|
||||
assertThat(capturedOutput).contains("withConfiguredJobAndTrigger").contains("jobDataValue");
|
||||
assertThat(output).contains("withConfiguredJobAndTrigger").contains("jobDataValue");
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -55,17 +55,15 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
class SecurityFilterAutoConfigurationEarlyInitializationTests {
|
||||
|
||||
@Test
|
||||
void testSecurityFilterDoesNotCauseEarlyInitialization(CapturedOutput capturedOutput) {
|
||||
void testSecurityFilterDoesNotCauseEarlyInitialization(CapturedOutput output) {
|
||||
try (AnnotationConfigServletWebServerApplicationContext context = new AnnotationConfigServletWebServerApplicationContext()) {
|
||||
TestPropertyValues.of("server.port:0").applyTo(context);
|
||||
context.register(Config.class);
|
||||
context.refresh();
|
||||
int port = context.getWebServer().getPort();
|
||||
String password = capturedOutput.toString().split("Using generated security password: ")[1].split("\n")[0]
|
||||
.trim();
|
||||
String password = output.toString().split("Using generated security password: ")[1].split("\n")[0].trim();
|
||||
new TestRestTemplate("user", password).getForEntity("http://localhost:" + port, Object.class);
|
||||
// If early initialization occurred a ConverterNotFoundException is thrown
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -60,40 +60,40 @@ class UserDetailsServiceAutoConfigurationTests {
|
||||
.withConfiguration(AutoConfigurations.of(UserDetailsServiceAutoConfiguration.class));
|
||||
|
||||
@Test
|
||||
void testDefaultUsernamePassword(CapturedOutput capturedOutput) {
|
||||
void testDefaultUsernamePassword(CapturedOutput output) {
|
||||
this.contextRunner.run((context) -> {
|
||||
UserDetailsService manager = context.getBean(UserDetailsService.class);
|
||||
assertThat(capturedOutput.toString()).contains("Using generated security password:");
|
||||
assertThat(output).contains("Using generated security password:");
|
||||
assertThat(manager.loadUserByUsername("user")).isNotNull();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void defaultUserNotCreatedIfAuthenticationManagerBeanPresent(CapturedOutput capturedOutput) {
|
||||
void defaultUserNotCreatedIfAuthenticationManagerBeanPresent(CapturedOutput output) {
|
||||
this.contextRunner.withUserConfiguration(TestAuthenticationManagerConfiguration.class).run((context) -> {
|
||||
AuthenticationManager manager = context.getBean(AuthenticationManager.class);
|
||||
assertThat(manager)
|
||||
.isEqualTo(context.getBean(TestAuthenticationManagerConfiguration.class).authenticationManager);
|
||||
assertThat(capturedOutput.toString()).doesNotContain("Using generated security password: ");
|
||||
assertThat(output).doesNotContain("Using generated security password: ");
|
||||
TestingAuthenticationToken token = new TestingAuthenticationToken("foo", "bar");
|
||||
assertThat(manager.authenticate(token)).isNotNull();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void defaultUserNotCreatedIfUserDetailsServiceBeanPresent(CapturedOutput capturedOutput) {
|
||||
void defaultUserNotCreatedIfUserDetailsServiceBeanPresent(CapturedOutput output) {
|
||||
this.contextRunner.withUserConfiguration(TestUserDetailsServiceConfiguration.class).run((context) -> {
|
||||
UserDetailsService userDetailsService = context.getBean(UserDetailsService.class);
|
||||
assertThat(capturedOutput.toString()).doesNotContain("Using generated security password: ");
|
||||
assertThat(output).doesNotContain("Using generated security password: ");
|
||||
assertThat(userDetailsService.loadUserByUsername("foo")).isNotNull();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void defaultUserNotCreatedIfAuthenticationProviderBeanPresent(CapturedOutput capturedOutput) {
|
||||
void defaultUserNotCreatedIfAuthenticationProviderBeanPresent(CapturedOutput output) {
|
||||
this.contextRunner.withUserConfiguration(TestAuthenticationProviderConfiguration.class).run((context) -> {
|
||||
AuthenticationProvider provider = context.getBean(AuthenticationProvider.class);
|
||||
assertThat(capturedOutput.toString()).doesNotContain("Using generated security password: ");
|
||||
assertThat(output).doesNotContain("Using generated security password: ");
|
||||
TestingAuthenticationToken token = new TestingAuthenticationToken("foo", "bar");
|
||||
assertThat(provider.authenticate(token)).isNotNull();
|
||||
});
|
||||
@ -131,10 +131,9 @@ class UserDetailsServiceAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void generatedPasswordShouldNotBePrintedIfAuthenticationManagerBuilderIsUsed(CapturedOutput capturedOutput) {
|
||||
void generatedPasswordShouldNotBePrintedIfAuthenticationManagerBuilderIsUsed(CapturedOutput output) {
|
||||
this.contextRunner.withUserConfiguration(TestConfigWithAuthenticationManagerBuilder.class)
|
||||
.run(((context) -> assertThat(capturedOutput.toString())
|
||||
.doesNotContain("Using generated security password: ")));
|
||||
.run(((context) -> assertThat(output).doesNotContain("Using generated security password: ")));
|
||||
}
|
||||
|
||||
private void testPasswordEncoding(Class<?> configClass, String providedPassword, String expectedPassword) {
|
||||
|
@ -98,13 +98,13 @@ class TaskExecutionAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void taskExecutorAutoConfigured(CapturedOutput capturedOutput) {
|
||||
void taskExecutorAutoConfigured(CapturedOutput output) {
|
||||
this.contextRunner.run((context) -> {
|
||||
assertThat(capturedOutput).doesNotContain("Initializing ExecutorService");
|
||||
assertThat(output).doesNotContain("Initializing ExecutorService");
|
||||
assertThat(context).hasSingleBean(Executor.class);
|
||||
assertThat(context).hasBean("applicationTaskExecutor");
|
||||
assertThat(context).getBean("applicationTaskExecutor").isInstanceOf(ThreadPoolTaskExecutor.class);
|
||||
assertThat(capturedOutput).contains("Initializing ExecutorService");
|
||||
assertThat(output).contains("Initializing ExecutorService");
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -159,16 +159,16 @@ class ThymeleafReactiveAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void templateLocationDoesNotExist(CapturedOutput capturedOutput) {
|
||||
void templateLocationDoesNotExist(CapturedOutput output) {
|
||||
this.contextRunner.withPropertyValues("spring.thymeleaf.prefix:classpath:/no-such-directory/")
|
||||
.run((context) -> assertThat(capturedOutput).contains("Cannot find template location"));
|
||||
.run((context) -> assertThat(output).contains("Cannot find template location"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void templateLocationEmpty(CapturedOutput capturedOutput) {
|
||||
void templateLocationEmpty(CapturedOutput output) {
|
||||
new File(this.buildOutput.getTestResourcesLocation(), "empty-templates/empty-directory").mkdirs();
|
||||
this.contextRunner.withPropertyValues("spring.thymeleaf.prefix:classpath:/empty-templates/empty-directory/")
|
||||
.run((context) -> assertThat(capturedOutput).doesNotContain("Cannot find template location"));
|
||||
.run((context) -> assertThat(output).doesNotContain("Cannot find template location"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -165,16 +165,16 @@ class ThymeleafServletAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void templateLocationDoesNotExist(CapturedOutput capturedOutput) {
|
||||
void templateLocationDoesNotExist(CapturedOutput output) {
|
||||
this.contextRunner.withPropertyValues("spring.thymeleaf.prefix:classpath:/no-such-directory/")
|
||||
.run((context) -> assertThat(capturedOutput).contains("Cannot find template location"));
|
||||
.run((context) -> assertThat(output).contains("Cannot find template location"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void templateLocationEmpty(CapturedOutput capturedOutput) {
|
||||
void templateLocationEmpty(CapturedOutput output) {
|
||||
new File(this.buildOutput.getTestResourcesLocation(), "empty-templates/empty-directory").mkdirs();
|
||||
this.contextRunner.withPropertyValues("spring.thymeleaf.prefix:classpath:/empty-templates/empty-directory/")
|
||||
.run((context) -> assertThat(capturedOutput).doesNotContain("Cannot find template location"));
|
||||
.run((context) -> assertThat(output).doesNotContain("Cannot find template location"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -72,7 +72,7 @@ class DefaultErrorWebExceptionHandlerIntegrationTests {
|
||||
.withUserConfiguration(Application.class);
|
||||
|
||||
@Test
|
||||
void jsonError(CapturedOutput capturedOutput) {
|
||||
void jsonError(CapturedOutput output) {
|
||||
this.contextRunner.run((context) -> {
|
||||
WebTestClient client = getWebClient(context);
|
||||
client.get().uri("/").exchange().expectStatus().isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR).expectBody()
|
||||
@ -80,7 +80,7 @@ class DefaultErrorWebExceptionHandlerIntegrationTests {
|
||||
.isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase()).jsonPath("path").isEqualTo(("/"))
|
||||
.jsonPath("message").isEqualTo("Expected!").jsonPath("exception").doesNotExist().jsonPath("trace")
|
||||
.doesNotExist().jsonPath("requestId").isEqualTo(this.logIdFilter.getLogId());
|
||||
assertThat(capturedOutput).contains("500 Server Error for HTTP GET \"/\"")
|
||||
assertThat(output).contains("500 Server Error for HTTP GET \"/\"")
|
||||
.contains("java.lang.IllegalStateException: Expected!");
|
||||
});
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ class ErrorMvcAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void renderWhenAlreadyCommittedLogsMessage(CapturedOutput capturedOutput) {
|
||||
void renderWhenAlreadyCommittedLogsMessage(CapturedOutput output) {
|
||||
this.contextRunner.run((context) -> {
|
||||
View errorView = context.getBean("error", View.class);
|
||||
ErrorAttributes errorAttributes = context.getBean(ErrorAttributes.class);
|
||||
@ -71,7 +71,7 @@ class ErrorMvcAutoConfigurationTests {
|
||||
true);
|
||||
errorView.render(errorAttributes.getErrorAttributes(webRequest, true), webRequest.getRequest(),
|
||||
webRequest.getResponse());
|
||||
assertThat(capturedOutput).contains("Cannot render error page for request [/path] "
|
||||
assertThat(output).contains("Cannot render error page for request [/path] "
|
||||
+ "and exception [Exception message] as the response has "
|
||||
+ "already been committed. As a result, the response may " + "have the wrong status code.");
|
||||
});
|
||||
|
@ -36,8 +36,8 @@ class ClassLoaderIntegrationTests {
|
||||
@RegisterExtension
|
||||
CliTester cli;
|
||||
|
||||
ClassLoaderIntegrationTests(CapturedOutput capturedOutput) {
|
||||
this.cli = new CliTester("src/test/resources/", capturedOutput);
|
||||
ClassLoaderIntegrationTests(CapturedOutput output) {
|
||||
this.cli = new CliTester("src/test/resources/", output);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -63,7 +63,7 @@ public class CliTester implements BeforeEachCallback, AfterEachCallback {
|
||||
|
||||
private final BuildOutput buildOutput = new BuildOutput(getClass());
|
||||
|
||||
private final CapturedOutput capturedOutput;
|
||||
private final CapturedOutput output;
|
||||
|
||||
private String previousOutput = "";
|
||||
|
||||
@ -75,7 +75,7 @@ public class CliTester implements BeforeEachCallback, AfterEachCallback {
|
||||
|
||||
private File serverPortFile;
|
||||
|
||||
public CliTester(String prefix, CapturedOutput capturedOutput) {
|
||||
public CliTester(String prefix, CapturedOutput output) {
|
||||
this.prefix = prefix;
|
||||
try {
|
||||
this.temp = Files.createTempDirectory("cli-tester").toFile();
|
||||
@ -83,7 +83,7 @@ public class CliTester implements BeforeEachCallback, AfterEachCallback {
|
||||
catch (IOException ex) {
|
||||
throw new IllegalStateException("Failed to create temp directory");
|
||||
}
|
||||
this.capturedOutput = capturedOutput;
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
public void setTimeout(long timeout) {
|
||||
@ -182,7 +182,7 @@ public class CliTester implements BeforeEachCallback, AfterEachCallback {
|
||||
}
|
||||
|
||||
private String getOutput() {
|
||||
String output = this.capturedOutput.toString().substring(this.previousOutput.length());
|
||||
String output = this.output.toString().substring(this.previousOutput.length());
|
||||
this.previousOutput = output;
|
||||
return output;
|
||||
}
|
||||
|
@ -36,8 +36,8 @@ class DirectorySourcesIntegrationTests {
|
||||
@RegisterExtension
|
||||
CliTester cli;
|
||||
|
||||
DirectorySourcesIntegrationTests(CapturedOutput capturedOutput) {
|
||||
this.cli = new CliTester("src/test/resources/dir-sample/", capturedOutput);
|
||||
DirectorySourcesIntegrationTests(CapturedOutput output) {
|
||||
this.cli = new CliTester("src/test/resources/dir-sample/", output);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -44,8 +44,8 @@ class GrabCommandIntegrationTests {
|
||||
@RegisterExtension
|
||||
CliTester cli;
|
||||
|
||||
GrabCommandIntegrationTests(CapturedOutput capturedOutput) {
|
||||
this.cli = new CliTester("src/test/resources/grab-samples/", capturedOutput);
|
||||
GrabCommandIntegrationTests(CapturedOutput output) {
|
||||
this.cli = new CliTester("src/test/resources/grab-samples/", output);
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
|
@ -41,8 +41,8 @@ class ReproIntegrationTests {
|
||||
@RegisterExtension
|
||||
CliTester cli;
|
||||
|
||||
ReproIntegrationTests(CapturedOutput capturedOutput) {
|
||||
this.cli = new CliTester("src/test/resources/repro-samples/", capturedOutput);
|
||||
ReproIntegrationTests(CapturedOutput output) {
|
||||
this.cli = new CliTester("src/test/resources/repro-samples/", output);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -41,8 +41,8 @@ class RunCommandIntegrationTests {
|
||||
@RegisterExtension
|
||||
CliTester cli;
|
||||
|
||||
RunCommandIntegrationTests(CapturedOutput capturedOutput) {
|
||||
this.cli = new CliTester("src/it/resources/run-command/", capturedOutput);
|
||||
RunCommandIntegrationTests(CapturedOutput output) {
|
||||
this.cli = new CliTester("src/it/resources/run-command/", output);
|
||||
}
|
||||
|
||||
private Properties systemProperties = new Properties();
|
||||
|
@ -43,8 +43,8 @@ class SampleIntegrationTests {
|
||||
@RegisterExtension
|
||||
CliTester cli;
|
||||
|
||||
SampleIntegrationTests(CapturedOutput capturedOutput) {
|
||||
this.cli = new CliTester("samples/", capturedOutput);
|
||||
SampleIntegrationTests(CapturedOutput output) {
|
||||
this.cli = new CliTester("samples/", output);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -78,21 +78,21 @@ class RemoteClientConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void warnIfRestartDisabled(CapturedOutput capturedOutput) {
|
||||
void warnIfRestartDisabled(CapturedOutput output) {
|
||||
configure("spring.devtools.remote.restart.enabled:false");
|
||||
assertThat(capturedOutput).contains("Remote restart is disabled");
|
||||
assertThat(output).contains("Remote restart is disabled");
|
||||
}
|
||||
|
||||
@Test
|
||||
void warnIfNotHttps(CapturedOutput capturedOutput) {
|
||||
void warnIfNotHttps(CapturedOutput output) {
|
||||
configure("http://localhost", true);
|
||||
assertThat(capturedOutput).contains("is insecure");
|
||||
assertThat(output).contains("is insecure");
|
||||
}
|
||||
|
||||
@Test
|
||||
void doesntWarnIfUsingHttps(CapturedOutput capturedOutput) {
|
||||
void doesntWarnIfUsingHttps(CapturedOutput output) {
|
||||
configure("https://localhost", true);
|
||||
assertThat(capturedOutput).doesNotContain("is insecure");
|
||||
assertThat(output).doesNotContain("is insecure");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -80,11 +80,11 @@ class RestartApplicationListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void disableWithSystemProperty(CapturedOutput capturedOutput) {
|
||||
void disableWithSystemProperty(CapturedOutput output) {
|
||||
System.setProperty(ENABLED_PROPERTY, "false");
|
||||
testInitialize(false);
|
||||
assertThat(Restarter.getInstance()).hasFieldOrPropertyWithValue("enabled", false);
|
||||
assertThat(capturedOutput).contains("Restart disabled due to System property");
|
||||
assertThat(output).contains("Restart disabled due to System property");
|
||||
}
|
||||
|
||||
private void testInitialize(boolean failed) {
|
||||
|
@ -76,14 +76,13 @@ class RestarterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRestart(CapturedOutput capturedOutput) throws Exception {
|
||||
void testRestart(CapturedOutput output) throws Exception {
|
||||
Restarter.clearInstance();
|
||||
Thread thread = new Thread(SampleApplication::main);
|
||||
thread.start();
|
||||
Thread.sleep(2600);
|
||||
String output = capturedOutput.toString();
|
||||
assertThat(StringUtils.countOccurrencesOf(output, "Tick 0")).isGreaterThan(1);
|
||||
assertThat(StringUtils.countOccurrencesOf(output, "Tick 1")).isGreaterThan(1);
|
||||
assertThat(StringUtils.countOccurrencesOf(output.toString(), "Tick 0")).isGreaterThan(1);
|
||||
assertThat(StringUtils.countOccurrencesOf(output.toString(), "Tick 1")).isGreaterThan(1);
|
||||
assertThat(CloseCountingApplicationListener.closed).isGreaterThan(0);
|
||||
}
|
||||
|
||||
|
@ -139,11 +139,11 @@ class HttpTunnelConnectionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void connectFailureLogsWarning(CapturedOutput capturedOutput) throws Exception {
|
||||
void connectFailureLogsWarning(CapturedOutput output) throws Exception {
|
||||
this.requestFactory.willRespond(new ConnectException());
|
||||
TunnelChannel tunnel = openTunnel(true);
|
||||
assertThat(tunnel.isOpen()).isFalse();
|
||||
assertThat(capturedOutput).contains("Failed to connect to remote application at http://localhost:12345");
|
||||
assertThat(output).contains("Failed to connect to remote application at http://localhost:12345");
|
||||
}
|
||||
|
||||
private void write(TunnelChannel channel, String string) throws IOException {
|
||||
|
@ -33,11 +33,11 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
class SpringApplicationBuilderExampleTests {
|
||||
|
||||
@Test
|
||||
void contextHierarchyWithDisabledBanner(CapturedOutput capturedOutput) {
|
||||
void contextHierarchyWithDisabledBanner(CapturedOutput output) {
|
||||
System.setProperty("spring.main.web-application-type", "none");
|
||||
try {
|
||||
new SpringApplicationBuilderExample().hierarchyWithDisabledBanner(new String[0]);
|
||||
assertThat(capturedOutput).doesNotContain(":: Spring Boot ::");
|
||||
assertThat(output).doesNotContain(":: Spring Boot ::");
|
||||
}
|
||||
finally {
|
||||
System.clearProperty("spring.main.web-application-type");
|
||||
|
@ -46,9 +46,9 @@ class PropertiesMigrationListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void sampleReport(CapturedOutput capturedOutput) {
|
||||
void sampleReport(CapturedOutput output) {
|
||||
this.context = createSampleApplication().run("--banner.charset=UTF8");
|
||||
assertThat(capturedOutput).contains("commandLineArgs").contains("spring.banner.charset")
|
||||
assertThat(output).contains("commandLineArgs").contains("spring.banner.charset")
|
||||
.contains("Each configuration key has been temporarily mapped")
|
||||
.doesNotContain("Please refer to the migration guide");
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ class SpringBootDependencyInjectionTestExecutionListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void prepareFailingTestInstanceShouldPrintReport(CapturedOutput capturedOutput) throws Exception {
|
||||
void prepareFailingTestInstanceShouldPrintReport(CapturedOutput output) throws Exception {
|
||||
TestContext testContext = mock(TestContext.class);
|
||||
given(testContext.getTestInstance()).willThrow(new IllegalStateException());
|
||||
SpringApplication application = new SpringApplication(Config.class);
|
||||
@ -66,7 +66,7 @@ class SpringBootDependencyInjectionTestExecutionListenerTests {
|
||||
catch (IllegalStateException ex) {
|
||||
// Expected
|
||||
}
|
||||
assertThat(capturedOutput).contains("CONDITIONS EVALUATION REPORT").contains("Positive matches")
|
||||
assertThat(output).contains("CONDITIONS EVALUATION REPORT").contains("Positive matches")
|
||||
.contains("Negative matches");
|
||||
}
|
||||
|
||||
|
@ -57,9 +57,9 @@ class MockMvcSpringBootTestIntegrationTests {
|
||||
private MockMvc mvc;
|
||||
|
||||
@Test
|
||||
void shouldFindController1(CapturedOutput capturedOutput) throws Exception {
|
||||
void shouldFindController1(CapturedOutput output) throws Exception {
|
||||
this.mvc.perform(get("/one")).andExpect(content().string("one")).andExpect(status().isOk());
|
||||
assertThat(capturedOutput).contains("Request URI = /one");
|
||||
assertThat(output).contains("Request URI = /one");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -47,9 +47,9 @@ class WebMvcTestPrintAlwaysIntegrationTests {
|
||||
private MockMvc mvc;
|
||||
|
||||
@Test
|
||||
void shouldPrint(CapturedOutput capturedOutput) throws Exception {
|
||||
void shouldPrint(CapturedOutput output) throws Exception {
|
||||
this.mvc.perform(get("/one")).andExpect(content().string("one")).andExpect(status().isOk());
|
||||
assertThat(capturedOutput).contains("Request URI = /one");
|
||||
assertThat(output).contains("Request URI = /one");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -47,15 +47,15 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
class WebMvcTestPrintDefaultIntegrationTests {
|
||||
|
||||
@Test
|
||||
void shouldNotPrint(CapturedOutput capturedOutput) {
|
||||
void shouldNotPrint(CapturedOutput output) {
|
||||
executeTests(ShouldNotPrint.class);
|
||||
assertThat(capturedOutput).doesNotContain("HTTP Method");
|
||||
assertThat(output).doesNotContain("HTTP Method");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldPrint(CapturedOutput capturedOutput) {
|
||||
void shouldPrint(CapturedOutput output) {
|
||||
executeTests(ShouldPrint.class);
|
||||
assertThat(capturedOutput).contains("HTTP Method");
|
||||
assertThat(output).contains("HTTP Method");
|
||||
}
|
||||
|
||||
private void executeTests(Class<?> testClass) {
|
||||
|
@ -47,9 +47,9 @@ class WebMvcTestPrintDefaultOverrideIntegrationTests {
|
||||
private MockMvc mvc;
|
||||
|
||||
@Test
|
||||
void shouldFindController1(CapturedOutput capturedOutput) throws Exception {
|
||||
void shouldFindController1(CapturedOutput output) throws Exception {
|
||||
this.mvc.perform(get("/one")).andExpect(content().string("one")).andExpect(status().isOk());
|
||||
assertThat(capturedOutput).doesNotContain("Request URI = /one");
|
||||
assertThat(output).doesNotContain("Request URI = /one");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -48,9 +48,9 @@ class WebMvcTestPrintOverrideIntegrationTests {
|
||||
private MockMvc mvc;
|
||||
|
||||
@Test
|
||||
void shouldNotPrint(CapturedOutput capturedOutput) throws Exception {
|
||||
void shouldNotPrint(CapturedOutput output) throws Exception {
|
||||
this.mvc.perform(get("/one")).andExpect(content().string("one")).andExpect(status().isOk());
|
||||
assertThat(capturedOutput).doesNotContain("Request URI = /one");
|
||||
assertThat(output).doesNotContain("Request URI = /one");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -59,13 +59,13 @@ class PropertiesLauncherTests {
|
||||
|
||||
private ClassLoader contextClassLoader;
|
||||
|
||||
private CapturedOutput capturedOutput;
|
||||
private CapturedOutput output;
|
||||
|
||||
@BeforeEach
|
||||
void setup(CapturedOutput capturedOutput) {
|
||||
this.contextClassLoader = Thread.currentThread().getContextClassLoader();
|
||||
System.setProperty("loader.home", new File("src/test/resources").getAbsolutePath());
|
||||
this.capturedOutput = capturedOutput;
|
||||
this.output = capturedOutput;
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
@ -312,8 +312,8 @@ class PropertiesLauncherTests {
|
||||
manifest.getMainAttributes().putValue("Loader-Path", "/foo.jar, /bar");
|
||||
File manifestFile = new File(this.tempDir, "META-INF/MANIFEST.MF");
|
||||
manifestFile.getParentFile().mkdirs();
|
||||
try (FileOutputStream output = new FileOutputStream(manifestFile)) {
|
||||
manifest.write(output);
|
||||
try (FileOutputStream manifestStream = new FileOutputStream(manifestFile)) {
|
||||
manifest.write(manifestStream);
|
||||
}
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertThat((List<String>) ReflectionTestUtils.getField(launcher, "paths")).containsExactly("/foo.jar", "/bar/");
|
||||
@ -344,7 +344,7 @@ class PropertiesLauncherTests {
|
||||
while (!timeout && count < 100) {
|
||||
count++;
|
||||
Thread.sleep(50L);
|
||||
timeout = this.capturedOutput.toString().contains(value);
|
||||
timeout = this.output.toString().contains(value);
|
||||
}
|
||||
assertThat(timeout).as("Timed out waiting for (" + value + ")").isTrue();
|
||||
}
|
||||
|
@ -68,25 +68,25 @@ class BannerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDefaultBanner(CapturedOutput capturedOutput) {
|
||||
void testDefaultBanner(CapturedOutput output) {
|
||||
SpringApplication application = createSpringApplication();
|
||||
this.context = application.run();
|
||||
assertThat(capturedOutput).contains(":: Spring Boot ::");
|
||||
assertThat(output).contains(":: Spring Boot ::");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDefaultBannerInLog(CapturedOutput capturedOutput) {
|
||||
void testDefaultBannerInLog(CapturedOutput output) {
|
||||
SpringApplication application = createSpringApplication();
|
||||
this.context = application.run();
|
||||
assertThat(capturedOutput).contains(":: Spring Boot ::");
|
||||
assertThat(output).contains(":: Spring Boot ::");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCustomBanner(CapturedOutput capturedOutput) {
|
||||
void testCustomBanner(CapturedOutput output) {
|
||||
SpringApplication application = createSpringApplication();
|
||||
application.setBanner(new DummyBanner());
|
||||
this.context = application.run();
|
||||
assertThat(capturedOutput).contains("My Banner");
|
||||
assertThat(output).contains("My Banner");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -49,27 +49,27 @@ class SimpleMainTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void basePackageScan(CapturedOutput capturedOutput) throws Exception {
|
||||
void basePackageScan(CapturedOutput output) throws Exception {
|
||||
SpringApplication.main(getArgs(ClassUtils.getPackageName(getClass()) + ".sampleconfig"));
|
||||
assertThat(capturedOutput).contains(SPRING_STARTUP);
|
||||
assertThat(output).contains(SPRING_STARTUP);
|
||||
}
|
||||
|
||||
@Test
|
||||
void configClassContext(CapturedOutput capturedOutput) throws Exception {
|
||||
void configClassContext(CapturedOutput output) throws Exception {
|
||||
SpringApplication.main(getArgs(getClass().getName()));
|
||||
assertThat(capturedOutput).contains(SPRING_STARTUP);
|
||||
assertThat(output).contains(SPRING_STARTUP);
|
||||
}
|
||||
|
||||
@Test
|
||||
void xmlContext(CapturedOutput capturedOutput) throws Exception {
|
||||
void xmlContext(CapturedOutput output) throws Exception {
|
||||
SpringApplication.main(getArgs("org/springframework/boot/sample-beans.xml"));
|
||||
assertThat(capturedOutput).contains(SPRING_STARTUP);
|
||||
assertThat(output).contains(SPRING_STARTUP);
|
||||
}
|
||||
|
||||
@Test
|
||||
void mixedContext(CapturedOutput capturedOutput) throws Exception {
|
||||
void mixedContext(CapturedOutput output) throws Exception {
|
||||
SpringApplication.main(getArgs(getClass().getName(), "org/springframework/boot/sample-beans.xml"));
|
||||
assertThat(capturedOutput).contains(SPRING_STARTUP);
|
||||
assertThat(output).contains(SPRING_STARTUP);
|
||||
}
|
||||
|
||||
private String[] getArgs(String... args) {
|
||||
|
@ -188,24 +188,24 @@ class SpringApplicationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void customBanner(CapturedOutput capturedOutput) {
|
||||
void customBanner(CapturedOutput output) {
|
||||
SpringApplication application = spy(new SpringApplication(ExampleConfig.class));
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
this.context = application.run("--spring.banner.location=classpath:test-banner.txt");
|
||||
assertThat(capturedOutput).startsWith("Running a Test!");
|
||||
assertThat(output).startsWith("Running a Test!");
|
||||
}
|
||||
|
||||
@Test
|
||||
void customBannerWithProperties(CapturedOutput capturedOutput) {
|
||||
void customBannerWithProperties(CapturedOutput output) {
|
||||
SpringApplication application = spy(new SpringApplication(ExampleConfig.class));
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
this.context = application.run("--spring.banner.location=classpath:test-banner-with-placeholder.txt",
|
||||
"--test.property=123456");
|
||||
assertThat(capturedOutput).containsPattern("Running a Test!\\s+123456");
|
||||
assertThat(output).containsPattern("Running a Test!\\s+123456");
|
||||
}
|
||||
|
||||
@Test
|
||||
void imageBannerAndTextBanner(CapturedOutput capturedOutput) {
|
||||
void imageBannerAndTextBanner(CapturedOutput output) {
|
||||
SpringApplication application = new SpringApplication(ExampleConfig.class);
|
||||
MockResourceLoader resourceLoader = new MockResourceLoader();
|
||||
resourceLoader.addResource("banner.gif", "black-and-white.gif");
|
||||
@ -213,47 +213,47 @@ class SpringApplicationTests {
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
application.setResourceLoader(resourceLoader);
|
||||
application.run();
|
||||
assertThat(capturedOutput).contains("@@@@").contains("Foo Bar");
|
||||
assertThat(output).contains("@@@@").contains("Foo Bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
void imageBannerLoads(CapturedOutput capturedOutput) {
|
||||
void imageBannerLoads(CapturedOutput output) {
|
||||
SpringApplication application = new SpringApplication(ExampleConfig.class);
|
||||
MockResourceLoader resourceLoader = new MockResourceLoader();
|
||||
resourceLoader.addResource("banner.gif", "black-and-white.gif");
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
application.setResourceLoader(resourceLoader);
|
||||
application.run();
|
||||
assertThat(capturedOutput).contains("@@@@@@");
|
||||
assertThat(output).contains("@@@@@@");
|
||||
}
|
||||
|
||||
@Test
|
||||
void logsNoActiveProfiles(CapturedOutput capturedOutput) {
|
||||
void logsNoActiveProfiles(CapturedOutput output) {
|
||||
SpringApplication application = new SpringApplication(ExampleConfig.class);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
this.context = application.run();
|
||||
assertThat(capturedOutput).contains("No active profile set, falling back to default profiles: default");
|
||||
assertThat(output).contains("No active profile set, falling back to default profiles: default");
|
||||
}
|
||||
|
||||
@Test
|
||||
void logsActiveProfiles(CapturedOutput capturedOutput) {
|
||||
void logsActiveProfiles(CapturedOutput output) {
|
||||
SpringApplication application = new SpringApplication(ExampleConfig.class);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
this.context = application.run("--spring.profiles.active=myprofiles");
|
||||
assertThat(capturedOutput).contains("The following profiles are active: myprofile");
|
||||
assertThat(output).contains("The following profiles are active: myprofile");
|
||||
}
|
||||
|
||||
@Test
|
||||
void enableBannerInLogViaProperty(CapturedOutput capturedOutput) {
|
||||
void enableBannerInLogViaProperty(CapturedOutput output) {
|
||||
SpringApplication application = spy(new SpringApplication(ExampleConfig.class));
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
this.context = application.run("--spring.main.banner-mode=log");
|
||||
verify(application, atLeastOnce()).setBannerMode(Banner.Mode.LOG);
|
||||
assertThat(capturedOutput).contains("o.s.b.SpringApplication");
|
||||
assertThat(output).contains("o.s.b.SpringApplication");
|
||||
}
|
||||
|
||||
@Test
|
||||
void setIgnoreBeanInfoPropertyByDefault(CapturedOutput capturedOutput) {
|
||||
void setIgnoreBeanInfoPropertyByDefault(CapturedOutput output) {
|
||||
SpringApplication application = new SpringApplication(ExampleConfig.class);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
this.context = application.run();
|
||||
@ -627,7 +627,7 @@ class SpringApplicationTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void runnersAreCalledAfterStartedIsLoggedAndBeforeApplicationReadyEventIsPublished(CapturedOutput capturedOutput)
|
||||
void runnersAreCalledAfterStartedIsLoggedAndBeforeApplicationReadyEventIsPublished(CapturedOutput output)
|
||||
throws Exception {
|
||||
SpringApplication application = new SpringApplication(ExampleConfig.class);
|
||||
ApplicationRunner applicationRunner = mock(ApplicationRunner.class);
|
||||
@ -635,11 +635,11 @@ class SpringApplicationTests {
|
||||
application.addInitializers((context) -> {
|
||||
ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
|
||||
beanFactory.registerSingleton("commandLineRunner", (CommandLineRunner) (args) -> {
|
||||
assertThat(capturedOutput).contains("Started");
|
||||
assertThat(output).contains("Started");
|
||||
commandLineRunner.run(args);
|
||||
});
|
||||
beanFactory.registerSingleton("applicationRunner", (ApplicationRunner) (args) -> {
|
||||
assertThat(capturedOutput).contains("Started");
|
||||
assertThat(output).contains("Started");
|
||||
applicationRunner.run(args);
|
||||
});
|
||||
});
|
||||
@ -706,7 +706,7 @@ class SpringApplicationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void failureInReadyEventListenerCloseApplicationContext(CapturedOutput capturedOutput) {
|
||||
void failureInReadyEventListenerCloseApplicationContext(CapturedOutput output) {
|
||||
SpringApplication application = new SpringApplication(ExampleConfig.class);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
ExitCodeListener exitCodeListener = new ExitCodeListener();
|
||||
@ -720,7 +720,7 @@ class SpringApplicationTests {
|
||||
verify(listener).onApplicationEvent(isA(ApplicationReadyEvent.class));
|
||||
verify(listener, never()).onApplicationEvent(isA(ApplicationFailedEvent.class));
|
||||
assertThat(exitCodeListener.getExitCode()).isEqualTo(11);
|
||||
assertThat(capturedOutput).contains("Application run failed");
|
||||
assertThat(output).contains("Application run failed");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -815,7 +815,7 @@ class SpringApplicationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void exceptionFromRefreshIsHandledGracefully(CapturedOutput capturedOutput) {
|
||||
void exceptionFromRefreshIsHandledGracefully(CapturedOutput output) {
|
||||
final SpringBootExceptionHandler handler = mock(SpringBootExceptionHandler.class);
|
||||
SpringApplication application = new SpringApplication(RefreshFailureConfig.class) {
|
||||
|
||||
@ -832,7 +832,7 @@ class SpringApplicationTests {
|
||||
ArgumentCaptor<RuntimeException> exceptionCaptor = ArgumentCaptor.forClass(RuntimeException.class);
|
||||
verify(handler).registerLoggedException(exceptionCaptor.capture());
|
||||
assertThat(exceptionCaptor.getValue()).hasCauseInstanceOf(RefreshFailureException.class);
|
||||
assertThat(capturedOutput).doesNotContain("NullPointerException");
|
||||
assertThat(output).doesNotContain("NullPointerException");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1046,19 +1046,21 @@ class SpringApplicationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void failureResultsInSingleStackTrace(CapturedOutput capturedOutput) throws Exception {
|
||||
void failureResultsInSingleStackTrace(CapturedOutput output) throws Exception {
|
||||
ThreadGroup group = new ThreadGroup("main");
|
||||
Thread thread = new Thread(group, "main") {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
SpringApplication application = new SpringApplication(FailingConfig.class);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
application.run();
|
||||
}
|
||||
|
||||
};
|
||||
thread.start();
|
||||
thread.join(6000);
|
||||
assertThat(capturedOutput).containsOnlyOnce("Caused by: java.lang.RuntimeException: ExpectedError");
|
||||
assertThat(output).containsOnlyOnce("Caused by: java.lang.RuntimeException: ExpectedError");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -54,57 +54,57 @@ class ConfigurationWarningsApplicationContextInitializerTests {
|
||||
+ "start due to a @ComponentScan of 'org.springframework'.";
|
||||
|
||||
@Test
|
||||
void logWarningInDefaultPackage(CapturedOutput capturedOutput) {
|
||||
void logWarningInDefaultPackage(CapturedOutput output) {
|
||||
load(InDefaultPackageConfiguration.class);
|
||||
assertThat(capturedOutput).contains(DEFAULT_SCAN_WARNING);
|
||||
assertThat(output).contains(DEFAULT_SCAN_WARNING);
|
||||
}
|
||||
|
||||
@Test
|
||||
void logWarningInDefaultPackageAndMetaAnnotation(CapturedOutput capturedOutput) {
|
||||
void logWarningInDefaultPackageAndMetaAnnotation(CapturedOutput output) {
|
||||
load(InDefaultPackageWithMetaAnnotationConfiguration.class);
|
||||
assertThat(capturedOutput).contains(DEFAULT_SCAN_WARNING);
|
||||
assertThat(output).contains(DEFAULT_SCAN_WARNING);
|
||||
}
|
||||
|
||||
@Test
|
||||
void noLogIfInRealPackage(CapturedOutput capturedOutput) {
|
||||
void noLogIfInRealPackage(CapturedOutput output) {
|
||||
load(InRealPackageConfiguration.class);
|
||||
assertThat(capturedOutput).doesNotContain(DEFAULT_SCAN_WARNING);
|
||||
assertThat(output).doesNotContain(DEFAULT_SCAN_WARNING);
|
||||
}
|
||||
|
||||
@Test
|
||||
void noLogWithoutComponentScanAnnotation(CapturedOutput capturedOutput) {
|
||||
void noLogWithoutComponentScanAnnotation(CapturedOutput output) {
|
||||
load(InDefaultPackageWithoutScanConfiguration.class);
|
||||
assertThat(capturedOutput).doesNotContain(DEFAULT_SCAN_WARNING);
|
||||
assertThat(output).doesNotContain(DEFAULT_SCAN_WARNING);
|
||||
}
|
||||
|
||||
@Test
|
||||
void noLogIfHasValue(CapturedOutput capturedOutput) {
|
||||
void noLogIfHasValue(CapturedOutput output) {
|
||||
load(InDefaultPackageWithValueConfiguration.class);
|
||||
assertThat(capturedOutput).doesNotContain(DEFAULT_SCAN_WARNING);
|
||||
assertThat(output).doesNotContain(DEFAULT_SCAN_WARNING);
|
||||
}
|
||||
|
||||
@Test
|
||||
void noLogIfHasBasePackages(CapturedOutput capturedOutput) {
|
||||
void noLogIfHasBasePackages(CapturedOutput output) {
|
||||
load(InDefaultPackageWithBasePackagesConfiguration.class);
|
||||
assertThat(capturedOutput).doesNotContain(DEFAULT_SCAN_WARNING);
|
||||
assertThat(output).doesNotContain(DEFAULT_SCAN_WARNING);
|
||||
}
|
||||
|
||||
@Test
|
||||
void noLogIfHasBasePackageClasses(CapturedOutput capturedOutput) {
|
||||
void noLogIfHasBasePackageClasses(CapturedOutput output) {
|
||||
load(InDefaultPackageWithBasePackageClassesConfiguration.class);
|
||||
assertThat(capturedOutput).doesNotContain(DEFAULT_SCAN_WARNING);
|
||||
assertThat(output).doesNotContain(DEFAULT_SCAN_WARNING);
|
||||
}
|
||||
|
||||
@Test
|
||||
void logWarningInOrgSpringPackage(CapturedOutput capturedOutput) {
|
||||
void logWarningInOrgSpringPackage(CapturedOutput output) {
|
||||
load(InOrgSpringPackageConfiguration.class);
|
||||
assertThat(capturedOutput).contains(ORGSPRING_SCAN_WARNING);
|
||||
assertThat(output).contains(ORGSPRING_SCAN_WARNING);
|
||||
}
|
||||
|
||||
@Test
|
||||
void logWarningIfScanningProblemPackages(CapturedOutput capturedOutput) {
|
||||
void logWarningIfScanningProblemPackages(CapturedOutput output) {
|
||||
load(InRealButScanningProblemPackages.class);
|
||||
assertThat(capturedOutput).contains("Your ApplicationContext is unlikely to start due to a "
|
||||
assertThat(output).contains("Your ApplicationContext is unlikely to start due to a "
|
||||
+ "@ComponentScan of the default package, 'org.springframework'.");
|
||||
|
||||
}
|
||||
|
@ -418,54 +418,54 @@ class ConfigFileApplicationListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void profilesAddedToEnvironmentAndViaProperty(CapturedOutput capturedOutput) {
|
||||
void profilesAddedToEnvironmentAndViaProperty(CapturedOutput output) {
|
||||
// External profile takes precedence over profile added via the environment
|
||||
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment, "spring.profiles.active=other");
|
||||
this.environment.addActiveProfile("dev");
|
||||
this.initializer.postProcessEnvironment(this.environment, this.application);
|
||||
assertThat(this.environment.getActiveProfiles()).contains("dev", "other");
|
||||
assertThat(this.environment.getProperty("my.property")).isEqualTo("fromotherpropertiesfile");
|
||||
validateProfilePreference(capturedOutput, null, "dev", "other");
|
||||
validateProfilePreference(output, null, "dev", "other");
|
||||
}
|
||||
|
||||
@Test
|
||||
void profilesAddedToEnvironmentViaActiveAndIncludeProperty(CapturedOutput capturedOutput) {
|
||||
void profilesAddedToEnvironmentViaActiveAndIncludeProperty(CapturedOutput output) {
|
||||
// Active profile property takes precedence
|
||||
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment, "spring.profiles.active=dev",
|
||||
"spring.profiles.include=other");
|
||||
this.initializer.postProcessEnvironment(this.environment, this.application);
|
||||
assertThat(this.environment.getActiveProfiles()).containsExactly("other", "dev");
|
||||
assertThat(this.environment.getProperty("my.property")).isEqualTo("fromdevpropertiesfile");
|
||||
validateProfilePreference(capturedOutput, null, "other", "dev");
|
||||
validateProfilePreference(output, null, "other", "dev");
|
||||
}
|
||||
|
||||
@Test
|
||||
void profilesAddedViaIncludePropertyAndActivatedViaAnotherPropertySource(CapturedOutput capturedOutput) {
|
||||
void profilesAddedViaIncludePropertyAndActivatedViaAnotherPropertySource(CapturedOutput output) {
|
||||
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment,
|
||||
"spring.profiles.include=dev,simple");
|
||||
this.initializer.postProcessEnvironment(this.environment, this.application);
|
||||
assertThat(this.environment.getActiveProfiles()).containsExactly("dev", "simple", "other");
|
||||
validateProfilePreference(capturedOutput, "dev", "simple", "other");
|
||||
validateProfilePreference(output, "dev", "simple", "other");
|
||||
}
|
||||
|
||||
@Test
|
||||
void profilesAddedToEnvironmentAndViaPropertyDuplicate(CapturedOutput capturedOutput) {
|
||||
void profilesAddedToEnvironmentAndViaPropertyDuplicate(CapturedOutput output) {
|
||||
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment, "spring.profiles.active=dev,other");
|
||||
this.environment.addActiveProfile("dev");
|
||||
this.initializer.postProcessEnvironment(this.environment, this.application);
|
||||
assertThat(this.environment.getActiveProfiles()).contains("dev", "other");
|
||||
assertThat(this.environment.getProperty("my.property")).isEqualTo("fromotherpropertiesfile");
|
||||
validateProfilePreference(capturedOutput, null, "dev", "other");
|
||||
validateProfilePreference(output, null, "dev", "other");
|
||||
}
|
||||
|
||||
@Test
|
||||
void profilesAddedToEnvironmentAndViaPropertyDuplicateEnvironmentWins(CapturedOutput capturedOutput) {
|
||||
void profilesAddedToEnvironmentAndViaPropertyDuplicateEnvironmentWins(CapturedOutput output) {
|
||||
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment, "spring.profiles.active=other,dev");
|
||||
this.environment.addActiveProfile("other");
|
||||
this.initializer.postProcessEnvironment(this.environment, this.application);
|
||||
assertThat(this.environment.getActiveProfiles()).contains("dev", "other");
|
||||
assertThat(this.environment.getProperty("my.property")).isEqualTo("fromdevpropertiesfile");
|
||||
validateProfilePreference(capturedOutput, null, "other", "dev");
|
||||
validateProfilePreference(output, null, "other", "dev");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -475,12 +475,11 @@ class ConfigFileApplicationListenerTests {
|
||||
new ApplicationEnvironmentPreparedEvent(this.application, new String[0], this.environment));
|
||||
}
|
||||
|
||||
private void validateProfilePreference(CapturedOutput capturedOutput, String... profiles) {
|
||||
private void validateProfilePreference(CapturedOutput output, String... profiles) {
|
||||
ApplicationPreparedEvent event = new ApplicationPreparedEvent(new SpringApplication(), new String[0],
|
||||
new AnnotationConfigApplicationContext());
|
||||
withDebugLogging(() -> this.initializer.onApplicationEvent(event));
|
||||
String log = capturedOutput.toString();
|
||||
|
||||
String log = output.toString();
|
||||
// First make sure that each profile got processed only once
|
||||
for (String profile : profiles) {
|
||||
String reason = "Wrong number of occurrences for profile '" + profile + "' --> " + log;
|
||||
@ -787,7 +786,7 @@ class ConfigFileApplicationListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void activateProfileFromProfileSpecificProperties(CapturedOutput capturedOutput) {
|
||||
void activateProfileFromProfileSpecificProperties(CapturedOutput output) {
|
||||
SpringApplication application = new SpringApplication(Config.class);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
this.context = application.run("--spring.profiles.active=includeprofile");
|
||||
@ -797,7 +796,7 @@ class ConfigFileApplicationListenerTests {
|
||||
assertThat(environment).has(matchingProfile("morespecific"));
|
||||
assertThat(environment).has(matchingProfile("yetmorespecific"));
|
||||
assertThat(environment).doesNotHave(matchingProfile("missing"));
|
||||
assertThat(capturedOutput)
|
||||
assertThat(output)
|
||||
.contains("The following profiles are active: includeprofile,specific,morespecific,yetmorespecific");
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ class LoggingApplicationListenerIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void loggingPerformedDuringChildApplicationStartIsNotLost(CapturedOutput capturedOutput) {
|
||||
void loggingPerformedDuringChildApplicationStartIsNotLost(CapturedOutput output) {
|
||||
new SpringApplicationBuilder(Config.class).web(WebApplicationType.NONE).child(Config.class)
|
||||
.web(WebApplicationType.NONE).listeners(new ApplicationListener<ApplicationStartingEvent>() {
|
||||
|
||||
@ -79,7 +79,7 @@ class LoggingApplicationListenerIntegrationTests {
|
||||
}
|
||||
|
||||
}).run();
|
||||
assertThat(capturedOutput).contains("Child application starting");
|
||||
assertThat(output).contains("Child application starting");
|
||||
}
|
||||
|
||||
@Component
|
||||
|
@ -92,7 +92,7 @@ public class LoggingApplicationListenerTests {
|
||||
private static final String[] NO_ARGS = {};
|
||||
|
||||
@Rule
|
||||
public OutputCaptureRule outputCapture = new OutputCaptureRule();
|
||||
public OutputCaptureRule output = new OutputCaptureRule();
|
||||
|
||||
@Rule
|
||||
public final TemporaryFolder temp = new TemporaryFolder();
|
||||
@ -150,9 +150,9 @@ public class LoggingApplicationListenerTests {
|
||||
@Test
|
||||
public void baseConfigLocation() {
|
||||
this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader());
|
||||
this.outputCapture.expect(containsString("Hello world"));
|
||||
this.outputCapture.expect(not(containsString("???")));
|
||||
this.outputCapture.expect(containsString("[junit-"));
|
||||
this.output.expect(containsString("Hello world"));
|
||||
this.output.expect(not(containsString("???")));
|
||||
this.output.expect(containsString("[junit-"));
|
||||
this.logger.info("Hello world", new RuntimeException("Expected"));
|
||||
assertThat(new File(tmpDir() + "/spring.log").exists()).isFalse();
|
||||
}
|
||||
@ -162,7 +162,7 @@ public class LoggingApplicationListenerTests {
|
||||
addPropertiesToEnvironment(this.context, "logging.config=classpath:logback-nondefault.xml");
|
||||
this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader());
|
||||
this.logger.info("Hello world");
|
||||
String output = this.outputCapture.toString().trim();
|
||||
String output = this.output.toString().trim();
|
||||
assertThat(output).contains("Hello world").doesNotContain("???").startsWith("null ").endsWith("BOOTBOOT");
|
||||
}
|
||||
|
||||
@ -170,7 +170,7 @@ public class LoggingApplicationListenerTests {
|
||||
public void overrideConfigDoesNotExist() {
|
||||
addPropertiesToEnvironment(this.context, "logging.config=doesnotexist.xml");
|
||||
assertThatIllegalStateException().isThrownBy(() -> {
|
||||
this.outputCapture.expect(
|
||||
this.output.expect(
|
||||
containsString("Logging system failed to initialize using configuration from 'doesnotexist.xml'"));
|
||||
this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader());
|
||||
});
|
||||
@ -182,7 +182,7 @@ public class LoggingApplicationListenerTests {
|
||||
"logging.config=-Djava.util.logging.config.file=\"d:\\home\\site\\wwwroot\\bin\\apache-tomcat-7.0.52\\conf\\logging.properties\"");
|
||||
this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader());
|
||||
this.logger.info("Hello world");
|
||||
String output = this.outputCapture.toString().trim();
|
||||
String output = this.output.toString().trim();
|
||||
assertThat(output).contains("Hello world").doesNotContain("???");
|
||||
assertThat(new File(tmpDir() + "/spring.log").exists()).isFalse();
|
||||
}
|
||||
@ -192,7 +192,7 @@ public class LoggingApplicationListenerTests {
|
||||
addPropertiesToEnvironment(this.context, "LOGGING_CONFIG=-Dnop");
|
||||
this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader());
|
||||
this.logger.info("Hello world");
|
||||
String output = this.outputCapture.toString().trim();
|
||||
String output = this.output.toString().trim();
|
||||
assertThat(output).contains("Hello world").doesNotContain("???");
|
||||
assertThat(new File(tmpDir() + "/spring.log").exists()).isFalse();
|
||||
}
|
||||
@ -201,9 +201,9 @@ public class LoggingApplicationListenerTests {
|
||||
public void overrideConfigBroken() {
|
||||
addPropertiesToEnvironment(this.context, "logging.config=classpath:logback-broken.xml");
|
||||
assertThatIllegalStateException().isThrownBy(() -> {
|
||||
this.outputCapture.expect(containsString(
|
||||
this.output.expect(containsString(
|
||||
"Logging system failed to initialize using configuration from 'classpath:logback-broken.xml'"));
|
||||
this.outputCapture.expect(containsString("ConsolAppender"));
|
||||
this.output.expect(containsString("ConsolAppender"));
|
||||
this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader());
|
||||
});
|
||||
}
|
||||
@ -214,9 +214,9 @@ public class LoggingApplicationListenerTests {
|
||||
"logging.file.name=" + this.logFile);
|
||||
this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader());
|
||||
Log logger = LogFactory.getLog(LoggingApplicationListenerTests.class);
|
||||
String existingOutput = this.outputCapture.toString();
|
||||
String existingOutput = this.output.toString();
|
||||
logger.info("Hello world");
|
||||
String output = this.outputCapture.toString().substring(existingOutput.length()).trim();
|
||||
String output = this.output.toString().substring(existingOutput.length()).trim();
|
||||
assertThat(output).startsWith(this.logFile.getAbsolutePath());
|
||||
}
|
||||
|
||||
@ -227,9 +227,9 @@ public class LoggingApplicationListenerTests {
|
||||
"logging.file=" + this.logFile);
|
||||
this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader());
|
||||
Log logger = LogFactory.getLog(LoggingApplicationListenerTests.class);
|
||||
String existingOutput = this.outputCapture.toString();
|
||||
String existingOutput = this.output.toString();
|
||||
logger.info("Hello world");
|
||||
String output = this.outputCapture.toString().substring(existingOutput.length()).trim();
|
||||
String output = this.output.toString().substring(existingOutput.length()).trim();
|
||||
assertThat(output).startsWith(this.logFile.getAbsolutePath());
|
||||
}
|
||||
|
||||
@ -260,9 +260,9 @@ public class LoggingApplicationListenerTests {
|
||||
"logging.file.path=" + this.temp.getRoot());
|
||||
this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader());
|
||||
Log logger = LogFactory.getLog(LoggingApplicationListenerTests.class);
|
||||
String existingOutput = this.outputCapture.toString();
|
||||
String existingOutput = this.output.toString();
|
||||
logger.info("Hello world");
|
||||
String output = this.outputCapture.toString().substring(existingOutput.length()).trim();
|
||||
String output = this.output.toString().substring(existingOutput.length()).trim();
|
||||
assertThat(output).startsWith(new File(this.temp.getRoot(), "spring.log").getAbsolutePath());
|
||||
}
|
||||
|
||||
@ -272,9 +272,9 @@ public class LoggingApplicationListenerTests {
|
||||
"logging.path=" + this.temp.getRoot());
|
||||
this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader());
|
||||
Log logger = LogFactory.getLog(LoggingApplicationListenerTests.class);
|
||||
String existingOutput = this.outputCapture.toString();
|
||||
String existingOutput = this.output.toString();
|
||||
logger.info("Hello world");
|
||||
String output = this.outputCapture.toString().substring(existingOutput.length()).trim();
|
||||
String output = this.output.toString().substring(existingOutput.length()).trim();
|
||||
assertThat(output).startsWith(new File(this.temp.getRoot(), "spring.log").getAbsolutePath());
|
||||
}
|
||||
|
||||
@ -284,8 +284,8 @@ public class LoggingApplicationListenerTests {
|
||||
this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader());
|
||||
this.logger.debug("testatdebug");
|
||||
this.logger.trace("testattrace");
|
||||
assertThat(this.outputCapture.toString()).contains("testatdebug");
|
||||
assertThat(this.outputCapture.toString()).doesNotContain("testattrace");
|
||||
assertThat(this.output.toString()).contains("testatdebug");
|
||||
assertThat(this.output.toString()).doesNotContain("testattrace");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -294,8 +294,8 @@ public class LoggingApplicationListenerTests {
|
||||
this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader());
|
||||
this.loggerContext.getLogger("org.springframework.boot.actuate.endpoint.web").debug("testdebugwebgroup");
|
||||
this.loggerContext.getLogger("org.hibernate.SQL").debug("testdebugsqlgroup");
|
||||
assertThat(this.outputCapture.toString()).contains("testdebugwebgroup");
|
||||
assertThat(this.outputCapture.toString()).contains("testdebugsqlgroup");
|
||||
assertThat(this.output.toString()).contains("testdebugwebgroup");
|
||||
assertThat(this.output.toString()).contains("testdebugsqlgroup");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -304,8 +304,8 @@ public class LoggingApplicationListenerTests {
|
||||
this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader());
|
||||
this.logger.debug("testatdebug");
|
||||
this.logger.trace("testattrace");
|
||||
assertThat(this.outputCapture.toString()).contains("testatdebug");
|
||||
assertThat(this.outputCapture.toString()).contains("testattrace");
|
||||
assertThat(this.output.toString()).contains("testatdebug");
|
||||
assertThat(this.output.toString()).contains("testattrace");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -323,8 +323,8 @@ public class LoggingApplicationListenerTests {
|
||||
this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader());
|
||||
this.logger.debug("testatdebug");
|
||||
this.logger.trace("testattrace");
|
||||
assertThat(this.outputCapture.toString()).doesNotContain("testatdebug");
|
||||
assertThat(this.outputCapture.toString()).doesNotContain("testattrace");
|
||||
assertThat(this.output.toString()).doesNotContain("testatdebug");
|
||||
assertThat(this.output.toString()).doesNotContain("testattrace");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -333,8 +333,8 @@ public class LoggingApplicationListenerTests {
|
||||
this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader());
|
||||
this.logger.debug("testatdebug");
|
||||
this.logger.trace("testattrace");
|
||||
assertThat(this.outputCapture.toString()).contains("testatdebug");
|
||||
assertThat(this.outputCapture.toString()).contains("testattrace");
|
||||
assertThat(this.output.toString()).contains("testatdebug");
|
||||
assertThat(this.output.toString()).contains("testattrace");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -343,8 +343,8 @@ public class LoggingApplicationListenerTests {
|
||||
this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader());
|
||||
this.logger.debug("testatdebug");
|
||||
this.logger.trace("testattrace");
|
||||
assertThat(this.outputCapture.toString()).contains("testatdebug");
|
||||
assertThat(this.outputCapture.toString()).contains("testattrace");
|
||||
assertThat(this.output.toString()).contains("testatdebug");
|
||||
assertThat(this.output.toString()).contains("testattrace");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -353,8 +353,8 @@ public class LoggingApplicationListenerTests {
|
||||
this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader());
|
||||
this.logger.debug("testatdebug");
|
||||
this.logger.trace("testattrace");
|
||||
assertThat(this.outputCapture.toString()).contains("testatdebug");
|
||||
assertThat(this.outputCapture.toString()).contains("testattrace");
|
||||
assertThat(this.output.toString()).contains("testatdebug");
|
||||
assertThat(this.output.toString()).contains("testattrace");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -363,8 +363,8 @@ public class LoggingApplicationListenerTests {
|
||||
this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader());
|
||||
this.logger.debug("testatdebug");
|
||||
this.logger.trace("testattrace");
|
||||
assertThat(this.outputCapture.toString()).contains("testatdebug");
|
||||
assertThat(this.outputCapture.toString()).contains("testattrace");
|
||||
assertThat(this.output.toString()).contains("testatdebug");
|
||||
assertThat(this.output.toString()).contains("testattrace");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -381,7 +381,7 @@ public class LoggingApplicationListenerTests {
|
||||
this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader());
|
||||
this.logger.debug("testatdebug");
|
||||
this.logger.error("testaterror");
|
||||
assertThat(this.outputCapture.toString()).doesNotContain("testatdebug").doesNotContain("testaterror");
|
||||
assertThat(this.output.toString()).doesNotContain("testatdebug").doesNotContain("testaterror");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -390,7 +390,7 @@ public class LoggingApplicationListenerTests {
|
||||
this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader());
|
||||
this.logger.debug("testatdebug");
|
||||
this.logger.error("testaterror");
|
||||
assertThat(this.outputCapture.toString()).doesNotContain("testatdebug").doesNotContain("testaterror");
|
||||
assertThat(this.output.toString()).doesNotContain("testatdebug").doesNotContain("testaterror");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -399,7 +399,7 @@ public class LoggingApplicationListenerTests {
|
||||
addPropertiesToEnvironment(this.context, "debug");
|
||||
this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader());
|
||||
this.logger.debug("testatdebug");
|
||||
assertThat(this.outputCapture.toString()).doesNotContain("testatdebug");
|
||||
assertThat(this.output.toString()).doesNotContain("testatdebug");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -409,7 +409,7 @@ public class LoggingApplicationListenerTests {
|
||||
multicastEvent(new ApplicationStartingEvent(this.springApplication, new String[] { "--debug" }));
|
||||
this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader());
|
||||
this.logger.debug("testatdebug");
|
||||
assertThat(this.outputCapture.toString()).doesNotContain("testatdebug");
|
||||
assertThat(this.output.toString()).doesNotContain("testatdebug");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -422,8 +422,8 @@ public class LoggingApplicationListenerTests {
|
||||
@Test
|
||||
public void defaultExceptionConversionWord() {
|
||||
this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader());
|
||||
this.outputCapture.expect(containsString("Hello world"));
|
||||
this.outputCapture.expect(not(containsString("Wrapped by: java.lang.RuntimeException: Wrapper")));
|
||||
this.output.expect(containsString("Hello world"));
|
||||
this.output.expect(not(containsString("Wrapped by: java.lang.RuntimeException: Wrapper")));
|
||||
this.logger.info("Hello world", new RuntimeException("Wrapper", new RuntimeException("Expected")));
|
||||
}
|
||||
|
||||
@ -431,8 +431,8 @@ public class LoggingApplicationListenerTests {
|
||||
public void overrideExceptionConversionWord() {
|
||||
addPropertiesToEnvironment(this.context, "logging.exceptionConversionWord=%rEx");
|
||||
this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader());
|
||||
this.outputCapture.expect(containsString("Hello world"));
|
||||
this.outputCapture.expect(containsString("Wrapped by: java.lang.RuntimeException: Wrapper"));
|
||||
this.output.expect(containsString("Hello world"));
|
||||
this.output.expect(containsString("Wrapped by: java.lang.RuntimeException: Wrapper"));
|
||||
this.logger.info("Hello world", new RuntimeException("Wrapper", new RuntimeException("Expected")));
|
||||
}
|
||||
|
||||
@ -554,7 +554,7 @@ public class LoggingApplicationListenerTests {
|
||||
propertySources.addLast(new MapPropertySource("test2", Collections.singletonMap("logging.level.root", "WARN")));
|
||||
this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader());
|
||||
this.logger.debug("testatdebug");
|
||||
assertThat(this.outputCapture.toString()).contains("testatdebug");
|
||||
assertThat(this.output.toString()).contains("testatdebug");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -504,9 +504,9 @@ class ConfigurationPropertiesTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void loadWhenHasMultiplePropertySourcesPlaceholderConfigurerShouldLogWarning(CapturedOutput capturedOutput) {
|
||||
void loadWhenHasMultiplePropertySourcesPlaceholderConfigurerShouldLogWarning(CapturedOutput output) {
|
||||
load(MultiplePropertySourcesPlaceholderConfigurerConfiguration.class);
|
||||
assertThat(capturedOutput).contains("Multiple PropertySourcesPlaceholderConfigurer beans registered");
|
||||
assertThat(output).contains("Multiple PropertySourcesPlaceholderConfigurer beans registered");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -40,10 +40,10 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
class FailureAnalyzersIntegrationTests {
|
||||
|
||||
@Test
|
||||
void analysisIsPerformed(CapturedOutput capturedOutput) {
|
||||
void analysisIsPerformed(CapturedOutput output) {
|
||||
assertThatExceptionOfType(Exception.class).isThrownBy(
|
||||
() -> new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE).run());
|
||||
assertThat(capturedOutput).contains("APPLICATION FAILED TO START");
|
||||
assertThat(output).contains("APPLICATION FAILED TO START");
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
|
@ -57,11 +57,11 @@ class SpringBootJoranConfiguratorTests {
|
||||
|
||||
private Logger logger;
|
||||
|
||||
private CapturedOutput capturedOutput;
|
||||
private CapturedOutput output;
|
||||
|
||||
@BeforeEach
|
||||
void setup(CapturedOutput capturedOutput) {
|
||||
this.capturedOutput = capturedOutput;
|
||||
void setup(CapturedOutput output) {
|
||||
this.output = output;
|
||||
this.environment = new MockEnvironment();
|
||||
this.initializationContext = new LoggingInitializationContext(this.environment);
|
||||
this.configurator = new SpringBootJoranConfigurator(this.initializationContext);
|
||||
@ -81,7 +81,7 @@ class SpringBootJoranConfiguratorTests {
|
||||
this.environment.setActiveProfiles("production");
|
||||
initialize("production-profile.xml");
|
||||
this.logger.trace("Hello");
|
||||
assertThat(this.capturedOutput).contains("Hello");
|
||||
assertThat(this.output).contains("Hello");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -89,7 +89,7 @@ class SpringBootJoranConfiguratorTests {
|
||||
this.environment.setActiveProfiles("production");
|
||||
initialize("multi-profile-names.xml");
|
||||
this.logger.trace("Hello");
|
||||
assertThat(this.capturedOutput).contains("Hello");
|
||||
assertThat(this.output).contains("Hello");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -97,14 +97,14 @@ class SpringBootJoranConfiguratorTests {
|
||||
this.environment.setActiveProfiles("test");
|
||||
initialize("multi-profile-names.xml");
|
||||
this.logger.trace("Hello");
|
||||
assertThat(this.capturedOutput).contains("Hello");
|
||||
assertThat(this.output).contains("Hello");
|
||||
}
|
||||
|
||||
@Test
|
||||
void profileNotActive() throws Exception {
|
||||
initialize("production-profile.xml");
|
||||
this.logger.trace("Hello");
|
||||
assertThat(this.capturedOutput).doesNotContain("Hello");
|
||||
assertThat(this.output).doesNotContain("Hello");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -112,7 +112,7 @@ class SpringBootJoranConfiguratorTests {
|
||||
this.environment.setActiveProfiles("production");
|
||||
initialize("profile-expression.xml");
|
||||
this.logger.trace("Hello");
|
||||
assertThat(this.capturedOutput).contains("Hello");
|
||||
assertThat(this.output).contains("Hello");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -120,7 +120,7 @@ class SpringBootJoranConfiguratorTests {
|
||||
this.environment.setActiveProfiles("test");
|
||||
initialize("profile-expression.xml");
|
||||
this.logger.trace("Hello");
|
||||
assertThat(this.capturedOutput).contains("Hello");
|
||||
assertThat(this.output).contains("Hello");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -128,7 +128,7 @@ class SpringBootJoranConfiguratorTests {
|
||||
this.environment.setActiveProfiles("development");
|
||||
initialize("profile-expression.xml");
|
||||
this.logger.trace("Hello");
|
||||
assertThat(this.capturedOutput).doesNotContain("Hello");
|
||||
assertThat(this.output).doesNotContain("Hello");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -195,10 +195,10 @@ class SpringBootJoranConfiguratorTests {
|
||||
initialize("nested.xml");
|
||||
this.logger.trace("Hello");
|
||||
if (expected) {
|
||||
assertThat(this.capturedOutput).contains("Hello");
|
||||
assertThat(this.output).contains("Hello");
|
||||
}
|
||||
else {
|
||||
assertThat(this.capturedOutput).doesNotContain("Hello");
|
||||
assertThat(this.output).doesNotContain("Hello");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -160,8 +160,7 @@ class SslConnectorCustomizerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void customizeWhenSslStoreProviderPresentShouldIgnorePasswordFromSsl(CapturedOutput capturedOutput)
|
||||
throws Exception {
|
||||
void customizeWhenSslStoreProviderPresentShouldIgnorePasswordFromSsl(CapturedOutput output) throws Exception {
|
||||
System.setProperty("javax.net.ssl.trustStorePassword", "trustStoreSecret");
|
||||
Ssl ssl = new Ssl();
|
||||
ssl.setKeyPassword("password");
|
||||
@ -174,7 +173,7 @@ class SslConnectorCustomizerTests {
|
||||
customizer.customize(connector);
|
||||
this.tomcat.start();
|
||||
assertThat(connector.getState()).isEqualTo(LifecycleState.STARTED);
|
||||
assertThat(capturedOutput).doesNotContain("Password verification failed");
|
||||
assertThat(output).doesNotContain("Password verification failed");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -328,9 +328,9 @@ class TomcatServletWebServerFactoryTests extends AbstractServletWebServerFactory
|
||||
}
|
||||
|
||||
@Test
|
||||
void startupFailureDoesNotResultInUnstoppedThreadsBeingReported(CapturedOutput capturedOutput) throws IOException {
|
||||
void startupFailureDoesNotResultInUnstoppedThreadsBeingReported(CapturedOutput output) throws IOException {
|
||||
super.portClashOfPrimaryConnectorResultsInPortInUseException();
|
||||
assertThat(capturedOutput).doesNotContain("appears to have started a thread named [main]");
|
||||
assertThat(output).doesNotContain("appears to have started a thread named [main]");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -419,9 +419,9 @@ class ServletWebServerApplicationContextTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void servletRequestCanBeInjectedEarly(CapturedOutput capturedOutput) throws Exception {
|
||||
void servletRequestCanBeInjectedEarly(CapturedOutput output) throws Exception {
|
||||
// gh-14990
|
||||
int initialOutputLength = capturedOutput.length();
|
||||
int initialOutputLength = output.length();
|
||||
addWebServerFactoryBean();
|
||||
RootBeanDefinition beanDefinition = new RootBeanDefinition(WithAutowiredServletRequest.class);
|
||||
beanDefinition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_CONSTRUCTOR);
|
||||
@ -431,8 +431,7 @@ class ServletWebServerApplicationContextTests {
|
||||
assertThat(bean.getRequest()).isNotNull();
|
||||
});
|
||||
this.context.refresh();
|
||||
String output = capturedOutput.toString().substring(initialOutputLength);
|
||||
assertThat(output).doesNotContain("Replacing scope");
|
||||
assertThat(output.toString().substring(initialOutputLength)).doesNotContain("Replacing scope");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -167,7 +167,7 @@ public abstract class AbstractServletWebServerFactoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void startCalledTwice(CapturedOutput capturedOutput) throws Exception {
|
||||
void startCalledTwice(CapturedOutput output) throws Exception {
|
||||
AbstractServletWebServerFactory factory = getFactory();
|
||||
this.webServer = factory.getWebServer(exampleServletRegistration());
|
||||
this.webServer.start();
|
||||
@ -175,7 +175,7 @@ public abstract class AbstractServletWebServerFactoryTests {
|
||||
this.webServer.start();
|
||||
assertThat(this.webServer.getPort()).isEqualTo(port);
|
||||
assertThat(getResponse(getLocalUrl("/hello"))).isEqualTo("Hello World");
|
||||
assertThat(capturedOutput).containsOnlyOnce("started on port");
|
||||
assertThat(output).containsOnlyOnce("started on port");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -264,12 +264,12 @@ public abstract class AbstractServletWebServerFactoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void contextPathIsLoggedOnStartup(CapturedOutput capturedOutput) {
|
||||
void contextPathIsLoggedOnStartup(CapturedOutput output) {
|
||||
AbstractServletWebServerFactory factory = getFactory();
|
||||
factory.setContextPath("/custom");
|
||||
this.webServer = factory.getWebServer(exampleServletRegistration());
|
||||
this.webServer.start();
|
||||
assertThat(capturedOutput).containsOnlyOnce("with context path '/custom'");
|
||||
assertThat(output).containsOnlyOnce("with context path '/custom'");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -125,7 +125,7 @@ class ErrorPageFilterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void responseCommittedWhenFromClientAbortException(CapturedOutput capturedOutput) throws Exception {
|
||||
void responseCommittedWhenFromClientAbortException(CapturedOutput output) throws Exception {
|
||||
this.filter.addErrorPages(new ErrorPage("/error"));
|
||||
this.response.setCommitted(true);
|
||||
this.chain = new TestFilterChain((request, response, chain) -> {
|
||||
@ -134,7 +134,7 @@ class ErrorPageFilterTests {
|
||||
});
|
||||
this.filter.doFilter(this.request, this.response, this.chain);
|
||||
assertThat(this.response.isCommitted()).isTrue();
|
||||
assertThat(capturedOutput).doesNotContain("Cannot forward");
|
||||
assertThat(output).doesNotContain("Cannot forward");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -342,7 +342,7 @@ class ErrorPageFilterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void errorMessageForRequestWithoutPathInfo(CapturedOutput capturedOutput) throws IOException, ServletException {
|
||||
void errorMessageForRequestWithoutPathInfo(CapturedOutput output) throws IOException, ServletException {
|
||||
this.request.setServletPath("/test");
|
||||
this.filter.addErrorPages(new ErrorPage("/error"));
|
||||
this.chain = new TestFilterChain((request, response, chain) -> {
|
||||
@ -350,11 +350,11 @@ class ErrorPageFilterTests {
|
||||
throw new RuntimeException();
|
||||
});
|
||||
this.filter.doFilter(this.request, this.response, this.chain);
|
||||
assertThat(capturedOutput).contains("request [/test]");
|
||||
assertThat(output).contains("request [/test]");
|
||||
}
|
||||
|
||||
@Test
|
||||
void errorMessageForRequestWithPathInfo(CapturedOutput capturedOutput) throws IOException, ServletException {
|
||||
void errorMessageForRequestWithPathInfo(CapturedOutput output) throws IOException, ServletException {
|
||||
this.request.setServletPath("/test");
|
||||
this.request.setPathInfo("/alpha");
|
||||
this.filter.addErrorPages(new ErrorPage("/error"));
|
||||
@ -363,7 +363,7 @@ class ErrorPageFilterTests {
|
||||
throw new RuntimeException();
|
||||
});
|
||||
this.filter.doFilter(this.request, this.response, this.chain);
|
||||
assertThat(capturedOutput).contains("request [/test/alpha]");
|
||||
assertThat(output).contains("request [/test/alpha]");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -61,8 +61,8 @@ class SpringBootServletInitializerTests {
|
||||
private SpringApplication application;
|
||||
|
||||
@AfterEach
|
||||
void verifyLoggingOutput(CapturedOutput capturedOutput) {
|
||||
assertThat(capturedOutput).doesNotContain(StandardServletEnvironment.class.getSimpleName());
|
||||
void verifyLoggingOutput(CapturedOutput output) {
|
||||
assertThat(output).doesNotContain(StandardServletEnvironment.class.getSimpleName());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -39,10 +39,10 @@ class SampleActiveMqTests {
|
||||
private Producer producer;
|
||||
|
||||
@Test
|
||||
void sendSimpleMessage(CapturedOutput capturedOutput) throws InterruptedException {
|
||||
void sendSimpleMessage(CapturedOutput output) throws InterruptedException {
|
||||
this.producer.send("Test message");
|
||||
Thread.sleep(1000L);
|
||||
assertThat(capturedOutput).contains("Test message");
|
||||
assertThat(output).contains("Test message");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -52,9 +52,9 @@ class SampleActuatorLog4J2ApplicationTests {
|
||||
private MockMvc mvc;
|
||||
|
||||
@Test
|
||||
void testLogger(CapturedOutput capturedOutput) {
|
||||
void testLogger(CapturedOutput output) {
|
||||
logger.info("Hello World");
|
||||
assertThat(capturedOutput).contains("Hello World");
|
||||
assertThat(output).contains("Hello World");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -53,15 +53,15 @@ class SampleAopApplicationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDefaultSettings(CapturedOutput capturedOutput) throws Exception {
|
||||
void testDefaultSettings(CapturedOutput output) throws Exception {
|
||||
SampleAopApplication.main(new String[0]);
|
||||
assertThat(capturedOutput).contains("Hello Phil");
|
||||
assertThat(output).contains("Hello Phil");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCommandLineOverrides(CapturedOutput capturedOutput) throws Exception {
|
||||
void testCommandLineOverrides(CapturedOutput output) throws Exception {
|
||||
SampleAopApplication.main(new String[] { "--name=Gordon" });
|
||||
assertThat(capturedOutput).contains("Hello Gordon");
|
||||
assertThat(output).contains("Hello Gordon");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -29,9 +29,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
class SampleBatchApplicationTests {
|
||||
|
||||
@Test
|
||||
void testDefaultSettings(CapturedOutput capturedOutput) {
|
||||
void testDefaultSettings(CapturedOutput output) {
|
||||
assertThat(SpringApplication.exit(SpringApplication.run(SampleBatchApplication.class))).isEqualTo(0);
|
||||
assertThat(capturedOutput).contains("completed with the following parameters");
|
||||
assertThat(output).contains("completed with the following parameters");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
class SampleCouchbaseApplicationTests {
|
||||
|
||||
@Test
|
||||
void testDefaultSettings(CapturedOutput capturedOutput) {
|
||||
void testDefaultSettings(CapturedOutput output) {
|
||||
try {
|
||||
new SpringApplicationBuilder(SampleCouchbaseApplication.class).run("--server.port=0");
|
||||
}
|
||||
@ -40,7 +40,7 @@ class SampleCouchbaseApplicationTests {
|
||||
return;
|
||||
}
|
||||
}
|
||||
assertThat(capturedOutput).contains("firstName='Alice', lastName='Smith'");
|
||||
assertThat(output).contains("firstName='Alice', lastName='Smith'");
|
||||
}
|
||||
|
||||
private boolean serverNotRunning(RuntimeException ex) {
|
||||
|
@ -36,7 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
class SampleElasticsearchApplicationTests {
|
||||
|
||||
@Test
|
||||
void testDefaultSettings(CapturedOutput capturedOutput) {
|
||||
void testDefaultSettings(CapturedOutput output) {
|
||||
try {
|
||||
new SpringApplicationBuilder(SampleElasticsearchApplication.class).run();
|
||||
}
|
||||
@ -46,7 +46,7 @@ class SampleElasticsearchApplicationTests {
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
assertThat(capturedOutput).contains("firstName='Alice', lastName='Smith'");
|
||||
assertThat(output).contains("firstName='Alice', lastName='Smith'");
|
||||
}
|
||||
|
||||
private boolean elasticsearchRunning(Exception ex) {
|
||||
|
@ -34,7 +34,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
class SampleNeo4jApplicationTests {
|
||||
|
||||
@Test
|
||||
void testDefaultSettings(CapturedOutput capturedOutput) {
|
||||
void testDefaultSettings(CapturedOutput output) {
|
||||
try {
|
||||
SampleNeo4jApplication.main(new String[0]);
|
||||
}
|
||||
@ -43,7 +43,7 @@ class SampleNeo4jApplicationTests {
|
||||
return;
|
||||
}
|
||||
}
|
||||
assertThat(capturedOutput).contains("firstName='Alice', lastName='Smith'");
|
||||
assertThat(output).contains("firstName='Alice', lastName='Smith'");
|
||||
}
|
||||
|
||||
private boolean neo4jServerRunning(Throwable ex) {
|
||||
|
@ -34,7 +34,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
class SampleRedisApplicationTests {
|
||||
|
||||
@Test
|
||||
void testDefaultSettings(CapturedOutput capturedOutput) {
|
||||
void testDefaultSettings(CapturedOutput output) {
|
||||
try {
|
||||
SampleRedisApplication.main(new String[0]);
|
||||
}
|
||||
@ -43,7 +43,7 @@ class SampleRedisApplicationTests {
|
||||
return;
|
||||
}
|
||||
}
|
||||
assertThat(capturedOutput).contains("Found key spring.boot.redis.test");
|
||||
assertThat(output).contains("Found key spring.boot.redis.test");
|
||||
}
|
||||
|
||||
private boolean redisServerRunning(Throwable ex) {
|
||||
|
@ -29,7 +29,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
class SampleSolrApplicationTests {
|
||||
|
||||
@Test
|
||||
void testDefaultSettings(CapturedOutput capturedOutput) throws Exception {
|
||||
void testDefaultSettings(CapturedOutput output) throws Exception {
|
||||
try {
|
||||
SampleSolrApplication.main(new String[0]);
|
||||
}
|
||||
@ -38,7 +38,7 @@ class SampleSolrApplicationTests {
|
||||
return;
|
||||
}
|
||||
}
|
||||
assertThat(capturedOutput).contains("name=Sony Playstation");
|
||||
assertThat(output).contains("name=Sony Playstation");
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
|
@ -33,9 +33,9 @@ class SampleJooqApplicationTests {
|
||||
private static final String[] NO_ARGS = {};
|
||||
|
||||
@Test
|
||||
void outputResults(CapturedOutput capturedOutput) {
|
||||
void outputResults(CapturedOutput output) {
|
||||
SampleJooqApplication.main(NO_ARGS);
|
||||
assertThat(capturedOutput).contains("jOOQ Fetch 1 Greg Turnquest").contains("jOOQ Fetch 2 Craig Walls")
|
||||
assertThat(output).contains("jOOQ Fetch 1 Greg Turnquest").contains("jOOQ Fetch 2 Craig Walls")
|
||||
.contains("jOOQ SQL " + "[Learning Spring Boot : Greg Turnquest, "
|
||||
+ "Spring Boot in Action : Craig Walls]");
|
||||
}
|
||||
|
@ -34,9 +34,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
class SampleAtomikosApplicationTests {
|
||||
|
||||
@Test
|
||||
void testTransactionRollback(CapturedOutput capturedOutput) throws Exception {
|
||||
void testTransactionRollback(CapturedOutput output) throws Exception {
|
||||
SampleAtomikosApplication.main(new String[] {});
|
||||
assertThat(capturedOutput.toString()).has(substring(1, "---->")).has(substring(1, "----> josh"))
|
||||
assertThat(output.toString()).has(substring(1, "---->")).has(substring(1, "----> josh"))
|
||||
.has(substring(2, "Count is 1")).has(substring(1, "Simulated error"));
|
||||
}
|
||||
|
||||
|
@ -37,9 +37,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
class SampleBitronixApplicationTests {
|
||||
|
||||
@Test
|
||||
void testTransactionRollback(CapturedOutput capturedOutput) throws Exception {
|
||||
void testTransactionRollback(CapturedOutput output) throws Exception {
|
||||
SampleBitronixApplication.main(new String[] {});
|
||||
assertThat(capturedOutput.toString()).has(substring(1, "---->")).has(substring(1, "----> josh"))
|
||||
assertThat(output.toString()).has(substring(1, "---->")).has(substring(1, "----> josh"))
|
||||
.has(substring(2, "Count is 1")).has(substring(1, "Simulated error"));
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
class SampleLiquibaseApplicationTests {
|
||||
|
||||
@Test
|
||||
void testDefaultSettings(CapturedOutput capturedOutput) throws Exception {
|
||||
void testDefaultSettings(CapturedOutput output) throws Exception {
|
||||
try {
|
||||
SampleLiquibaseApplication.main(new String[] { "--server.port=0" });
|
||||
}
|
||||
@ -40,7 +40,7 @@ class SampleLiquibaseApplicationTests {
|
||||
return;
|
||||
}
|
||||
}
|
||||
assertThat(capturedOutput).contains("Successfully acquired change log lock")
|
||||
assertThat(output).contains("Successfully acquired change log lock")
|
||||
.contains("Creating database history " + "table with name: PUBLIC.DATABASECHANGELOG")
|
||||
.contains("Table person created")
|
||||
.contains("ChangeSet classpath:/db/" + "changelog/db.changelog-master.yaml::1::"
|
||||
|
@ -28,15 +28,15 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
class SampleLogbackApplicationTests {
|
||||
|
||||
@Test
|
||||
void testLoadedCustomLogbackConfig(CapturedOutput capturedOutput) throws Exception {
|
||||
void testLoadedCustomLogbackConfig(CapturedOutput output) throws Exception {
|
||||
SampleLogbackApplication.main(new String[0]);
|
||||
assertThat(capturedOutput).contains("Sample Debug Message").doesNotContain("Sample Trace Message");
|
||||
assertThat(output).contains("Sample Debug Message").doesNotContain("Sample Trace Message");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testProfile(CapturedOutput capturedOutput) throws Exception {
|
||||
void testProfile(CapturedOutput output) throws Exception {
|
||||
SampleLogbackApplication.main(new String[] { "--spring.profiles.active=staging" });
|
||||
assertThat(capturedOutput).contains("Sample Debug Message").contains("Sample Trace Message");
|
||||
assertThat(output).contains("Sample Debug Message").contains("Sample Trace Message");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -47,20 +47,20 @@ class SampleProfileApplicationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDefaultProfile(CapturedOutput capturedOutput) {
|
||||
void testDefaultProfile(CapturedOutput output) {
|
||||
SampleProfileApplication.main(new String[0]);
|
||||
assertThat(capturedOutput).contains("Hello Phil");
|
||||
assertThat(output).contains("Hello Phil");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGoodbyeProfile(CapturedOutput capturedOutput) {
|
||||
void testGoodbyeProfile(CapturedOutput output) {
|
||||
System.setProperty("spring.profiles.active", "goodbye");
|
||||
SampleProfileApplication.main(new String[0]);
|
||||
assertThat(capturedOutput).contains("Goodbye Everyone");
|
||||
assertThat(output).contains("Goodbye Everyone");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericProfile(CapturedOutput capturedOutput) {
|
||||
void testGenericProfile(CapturedOutput output) {
|
||||
/*
|
||||
* This is a profile that requires a new environment property, and one which is
|
||||
* only overridden in the current working directory. That file also only contains
|
||||
@ -69,13 +69,13 @@ class SampleProfileApplicationTests {
|
||||
*/
|
||||
System.setProperty("spring.profiles.active", "generic");
|
||||
SampleProfileApplication.main(new String[0]);
|
||||
assertThat(capturedOutput).contains("Bonjour Phil");
|
||||
assertThat(output).contains("Bonjour Phil");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGoodbyeProfileFromCommandline(CapturedOutput capturedOutput) {
|
||||
void testGoodbyeProfileFromCommandline(CapturedOutput output) {
|
||||
SampleProfileApplication.main(new String[] { "--spring.profiles.active=goodbye" });
|
||||
assertThat(capturedOutput).contains("Goodbye Everyone");
|
||||
assertThat(output).contains("Goodbye Everyone");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -35,13 +35,13 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
class SampleQuartzApplicationTests {
|
||||
|
||||
@Test
|
||||
void quartzJobIsTriggered(CapturedOutput capturedOutput) throws InterruptedException {
|
||||
void quartzJobIsTriggered(CapturedOutput output) throws InterruptedException {
|
||||
try (ConfigurableApplicationContext context = SpringApplication.run(SampleQuartzApplication.class)) {
|
||||
long end = System.currentTimeMillis() + 5000;
|
||||
while ((!capturedOutput.toString().contains("Hello World!")) && System.currentTimeMillis() < end) {
|
||||
while ((!output.toString().contains("Hello World!")) && System.currentTimeMillis() < end) {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
assertThat(capturedOutput).contains("Hello World!");
|
||||
assertThat(output).contains("Hello World!");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -53,15 +53,15 @@ class SampleSimpleApplicationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDefaultSettings(CapturedOutput capturedOutput) {
|
||||
void testDefaultSettings(CapturedOutput output) {
|
||||
SampleSimpleApplication.main(new String[0]);
|
||||
assertThat(capturedOutput).contains("Hello Phil");
|
||||
assertThat(output).contains("Hello Phil");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCommandLineOverrides(CapturedOutput capturedOutput) {
|
||||
void testCommandLineOverrides(CapturedOutput output) {
|
||||
SampleSimpleApplication.main(new String[] { "--name=Gordon", "--duration=1m" });
|
||||
assertThat(capturedOutput).contains("Hello Gordon for 60 seconds");
|
||||
assertThat(output).contains("Hello Gordon for 60 seconds");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ class SampleWsApplicationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSendingHolidayRequest(CapturedOutput capturedOutput) {
|
||||
void testSendingHolidayRequest(CapturedOutput output) {
|
||||
final String request = "<hr:HolidayRequest xmlns:hr=\"https://company.example.com/hr/schemas\">"
|
||||
+ " <hr:Holiday>" + " <hr:StartDate>2013-10-20</hr:StartDate>"
|
||||
+ " <hr:EndDate>2013-11-22</hr:EndDate>" + " </hr:Holiday>" + " <hr:Employee>"
|
||||
@ -58,7 +58,7 @@ class SampleWsApplicationTests {
|
||||
StreamSource source = new StreamSource(new StringReader(request));
|
||||
StreamResult result = new StreamResult(System.out);
|
||||
this.webServiceTemplate.sendSourceAndReceiveToResult(source, result);
|
||||
assertThat(capturedOutput).contains("Booking holiday for");
|
||||
assertThat(output).contains("Booking holiday for");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,9 +28,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
class SampleSpringXmlApplicationTests {
|
||||
|
||||
@Test
|
||||
void testDefaultSettings(CapturedOutput capturedOutput) throws Exception {
|
||||
void testDefaultSettings(CapturedOutput output) throws Exception {
|
||||
SampleSpringXmlApplication.main(new String[0]);
|
||||
assertThat(capturedOutput).contains("Hello World");
|
||||
assertThat(output).contains("Hello World");
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user