From 51f0d88eecdbbdb37f34136f85096c6bffd929f7 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Wed, 17 Jan 2018 14:31:52 +0100 Subject: [PATCH] Polish "Add test to spring-boot-sample-quartz" Closes gh-11621 --- spring-boot-samples/spring-boot-sample-quartz/pom.xml | 1 + .../sample/quartz/SampleQuartzApplicationTests.java | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/spring-boot-samples/spring-boot-sample-quartz/pom.xml b/spring-boot-samples/spring-boot-sample-quartz/pom.xml index 082cd0bc81..0db481251c 100644 --- a/spring-boot-samples/spring-boot-sample-quartz/pom.xml +++ b/spring-boot-samples/spring-boot-sample-quartz/pom.xml @@ -19,6 +19,7 @@ org.springframework.boot spring-boot-starter-quartz + org.springframework.boot spring-boot-starter-test diff --git a/spring-boot-samples/spring-boot-sample-quartz/src/test/java/sample/quartz/SampleQuartzApplicationTests.java b/spring-boot-samples/spring-boot-sample-quartz/src/test/java/sample/quartz/SampleQuartzApplicationTests.java index 58c62ce96b..60890e9ad9 100644 --- a/spring-boot-samples/spring-boot-sample-quartz/src/test/java/sample/quartz/SampleQuartzApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-quartz/src/test/java/sample/quartz/SampleQuartzApplicationTests.java @@ -19,7 +19,9 @@ package sample.quartz; import org.junit.Rule; import org.junit.Test; +import org.springframework.boot.SpringApplication; import org.springframework.boot.test.rule.OutputCapture; +import org.springframework.context.ConfigurableApplicationContext; import static org.assertj.core.api.Assertions.assertThat; @@ -35,9 +37,11 @@ public class SampleQuartzApplicationTests { @Test public void test() { - SampleQuartzApplication.main(new String[0]); - String output = this.outputCapture.toString(); - assertThat(output).contains("Hello World!"); + try (ConfigurableApplicationContext context = SpringApplication.run( + SampleQuartzApplication.class)) { + String output = this.outputCapture.toString(); + assertThat(output).contains("Hello World!"); + } } }