Repackage output capture and always use extension declaratively
Closes gh-17029
This commit is contained in:
@@ -79,6 +79,7 @@ public class MongoProperties {
|
||||
/**
|
||||
* Login user of the mongo server. Cannot be set with URI.
|
||||
*/
|
||||
|
||||
private String username;
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,12 +20,12 @@ import java.io.File;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.boot.test.extension.CapturedOutput;
|
||||
import org.springframework.boot.test.extension.OutputExtension;
|
||||
import org.springframework.boot.test.system.CapturedOutput;
|
||||
import org.springframework.boot.test.system.OutputCaptureExtension;
|
||||
import org.springframework.boot.testsupport.BuildOutput;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -36,11 +36,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Andy Wilkinson
|
||||
* @author Kazuki Shimizu
|
||||
*/
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
public class FreeMarkerAutoConfigurationTests {
|
||||
|
||||
@RegisterExtension
|
||||
CapturedOutput output = OutputExtension.capture();
|
||||
|
||||
private final BuildOutput buildOutput = new BuildOutput(getClass());
|
||||
|
||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
@@ -62,33 +60,33 @@ public class FreeMarkerAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonExistentTemplateLocation() {
|
||||
public void nonExistentTemplateLocation(CapturedOutput capturedOutput) {
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.freemarker.templateLoaderPath:"
|
||||
+ "classpath:/does-not-exist/,classpath:/also-does-not-exist")
|
||||
.run((context) -> assertThat(this.output)
|
||||
.run((context) -> assertThat(capturedOutput)
|
||||
.contains("Cannot find template location"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyTemplateLocation() {
|
||||
public void emptyTemplateLocation(CapturedOutput capturedOutput) {
|
||||
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(this.output.toString())
|
||||
.run((context) -> assertThat(capturedOutput)
|
||||
.doesNotContain("Cannot find template location"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonExistentLocationAndEmptyLocation() {
|
||||
public void nonExistentLocationAndEmptyLocation(CapturedOutput capturedOutput) {
|
||||
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(this.output.toString())
|
||||
.run((context) -> assertThat(capturedOutput)
|
||||
.doesNotContain("Cannot find template location"));
|
||||
}
|
||||
|
||||
|
||||
@@ -21,14 +21,11 @@ import java.util.concurrent.TimeUnit;
|
||||
import okhttp3.OkHttpClient;
|
||||
import org.influxdb.InfluxDB;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.boot.test.extension.CapturedOutput;
|
||||
import org.springframework.boot.test.extension.OutputExtension;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
@@ -44,9 +41,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
public class InfluxDbAutoConfigurationTests {
|
||||
|
||||
@RegisterExtension
|
||||
CapturedOutput output = OutputExtension.capture();
|
||||
|
||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(InfluxDbAutoConfiguration.class));
|
||||
|
||||
|
||||
@@ -36,8 +36,8 @@ import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationServ
|
||||
import org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||
import org.springframework.boot.test.extension.CapturedOutput;
|
||||
import org.springframework.boot.test.extension.OutputExtension;
|
||||
import org.springframework.boot.test.system.CapturedOutput;
|
||||
import org.springframework.boot.test.system.OutputCaptureExtension;
|
||||
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -54,7 +54,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
@SpringBootTest(classes = Application.class, webEnvironment = WebEnvironment.RANDOM_PORT)
|
||||
@DirtiesContext
|
||||
@ExtendWith(OutputExtension.class)
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
public class JerseyAutoConfigurationServletContainerTests {
|
||||
|
||||
@Test
|
||||
|
||||
@@ -43,8 +43,8 @@ import org.springframework.boot.liquibase.LiquibaseServiceLocatorApplicationList
|
||||
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.boot.test.context.runner.ContextConsumer;
|
||||
import org.springframework.boot.test.extension.CapturedOutput;
|
||||
import org.springframework.boot.test.extension.OutputExtension;
|
||||
import org.springframework.boot.test.system.CapturedOutput;
|
||||
import org.springframework.boot.test.system.OutputCaptureExtension;
|
||||
import org.springframework.boot.testsupport.Assume;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -64,7 +64,7 @@ import static org.assertj.core.api.Assertions.contentOf;
|
||||
* @author Stephane Nicoll
|
||||
* @author Dominic Gunn
|
||||
*/
|
||||
@ExtendWith(OutputExtension.class)
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
public class LiquibaseAutoConfigurationTests {
|
||||
|
||||
@BeforeEach
|
||||
|
||||
@@ -22,7 +22,7 @@ import ch.qos.logback.classic.Level;
|
||||
import ch.qos.logback.classic.Logger;
|
||||
import ch.qos.logback.classic.LoggerContext;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.slf4j.impl.StaticLoggerBinder;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
@@ -32,8 +32,8 @@ import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConf
|
||||
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
|
||||
import org.springframework.boot.context.event.ApplicationFailedEvent;
|
||||
import org.springframework.boot.logging.LogLevel;
|
||||
import org.springframework.boot.test.extension.CapturedOutput;
|
||||
import org.springframework.boot.test.extension.OutputExtension;
|
||||
import org.springframework.boot.test.system.CapturedOutput;
|
||||
import org.springframework.boot.test.system.OutputCaptureExtension;
|
||||
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -53,26 +53,24 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
||||
* @author Andy Wilkinson
|
||||
* @author Madhura Bhave
|
||||
*/
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
public class ConditionEvaluationReportLoggingListenerTests {
|
||||
|
||||
@RegisterExtension
|
||||
CapturedOutput output = OutputExtension.capture();
|
||||
|
||||
private ConditionEvaluationReportLoggingListener initializer = new ConditionEvaluationReportLoggingListener();
|
||||
|
||||
@Test
|
||||
public void logsDebugOnContextRefresh() {
|
||||
public void logsDebugOnContextRefresh(CapturedOutput capturedOutput) {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
this.initializer.initialize(context);
|
||||
context.register(Config.class);
|
||||
context.refresh();
|
||||
withDebugLogging(() -> this.initializer
|
||||
.onApplicationEvent(new ContextRefreshedEvent(context)));
|
||||
assertThat(this.output).contains("CONDITIONS EVALUATION REPORT");
|
||||
assertThat(capturedOutput).contains("CONDITIONS EVALUATION REPORT");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void logsDebugOnError() {
|
||||
public void logsDebugOnError(CapturedOutput capturedOutput) {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
this.initializer.initialize(context);
|
||||
context.register(ErrorConfig.class);
|
||||
@@ -80,11 +78,11 @@ public class ConditionEvaluationReportLoggingListenerTests {
|
||||
(ex) -> withDebugLogging(() -> this.initializer.onApplicationEvent(
|
||||
new ApplicationFailedEvent(new SpringApplication(), new String[0],
|
||||
context, ex))));
|
||||
assertThat(this.output).contains("CONDITIONS EVALUATION REPORT");
|
||||
assertThat(capturedOutput).contains("CONDITIONS EVALUATION REPORT");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void logsInfoOnErrorIfDebugDisabled() {
|
||||
public void logsInfoOnErrorIfDebugDisabled(CapturedOutput capturedOutput) {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
this.initializer.initialize(context);
|
||||
context.register(ErrorConfig.class);
|
||||
@@ -92,13 +90,13 @@ public class ConditionEvaluationReportLoggingListenerTests {
|
||||
.satisfies((ex) -> this.initializer.onApplicationEvent(
|
||||
new ApplicationFailedEvent(new SpringApplication(), new String[0],
|
||||
context, ex)));
|
||||
assertThat(this.output).contains("Error starting"
|
||||
assertThat(capturedOutput).contains("Error starting"
|
||||
+ " ApplicationContext. To display the conditions report re-run"
|
||||
+ " your application with 'debug' enabled.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void logsOutput() {
|
||||
public void logsOutput(CapturedOutput capturedOutput) {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
this.initializer.initialize(context);
|
||||
context.register(Config.class);
|
||||
@@ -107,7 +105,7 @@ public class ConditionEvaluationReportLoggingListenerTests {
|
||||
context.refresh();
|
||||
withDebugLogging(() -> this.initializer
|
||||
.onApplicationEvent(new ContextRefreshedEvent(context)));
|
||||
assertThat(this.output)
|
||||
assertThat(capturedOutput)
|
||||
.contains("not a servlet web application (OnWebApplicationCondition)");
|
||||
}
|
||||
|
||||
@@ -131,7 +129,7 @@ public class ConditionEvaluationReportLoggingListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listenerWithInfoLevelShouldLogAtInfo() {
|
||||
public void listenerWithInfoLevelShouldLogAtInfo(CapturedOutput capturedOutput) {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
ConditionEvaluationReportLoggingListener initializer = new ConditionEvaluationReportLoggingListener(
|
||||
LogLevel.INFO);
|
||||
@@ -139,7 +137,7 @@ public class ConditionEvaluationReportLoggingListenerTests {
|
||||
context.register(Config.class);
|
||||
context.refresh();
|
||||
initializer.onApplicationEvent(new ContextRefreshedEvent(context));
|
||||
assertThat(this.output).contains("CONDITIONS EVALUATION REPORT");
|
||||
assertThat(capturedOutput).contains("CONDITIONS EVALUATION REPORT");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -150,11 +148,11 @@ public class ConditionEvaluationReportLoggingListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noErrorIfNotInitialized() {
|
||||
public void noErrorIfNotInitialized(CapturedOutput capturedOutput) {
|
||||
this.initializer
|
||||
.onApplicationEvent(new ApplicationFailedEvent(new SpringApplication(),
|
||||
new String[0], null, new RuntimeException("Planned")));
|
||||
assertThat(this.output).contains("Unable to provide the conditions report");
|
||||
assertThat(capturedOutput).contains("Unable to provide the conditions report");
|
||||
}
|
||||
|
||||
private void withDebugLogging(Runnable runnable) {
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.util.concurrent.Executor;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.quartz.Calendar;
|
||||
import org.quartz.JobBuilder;
|
||||
import org.quartz.JobDetail;
|
||||
@@ -45,8 +45,8 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerA
|
||||
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.boot.test.context.runner.ContextConsumer;
|
||||
import org.springframework.boot.test.extension.CapturedOutput;
|
||||
import org.springframework.boot.test.extension.OutputExtension;
|
||||
import org.springframework.boot.test.system.CapturedOutput;
|
||||
import org.springframework.boot.test.system.OutputCaptureExtension;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
@@ -68,11 +68,9 @@ import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
* @author Vedran Pavic
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
public class QuartzAutoConfigurationTests {
|
||||
|
||||
@RegisterExtension
|
||||
CapturedOutput output = OutputExtension.capture();
|
||||
|
||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withPropertyValues("spring.datasource.generate-unique-name=true")
|
||||
.withConfiguration(AutoConfigurations.of(QuartzAutoConfiguration.class));
|
||||
@@ -176,7 +174,7 @@ public class QuartzAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withConfiguredJobAndTrigger() {
|
||||
public void withConfiguredJobAndTrigger(CapturedOutput capturedOutput) {
|
||||
this.contextRunner.withUserConfiguration(QuartzFullConfiguration.class)
|
||||
.withPropertyValues("test-name=withConfiguredJobAndTrigger")
|
||||
.run((context) -> {
|
||||
@@ -187,8 +185,8 @@ public class QuartzAutoConfigurationTests {
|
||||
assertThat(scheduler.getTrigger(TriggerKey.triggerKey("fooTrigger")))
|
||||
.isNotNull();
|
||||
Thread.sleep(1000L);
|
||||
assertThat(this.output).contains("withConfiguredJobAndTrigger");
|
||||
assertThat(this.output).contains("jobDataValue");
|
||||
assertThat(capturedOutput).contains("withConfiguredJobAndTrigger")
|
||||
.contains("jobDataValue");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ import java.util.EnumSet;
|
||||
import javax.servlet.DispatcherType;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage;
|
||||
@@ -30,8 +29,6 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.orm.jpa.test.City;
|
||||
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
|
||||
import org.springframework.boot.test.extension.CapturedOutput;
|
||||
import org.springframework.boot.test.extension.OutputExtension;
|
||||
import org.springframework.boot.web.servlet.DelegatingFilterProxyRegistrationBean;
|
||||
import org.springframework.boot.web.servlet.filter.OrderedFilter;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
@@ -65,9 +62,6 @@ public class SecurityAutoConfigurationTests {
|
||||
.withConfiguration(AutoConfigurations.of(SecurityAutoConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class));
|
||||
|
||||
@RegisterExtension
|
||||
CapturedOutput output = OutputExtension.capture();
|
||||
|
||||
@Test
|
||||
public void testWebConfiguration() {
|
||||
this.contextRunner.run((context) -> {
|
||||
|
||||
@@ -21,7 +21,7 @@ import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
@@ -30,8 +30,8 @@ import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConf
|
||||
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
|
||||
import org.springframework.boot.test.extension.CapturedOutput;
|
||||
import org.springframework.boot.test.extension.OutputExtension;
|
||||
import org.springframework.boot.test.system.CapturedOutput;
|
||||
import org.springframework.boot.test.system.OutputCaptureExtension;
|
||||
import org.springframework.boot.test.util.TestPropertyValues;
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
|
||||
@@ -51,19 +51,18 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
public class SecurityFilterAutoConfigurationEarlyInitializationTests {
|
||||
|
||||
@RegisterExtension
|
||||
CapturedOutput output = OutputExtension.capture();
|
||||
|
||||
@Test
|
||||
public void testSecurityFilterDoesNotCauseEarlyInitialization() {
|
||||
public void testSecurityFilterDoesNotCauseEarlyInitialization(
|
||||
CapturedOutput capturedOutput) {
|
||||
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 = this.output.toString()
|
||||
String password = capturedOutput.toString()
|
||||
.split("Using generated security password: ")[1].split("\n")[0]
|
||||
.trim();
|
||||
new TestRestTemplate("user", password)
|
||||
|
||||
@@ -19,14 +19,14 @@ package org.springframework.boot.autoconfigure.security.servlet;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.autoconfigure.security.SecurityProperties;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.boot.test.extension.CapturedOutput;
|
||||
import org.springframework.boot.test.extension.OutputExtension;
|
||||
import org.springframework.boot.test.system.CapturedOutput;
|
||||
import org.springframework.boot.test.system.OutputCaptureExtension;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
@@ -52,27 +52,26 @@ import static org.mockito.Mockito.mock;
|
||||
*
|
||||
* @author Madhura Bhave
|
||||
*/
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
public class UserDetailsServiceAutoConfigurationTests {
|
||||
|
||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(TestSecurityConfiguration.class).withConfiguration(
|
||||
AutoConfigurations.of(UserDetailsServiceAutoConfiguration.class));
|
||||
|
||||
@RegisterExtension
|
||||
CapturedOutput output = OutputExtension.capture();
|
||||
|
||||
@Test
|
||||
public void testDefaultUsernamePassword() {
|
||||
public void testDefaultUsernamePassword(CapturedOutput capturedOutput) {
|
||||
this.contextRunner.run((context) -> {
|
||||
UserDetailsService manager = context.getBean(UserDetailsService.class);
|
||||
assertThat(this.output.toString())
|
||||
assertThat(capturedOutput.toString())
|
||||
.contains("Using generated security password:");
|
||||
assertThat(manager.loadUserByUsername("user")).isNotNull();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultUserNotCreatedIfAuthenticationManagerBeanPresent() {
|
||||
public void defaultUserNotCreatedIfAuthenticationManagerBeanPresent(
|
||||
CapturedOutput capturedOutput) {
|
||||
this.contextRunner
|
||||
.withUserConfiguration(TestAuthenticationManagerConfiguration.class)
|
||||
.run((context) -> {
|
||||
@@ -80,7 +79,7 @@ public class UserDetailsServiceAutoConfigurationTests {
|
||||
.getBean(AuthenticationManager.class);
|
||||
assertThat(manager).isEqualTo(context.getBean(
|
||||
TestAuthenticationManagerConfiguration.class).authenticationManager);
|
||||
assertThat(this.output.toString())
|
||||
assertThat(capturedOutput.toString())
|
||||
.doesNotContain("Using generated security password: ");
|
||||
TestingAuthenticationToken token = new TestingAuthenticationToken(
|
||||
"foo", "bar");
|
||||
@@ -89,26 +88,28 @@ public class UserDetailsServiceAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultUserNotCreatedIfUserDetailsServiceBeanPresent() {
|
||||
public void defaultUserNotCreatedIfUserDetailsServiceBeanPresent(
|
||||
CapturedOutput capturedOutput) {
|
||||
this.contextRunner
|
||||
.withUserConfiguration(TestUserDetailsServiceConfiguration.class)
|
||||
.run((context) -> {
|
||||
UserDetailsService userDetailsService = context
|
||||
.getBean(UserDetailsService.class);
|
||||
assertThat(this.output.toString())
|
||||
assertThat(capturedOutput.toString())
|
||||
.doesNotContain("Using generated security password: ");
|
||||
assertThat(userDetailsService.loadUserByUsername("foo")).isNotNull();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultUserNotCreatedIfAuthenticationProviderBeanPresent() {
|
||||
public void defaultUserNotCreatedIfAuthenticationProviderBeanPresent(
|
||||
CapturedOutput capturedOutput) {
|
||||
this.contextRunner
|
||||
.withUserConfiguration(TestAuthenticationProviderConfiguration.class)
|
||||
.run((context) -> {
|
||||
AuthenticationProvider provider = context
|
||||
.getBean(AuthenticationProvider.class);
|
||||
assertThat(this.output.toString())
|
||||
assertThat(capturedOutput.toString())
|
||||
.doesNotContain("Using generated security password: ");
|
||||
TestingAuthenticationToken token = new TestingAuthenticationToken(
|
||||
"foo", "bar");
|
||||
@@ -153,10 +154,11 @@ public class UserDetailsServiceAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generatedPasswordShouldNotBePrintedIfAuthenticationManagerBuilderIsUsed() {
|
||||
public void generatedPasswordShouldNotBePrintedIfAuthenticationManagerBuilderIsUsed(
|
||||
CapturedOutput capturedOutput) {
|
||||
this.contextRunner
|
||||
.withUserConfiguration(TestConfigWithAuthenticationManagerBuilder.class)
|
||||
.run(((context) -> assertThat(this.output.toString())
|
||||
.run(((context) -> assertThat(capturedOutput.toString())
|
||||
.doesNotContain("Using generated security password: ")));
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.util.concurrent.Future;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.task.TaskExecutorBuilder;
|
||||
@@ -29,8 +29,8 @@ import org.springframework.boot.task.TaskExecutorCustomizer;
|
||||
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.boot.test.context.runner.ContextConsumer;
|
||||
import org.springframework.boot.test.extension.CapturedOutput;
|
||||
import org.springframework.boot.test.extension.OutputExtension;
|
||||
import org.springframework.boot.test.system.CapturedOutput;
|
||||
import org.springframework.boot.test.system.OutputCaptureExtension;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.task.SyncTaskExecutor;
|
||||
@@ -53,15 +53,13 @@ import static org.mockito.Mockito.verify;
|
||||
* @author Stephane Nicoll
|
||||
* @author Camille Vienot
|
||||
*/
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
public class TaskExecutionAutoConfigurationTests {
|
||||
|
||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(TaskExecutionAutoConfiguration.class));
|
||||
|
||||
@RegisterExtension
|
||||
CapturedOutput output = OutputExtension.capture();
|
||||
|
||||
@Test
|
||||
public void taskExecutorBuilderShouldApplyCustomSettings() {
|
||||
this.contextRunner
|
||||
@@ -113,15 +111,14 @@ public class TaskExecutionAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void taskExecutorAutoConfigured() {
|
||||
public void taskExecutorAutoConfigured(CapturedOutput capturedOutput) {
|
||||
this.contextRunner.run((context) -> {
|
||||
assertThat(this.output.toString())
|
||||
.doesNotContain("Initializing ExecutorService");
|
||||
assertThat(capturedOutput).doesNotContain("Initializing ExecutorService");
|
||||
assertThat(context).hasSingleBean(Executor.class);
|
||||
assertThat(context).hasBean("applicationTaskExecutor");
|
||||
assertThat(context).getBean("applicationTaskExecutor")
|
||||
.isInstanceOf(ThreadPoolTaskExecutor.class);
|
||||
assertThat(this.output.toString()).contains("Initializing ExecutorService");
|
||||
assertThat(capturedOutput).contains("Initializing ExecutorService");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.util.Locale;
|
||||
import nz.net.ultraq.thymeleaf.LayoutDialect;
|
||||
import nz.net.ultraq.thymeleaf.decorators.strategies.GroupingRespectLayoutTitleStrategy;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.thymeleaf.TemplateEngine;
|
||||
import org.thymeleaf.context.Context;
|
||||
import org.thymeleaf.context.IContext;
|
||||
@@ -37,8 +37,8 @@ import org.thymeleaf.templateresolver.ITemplateResolver;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner;
|
||||
import org.springframework.boot.test.extension.CapturedOutput;
|
||||
import org.springframework.boot.test.extension.OutputExtension;
|
||||
import org.springframework.boot.test.system.CapturedOutput;
|
||||
import org.springframework.boot.test.system.OutputCaptureExtension;
|
||||
import org.springframework.boot.testsupport.BuildOutput;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -58,11 +58,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Kazuki Shimizu
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
public class ThymeleafReactiveAutoConfigurationTests {
|
||||
|
||||
@RegisterExtension
|
||||
CapturedOutput output = OutputExtension.capture();
|
||||
|
||||
private final BuildOutput buildOutput = new BuildOutput(getClass());
|
||||
|
||||
private ReactiveWebApplicationContextRunner contextRunner = new ReactiveWebApplicationContextRunner()
|
||||
@@ -187,21 +185,21 @@ public class ThymeleafReactiveAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void templateLocationDoesNotExist() {
|
||||
public void templateLocationDoesNotExist(CapturedOutput capturedOutput) {
|
||||
this.contextRunner
|
||||
.withPropertyValues(
|
||||
"spring.thymeleaf.prefix:classpath:/no-such-directory/")
|
||||
.run((context) -> assertThat(this.output)
|
||||
.run((context) -> assertThat(capturedOutput)
|
||||
.contains("Cannot find template location"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void templateLocationEmpty() {
|
||||
public void templateLocationEmpty(CapturedOutput capturedOutput) {
|
||||
new File(this.buildOutput.getTestResourcesLocation(),
|
||||
"empty-templates/empty-directory").mkdirs();
|
||||
this.contextRunner.withPropertyValues(
|
||||
"spring.thymeleaf.prefix:classpath:/empty-templates/empty-directory/")
|
||||
.run((context) -> assertThat(this.output.toString())
|
||||
.run((context) -> assertThat(capturedOutput)
|
||||
.doesNotContain("Cannot find template location"));
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.test.context.FilteredClassLoader;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
|
||||
import org.springframework.boot.test.rule.OutputCapture;
|
||||
import org.springframework.boot.test.system.OutputCaptureRule;
|
||||
import org.springframework.boot.testsupport.BuildOutput;
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.boot.web.servlet.filter.OrderedCharacterEncodingFilter;
|
||||
@@ -75,7 +75,7 @@ import static org.hamcrest.Matchers.not;
|
||||
public class ThymeleafServletAutoConfigurationTests {
|
||||
|
||||
@Rule
|
||||
public OutputCapture output = new OutputCapture();
|
||||
public OutputCaptureRule output = new OutputCaptureRule();
|
||||
|
||||
private final BuildOutput buildOutput = new BuildOutput(getClass());
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.nio.charset.StandardCharsets;
|
||||
import javax.validation.Valid;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
@@ -32,8 +32,8 @@ import org.springframework.boot.autoconfigure.web.reactive.ReactiveWebServerFact
|
||||
import org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfiguration;
|
||||
import org.springframework.boot.test.context.assertj.AssertableReactiveWebApplicationContext;
|
||||
import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner;
|
||||
import org.springframework.boot.test.extension.CapturedOutput;
|
||||
import org.springframework.boot.test.extension.OutputExtension;
|
||||
import org.springframework.boot.test.system.CapturedOutput;
|
||||
import org.springframework.boot.test.system.OutputCaptureExtension;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -56,6 +56,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
*
|
||||
* @author Brian Clozel
|
||||
*/
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
public class DefaultErrorWebExceptionHandlerIntegrationTests {
|
||||
|
||||
private static final MediaType TEXT_HTML_UTF8 = new MediaType("text", "html",
|
||||
@@ -63,9 +64,6 @@ public class DefaultErrorWebExceptionHandlerIntegrationTests {
|
||||
|
||||
private final LogIdFilter logIdFilter = new LogIdFilter();
|
||||
|
||||
@RegisterExtension
|
||||
CapturedOutput output = OutputExtension.capture();
|
||||
|
||||
private ReactiveWebApplicationContextRunner contextRunner = new ReactiveWebApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
ReactiveWebServerFactoryAutoConfiguration.class,
|
||||
@@ -78,7 +76,7 @@ public class DefaultErrorWebExceptionHandlerIntegrationTests {
|
||||
.withUserConfiguration(Application.class);
|
||||
|
||||
@Test
|
||||
public void jsonError() {
|
||||
public void jsonError(CapturedOutput capturedOutput) {
|
||||
this.contextRunner.run((context) -> {
|
||||
WebTestClient client = getWebClient(context);
|
||||
client.get().uri("/").exchange().expectStatus()
|
||||
@@ -89,7 +87,7 @@ public class DefaultErrorWebExceptionHandlerIntegrationTests {
|
||||
.isEqualTo("Expected!").jsonPath("exception").doesNotExist()
|
||||
.jsonPath("trace").doesNotExist().jsonPath("requestId")
|
||||
.isEqualTo(this.logIdFilter.getLogId());
|
||||
assertThat(this.output).contains("500 Server Error for HTTP GET \"/\"")
|
||||
assertThat(capturedOutput).contains("500 Server Error for HTTP GET \"/\"")
|
||||
.contains("java.lang.IllegalStateException: Expected!");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,13 +17,13 @@
|
||||
package org.springframework.boot.autoconfigure.web.servlet.error;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration;
|
||||
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
|
||||
import org.springframework.boot.test.extension.CapturedOutput;
|
||||
import org.springframework.boot.test.extension.OutputExtension;
|
||||
import org.springframework.boot.test.system.CapturedOutput;
|
||||
import org.springframework.boot.test.system.OutputCaptureExtension;
|
||||
import org.springframework.boot.web.servlet.error.ErrorAttributes;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
@@ -38,6 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Brian Clozel
|
||||
*/
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
public class ErrorMvcAutoConfigurationTests {
|
||||
|
||||
private WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
|
||||
@@ -45,9 +46,6 @@ public class ErrorMvcAutoConfigurationTests {
|
||||
AutoConfigurations.of(DispatcherServletAutoConfiguration.class,
|
||||
ErrorMvcAutoConfiguration.class));
|
||||
|
||||
@RegisterExtension
|
||||
CapturedOutput output = OutputExtension.capture();
|
||||
|
||||
@Test
|
||||
public void renderContainsViewWithExceptionDetails() throws Exception {
|
||||
this.contextRunner.run((context) -> {
|
||||
@@ -69,7 +67,7 @@ public class ErrorMvcAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void renderWhenAlreadyCommittedLogsMessage() {
|
||||
public void renderWhenAlreadyCommittedLogsMessage(CapturedOutput capturedOutput) {
|
||||
this.contextRunner.run((context) -> {
|
||||
View errorView = context.getBean("error", View.class);
|
||||
ErrorAttributes errorAttributes = context.getBean(ErrorAttributes.class);
|
||||
@@ -77,7 +75,7 @@ public class ErrorMvcAutoConfigurationTests {
|
||||
new IllegalStateException("Exception message"), true);
|
||||
errorView.render(errorAttributes.getErrorAttributes(webRequest, true),
|
||||
webRequest.getRequest(), webRequest.getResponse());
|
||||
assertThat(this.output)
|
||||
assertThat(capturedOutput)
|
||||
.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 "
|
||||
|
||||
Reference in New Issue
Block a user