Repackage output capture and always use extension declaratively
Closes gh-17029
This commit is contained in:
@@ -17,12 +17,12 @@
|
||||
package sample.activemq;
|
||||
|
||||
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.test.context.SpringBootTest;
|
||||
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 static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -32,19 +32,17 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Eddú Meléndez
|
||||
*/
|
||||
@SpringBootTest
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
class SampleActiveMqTests {
|
||||
|
||||
@RegisterExtension
|
||||
CapturedOutput output = OutputExtension.capture();
|
||||
|
||||
@Autowired
|
||||
private Producer producer;
|
||||
|
||||
@Test
|
||||
void sendSimpleMessage() throws InterruptedException {
|
||||
void sendSimpleMessage(CapturedOutput capturedOutput) throws InterruptedException {
|
||||
this.producer.send("Test message");
|
||||
Thread.sleep(1000L);
|
||||
assertThat(this.output.toString().contains("Test message")).isTrue();
|
||||
assertThat(capturedOutput).contains("Test message");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,13 +21,13 @@ import java.util.Base64;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
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.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
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.test.web.servlet.MockMvc;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -44,21 +44,19 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
*/
|
||||
@SpringBootTest
|
||||
@AutoConfigureMockMvc
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
class SampleActuatorLog4J2ApplicationTests {
|
||||
|
||||
private static final Logger logger = LogManager
|
||||
.getLogger(SampleActuatorLog4J2ApplicationTests.class);
|
||||
|
||||
@RegisterExtension
|
||||
CapturedOutput output = OutputExtension.capture();
|
||||
|
||||
@Autowired
|
||||
private MockMvc mvc;
|
||||
|
||||
@Test
|
||||
void testLogger() {
|
||||
void testLogger(CapturedOutput capturedOutput) {
|
||||
logger.info("Hello World");
|
||||
assertThat(this.output).contains("Hello World");
|
||||
assertThat(capturedOutput).contains("Hello World");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -19,10 +19,10 @@ package sample.aop;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
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 static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -32,11 +32,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Dave Syer
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
class SampleAopApplicationTests {
|
||||
|
||||
@RegisterExtension
|
||||
CapturedOutput output = OutputExtension.capture();
|
||||
|
||||
private String profiles;
|
||||
|
||||
@BeforeEach
|
||||
@@ -55,15 +53,15 @@ class SampleAopApplicationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDefaultSettings() throws Exception {
|
||||
void testDefaultSettings(CapturedOutput capturedOutput) throws Exception {
|
||||
SampleAopApplication.main(new String[0]);
|
||||
assertThat(this.output).contains("Hello Phil");
|
||||
assertThat(capturedOutput).contains("Hello Phil");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCommandLineOverrides() throws Exception {
|
||||
void testCommandLineOverrides(CapturedOutput capturedOutput) throws Exception {
|
||||
SampleAopApplication.main(new String[] { "--name=Gordon" });
|
||||
assertThat(this.output).contains("Hello Gordon");
|
||||
assertThat(capturedOutput).contains("Hello Gordon");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,24 +17,22 @@
|
||||
package sample.batch;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
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 static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
class SampleBatchApplicationTests {
|
||||
|
||||
@RegisterExtension
|
||||
CapturedOutput output = OutputExtension.capture();
|
||||
|
||||
@Test
|
||||
void testDefaultSettings() {
|
||||
void testDefaultSettings(CapturedOutput capturedOutput) {
|
||||
assertThat(SpringApplication
|
||||
.exit(SpringApplication.run(SampleBatchApplication.class))).isEqualTo(0);
|
||||
assertThat(this.output).contains("completed with the following parameters");
|
||||
assertThat(capturedOutput).contains("completed with the following parameters");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,8 +25,8 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
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.test.context.TestExecutionListeners;
|
||||
import org.springframework.test.context.TestExecutionListeners.MergeMode;
|
||||
|
||||
@@ -37,7 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
@TestExecutionListeners(mergeMode = MergeMode.MERGE_WITH_DEFAULTS,
|
||||
listeners = { OrderedCassandraTestExecutionListener.class })
|
||||
@ExtendWith(OutputExtension.class)
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
@SpringBootTest
|
||||
@CassandraDataSet(keyspace = "mykeyspace", value = "setup.cql")
|
||||
@EmbeddedCassandra(timeout = 60000)
|
||||
|
||||
@@ -18,22 +18,20 @@ package sample.data.couchbase;
|
||||
import java.net.ConnectException;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
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.core.NestedCheckedException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
class SampleCouchbaseApplicationTests {
|
||||
|
||||
@RegisterExtension
|
||||
CapturedOutput output = OutputExtension.capture();
|
||||
|
||||
@Test
|
||||
void testDefaultSettings() {
|
||||
void testDefaultSettings(CapturedOutput capturedOutput) {
|
||||
try {
|
||||
new SpringApplicationBuilder(SampleCouchbaseApplication.class)
|
||||
.run("--server.port=0");
|
||||
@@ -43,7 +41,7 @@ class SampleCouchbaseApplicationTests {
|
||||
return;
|
||||
}
|
||||
}
|
||||
assertThat(this.output).contains("firstName='Alice', lastName='Smith'");
|
||||
assertThat(capturedOutput).contains("firstName='Alice', lastName='Smith'");
|
||||
}
|
||||
|
||||
private boolean serverNotRunning(RuntimeException ex) {
|
||||
|
||||
@@ -18,11 +18,11 @@ package sample.data.elasticsearch;
|
||||
|
||||
import org.elasticsearch.client.transport.NoNodeAvailableException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
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 static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -31,13 +31,11 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Artur Konczak
|
||||
*/
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
class SampleElasticsearchApplicationTests {
|
||||
|
||||
@RegisterExtension
|
||||
CapturedOutput output = OutputExtension.capture();
|
||||
|
||||
@Test
|
||||
void testDefaultSettings() {
|
||||
void testDefaultSettings(CapturedOutput capturedOutput) {
|
||||
try {
|
||||
new SpringApplicationBuilder(SampleElasticsearchApplication.class).run();
|
||||
}
|
||||
@@ -47,7 +45,7 @@ class SampleElasticsearchApplicationTests {
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
assertThat(this.output).contains("firstName='Alice', lastName='Smith'");
|
||||
assertThat(capturedOutput).contains("firstName='Alice', lastName='Smith'");
|
||||
}
|
||||
|
||||
private boolean elasticsearchRunning(Exception ex) {
|
||||
|
||||
@@ -20,8 +20,8 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
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 static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -30,7 +30,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@ExtendWith(OutputExtension.class)
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
@SpringBootTest
|
||||
class SampleLdapApplicationTests {
|
||||
|
||||
|
||||
@@ -16,10 +16,14 @@
|
||||
|
||||
package sample.data.mongo;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.mongo.MongoClientSettingsBuilderCustomizer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
@SpringBootApplication
|
||||
public class SampleMongoApplication implements CommandLineRunner {
|
||||
@@ -55,6 +59,13 @@ public class SampleMongoApplication implements CommandLineRunner {
|
||||
}
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MongoClientSettingsBuilderCustomizer customizer() {
|
||||
return (builder) -> builder
|
||||
.applyToConnectionPoolSettings((connectionPool) -> connectionPool
|
||||
.maxConnectionIdleTime(5, TimeUnit.MINUTES));
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SampleMongoApplication.class, args);
|
||||
}
|
||||
|
||||
@@ -20,8 +20,8 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
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 static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -31,7 +31,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Dave Syer
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@ExtendWith(OutputExtension.class)
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
@SpringBootTest
|
||||
class SampleMongoApplicationTests {
|
||||
|
||||
|
||||
@@ -17,11 +17,11 @@
|
||||
package sample.data.neo4j;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.neo4j.driver.v1.exceptions.ServiceUnavailableException;
|
||||
|
||||
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 static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -30,13 +30,11 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
class SampleNeo4jApplicationTests {
|
||||
|
||||
@RegisterExtension
|
||||
CapturedOutput output = OutputExtension.capture();
|
||||
|
||||
@Test
|
||||
void testDefaultSettings() {
|
||||
void testDefaultSettings(CapturedOutput capturedOutput) {
|
||||
try {
|
||||
SampleNeo4jApplication.main(new String[0]);
|
||||
}
|
||||
@@ -45,7 +43,7 @@ class SampleNeo4jApplicationTests {
|
||||
return;
|
||||
}
|
||||
}
|
||||
assertThat(this.output).contains("firstName='Alice', lastName='Smith'");
|
||||
assertThat(capturedOutput).contains("firstName='Alice', lastName='Smith'");
|
||||
}
|
||||
|
||||
private boolean neo4jServerRunning(Throwable ex) {
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
package sample.data.redis;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
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.data.redis.RedisConnectionFailureException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -30,13 +30,11 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
class SampleRedisApplicationTests {
|
||||
|
||||
@RegisterExtension
|
||||
CapturedOutput output = OutputExtension.capture();
|
||||
|
||||
@Test
|
||||
void testDefaultSettings() {
|
||||
void testDefaultSettings(CapturedOutput capturedOutput) {
|
||||
try {
|
||||
SampleRedisApplication.main(new String[0]);
|
||||
}
|
||||
@@ -45,7 +43,7 @@ class SampleRedisApplicationTests {
|
||||
return;
|
||||
}
|
||||
}
|
||||
assertThat(this.output).contains("Found key spring.boot.redis.test");
|
||||
assertThat(capturedOutput).contains("Found key spring.boot.redis.test");
|
||||
}
|
||||
|
||||
private boolean redisServerRunning(Throwable ex) {
|
||||
|
||||
@@ -17,21 +17,19 @@
|
||||
package sample.data.solr;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
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.core.NestedCheckedException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
class SampleSolrApplicationTests {
|
||||
|
||||
@RegisterExtension
|
||||
CapturedOutput output = OutputExtension.capture();
|
||||
|
||||
@Test
|
||||
void testDefaultSettings() throws Exception {
|
||||
void testDefaultSettings(CapturedOutput capturedOutput) throws Exception {
|
||||
try {
|
||||
SampleSolrApplication.main(new String[0]);
|
||||
}
|
||||
@@ -40,7 +38,7 @@ class SampleSolrApplicationTests {
|
||||
return;
|
||||
}
|
||||
}
|
||||
assertThat(this.output).contains("name=Sony Playstation");
|
||||
assertThat(capturedOutput).contains("name=Sony Playstation");
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
|
||||
@@ -17,29 +17,26 @@
|
||||
package sample.jooq;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
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 static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link SampleJooqApplication}.
|
||||
*/
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
class SampleJooqApplicationTests {
|
||||
|
||||
private static final String[] NO_ARGS = {};
|
||||
|
||||
@RegisterExtension
|
||||
CapturedOutput output = OutputExtension.capture();
|
||||
|
||||
@Test
|
||||
void outputResults() {
|
||||
void outputResults(CapturedOutput capturedOutput) {
|
||||
SampleJooqApplication.main(NO_ARGS);
|
||||
assertThat(this.output).contains("jOOQ Fetch 1 Greg Turnquest");
|
||||
assertThat(this.output).contains("jOOQ Fetch 2 Craig Walls");
|
||||
assertThat(this.output)
|
||||
assertThat(capturedOutput).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]");
|
||||
}
|
||||
|
||||
@@ -18,10 +18,10 @@ package sample.atomikos;
|
||||
|
||||
import org.assertj.core.api.Condition;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
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 static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -30,18 +30,15 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
class SampleAtomikosApplicationTests {
|
||||
|
||||
@RegisterExtension
|
||||
CapturedOutput output = OutputExtension.capture();
|
||||
|
||||
@Test
|
||||
void testTransactionRollback() throws Exception {
|
||||
void testTransactionRollback(CapturedOutput capturedOutput) throws Exception {
|
||||
SampleAtomikosApplication.main(new String[] {});
|
||||
assertThat(this.output.toString()).has(substring(1, "---->"));
|
||||
assertThat(this.output.toString()).has(substring(1, "----> josh"));
|
||||
assertThat(this.output.toString()).has(substring(2, "Count is 1"));
|
||||
assertThat(this.output.toString()).has(substring(1, "Simulated error"));
|
||||
assertThat(capturedOutput.toString()).has(substring(1, "---->"))
|
||||
.has(substring(1, "----> josh")).has(substring(2, "Count is 1"))
|
||||
.has(substring(1, "Simulated error"));
|
||||
}
|
||||
|
||||
private Condition<String> substring(int times, String substring) {
|
||||
|
||||
@@ -19,11 +19,11 @@ package sample.bitronix;
|
||||
import bitronix.tm.resource.jms.PoolingConnectionFactory;
|
||||
import org.assertj.core.api.Condition;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
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.ApplicationContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -33,18 +33,15 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
class SampleBitronixApplicationTests {
|
||||
|
||||
@RegisterExtension
|
||||
CapturedOutput output = OutputExtension.capture();
|
||||
|
||||
@Test
|
||||
void testTransactionRollback() throws Exception {
|
||||
void testTransactionRollback(CapturedOutput capturedOutput) throws Exception {
|
||||
SampleBitronixApplication.main(new String[] {});
|
||||
assertThat(this.output.toString()).has(substring(1, "---->"));
|
||||
assertThat(this.output.toString()).has(substring(1, "----> josh"));
|
||||
assertThat(this.output.toString()).has(substring(2, "Count is 1"));
|
||||
assertThat(this.output.toString()).has(substring(1, "Simulated error"));
|
||||
assertThat(capturedOutput.toString()).has(substring(1, "---->"))
|
||||
.has(substring(1, "----> josh")).has(substring(2, "Count is 1"))
|
||||
.has(substring(1, "Simulated error"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -19,21 +19,19 @@ package sample.liquibase;
|
||||
import java.net.ConnectException;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
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.core.NestedCheckedException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
class SampleLiquibaseApplicationTests {
|
||||
|
||||
@RegisterExtension
|
||||
CapturedOutput output = OutputExtension.capture();
|
||||
|
||||
@Test
|
||||
void testDefaultSettings() throws Exception {
|
||||
void testDefaultSettings(CapturedOutput capturedOutput) throws Exception {
|
||||
try {
|
||||
SampleLiquibaseApplication.main(new String[] { "--server.port=0" });
|
||||
}
|
||||
@@ -42,7 +40,7 @@ class SampleLiquibaseApplicationTests {
|
||||
return;
|
||||
}
|
||||
}
|
||||
assertThat(this.output).contains("Successfully acquired change log lock")
|
||||
assertThat(capturedOutput).contains("Successfully acquired change log lock")
|
||||
.contains("Creating database history "
|
||||
+ "table with name: PUBLIC.DATABASECHANGELOG")
|
||||
.contains("Table person created")
|
||||
|
||||
@@ -17,31 +17,29 @@
|
||||
package sample.logback;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
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 static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
class SampleLogbackApplicationTests {
|
||||
|
||||
@RegisterExtension
|
||||
CapturedOutput output = OutputExtension.capture();
|
||||
|
||||
@Test
|
||||
void testLoadedCustomLogbackConfig() throws Exception {
|
||||
void testLoadedCustomLogbackConfig(CapturedOutput capturedOutput) throws Exception {
|
||||
SampleLogbackApplication.main(new String[0]);
|
||||
assertThat(this.output).contains("Sample Debug Message");
|
||||
assertThat(this.output).doesNotContain("Sample Trace Message");
|
||||
assertThat(capturedOutput).contains("Sample Debug Message")
|
||||
.doesNotContain("Sample Trace Message");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testProfile() throws Exception {
|
||||
void testProfile(CapturedOutput capturedOutput) throws Exception {
|
||||
SampleLogbackApplication
|
||||
.main(new String[] { "--spring.profiles.active=staging" });
|
||||
assertThat(this.output).contains("Sample Debug Message");
|
||||
assertThat(this.output).contains("Sample Trace Message");
|
||||
assertThat(capturedOutput).contains("Sample Debug Message")
|
||||
.contains("Sample Trace Message");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,18 +19,16 @@ package sample.profile;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
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 static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
class SampleProfileApplicationTests {
|
||||
|
||||
@RegisterExtension
|
||||
CapturedOutput output = OutputExtension.capture();
|
||||
|
||||
private String profiles;
|
||||
|
||||
@BeforeEach
|
||||
@@ -49,20 +47,20 @@ class SampleProfileApplicationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDefaultProfile() throws Exception {
|
||||
void testDefaultProfile(CapturedOutput capturedOutput) {
|
||||
SampleProfileApplication.main(new String[0]);
|
||||
assertThat(this.output).contains("Hello Phil");
|
||||
assertThat(capturedOutput).contains("Hello Phil");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGoodbyeProfile() throws Exception {
|
||||
void testGoodbyeProfile(CapturedOutput capturedOutput) {
|
||||
System.setProperty("spring.profiles.active", "goodbye");
|
||||
SampleProfileApplication.main(new String[0]);
|
||||
assertThat(this.output).contains("Goodbye Everyone");
|
||||
assertThat(capturedOutput).contains("Goodbye Everyone");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericProfile() throws Exception {
|
||||
void testGenericProfile(CapturedOutput capturedOutput) {
|
||||
/*
|
||||
* 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
|
||||
@@ -71,14 +69,14 @@ class SampleProfileApplicationTests {
|
||||
*/
|
||||
System.setProperty("spring.profiles.active", "generic");
|
||||
SampleProfileApplication.main(new String[0]);
|
||||
assertThat(this.output).contains("Bonjour Phil");
|
||||
assertThat(capturedOutput).contains("Bonjour Phil");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGoodbyeProfileFromCommandline() throws Exception {
|
||||
void testGoodbyeProfileFromCommandline(CapturedOutput capturedOutput) {
|
||||
SampleProfileApplication
|
||||
.main(new String[] { "--spring.profiles.active=goodbye" });
|
||||
assertThat(this.output).contains("Goodbye Everyone");
|
||||
assertThat(capturedOutput).contains("Goodbye Everyone");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,11 +17,11 @@
|
||||
package sample.quartz;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
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.ConfigurableApplicationContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -31,21 +31,19 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Eddú Meléndez
|
||||
*/
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
class SampleQuartzApplicationTests {
|
||||
|
||||
@RegisterExtension
|
||||
CapturedOutput output = OutputExtension.capture();
|
||||
|
||||
@Test
|
||||
void quartzJobIsTriggered() throws InterruptedException {
|
||||
void quartzJobIsTriggered(CapturedOutput capturedOutput) throws InterruptedException {
|
||||
try (ConfigurableApplicationContext context = SpringApplication
|
||||
.run(SampleQuartzApplication.class)) {
|
||||
long end = System.currentTimeMillis() + 5000;
|
||||
while ((!this.output.toString().contains("Hello World!"))
|
||||
while ((!capturedOutput.toString().contains("Hello World!"))
|
||||
&& System.currentTimeMillis() < end) {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
assertThat(this.output).contains("Hello World!");
|
||||
assertThat(capturedOutput).contains("Hello World!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,10 +19,10 @@ package sample.simple;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
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 static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -32,11 +32,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Dave Syer
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
class SampleSimpleApplicationTests {
|
||||
|
||||
@RegisterExtension
|
||||
CapturedOutput output = OutputExtension.capture();
|
||||
|
||||
private String profiles;
|
||||
|
||||
@BeforeEach
|
||||
@@ -55,17 +53,15 @@ class SampleSimpleApplicationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDefaultSettings() throws Exception {
|
||||
void testDefaultSettings(CapturedOutput capturedOutput) {
|
||||
SampleSimpleApplication.main(new String[0]);
|
||||
String output = this.output.toString();
|
||||
assertThat(output).contains("Hello Phil");
|
||||
assertThat(capturedOutput).contains("Hello Phil");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCommandLineOverrides() throws Exception {
|
||||
void testCommandLineOverrides(CapturedOutput capturedOutput) {
|
||||
SampleSimpleApplication.main(new String[] { "--name=Gordon", "--duration=1m" });
|
||||
String output = this.output.toString();
|
||||
assertThat(output).contains("Hello Gordon for 60 seconds");
|
||||
assertThat(capturedOutput).contains("Hello Gordon for 60 seconds");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,23 +23,21 @@ import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
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.server.LocalServerPort;
|
||||
import org.springframework.ws.client.core.WebServiceTemplate;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
class SampleWsApplicationTests {
|
||||
|
||||
@RegisterExtension
|
||||
CapturedOutput output = OutputExtension.capture();
|
||||
|
||||
private WebServiceTemplate webServiceTemplate = new WebServiceTemplate();
|
||||
|
||||
@LocalServerPort
|
||||
@@ -52,7 +50,7 @@ class SampleWsApplicationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSendingHolidayRequest() {
|
||||
void testSendingHolidayRequest(CapturedOutput capturedOutput) {
|
||||
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>"
|
||||
@@ -63,7 +61,7 @@ class SampleWsApplicationTests {
|
||||
StreamSource source = new StreamSource(new StringReader(request));
|
||||
StreamResult result = new StreamResult(System.out);
|
||||
this.webServiceTemplate.sendSourceAndReceiveToResult(source, result);
|
||||
assertThat(this.output.toString()).contains("Booking holiday for");
|
||||
assertThat(capturedOutput).contains("Booking holiday for");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,23 +17,20 @@
|
||||
package sample.xml;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
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 static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
class SampleSpringXmlApplicationTests {
|
||||
|
||||
@RegisterExtension
|
||||
CapturedOutput output = OutputExtension.capture();
|
||||
|
||||
@Test
|
||||
void testDefaultSettings() throws Exception {
|
||||
void testDefaultSettings(CapturedOutput capturedOutput) throws Exception {
|
||||
SampleSpringXmlApplication.main(new String[0]);
|
||||
String output = this.output.toString();
|
||||
assertThat(output).contains("Hello World");
|
||||
assertThat(capturedOutput).contains("Hello World");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user