Validate our own tests work with JUnit5 and the vintage engine
Closes gh-14737 Co-authored-by: Stephane Nicoll <snicoll@pivotal.io>
This commit is contained in:
committed by
Stephane Nicoll
parent
d9f339a1b6
commit
1db1c8b03c
@@ -16,12 +16,12 @@
|
||||
|
||||
package sample.simple;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
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.springframework.boot.test.rule.OutputCapture;
|
||||
import org.springframework.boot.test.extension.OutputCapture;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -31,19 +31,19 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Dave Syer
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class SampleSimpleApplicationTests {
|
||||
class SampleSimpleApplicationTests {
|
||||
|
||||
@Rule
|
||||
public final OutputCapture output = new OutputCapture();
|
||||
@RegisterExtension
|
||||
OutputCapture output = new OutputCapture();
|
||||
|
||||
private String profiles;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void init() {
|
||||
this.profiles = System.getProperty("spring.profiles.active");
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void after() {
|
||||
if (this.profiles != null) {
|
||||
System.setProperty("spring.profiles.active", this.profiles);
|
||||
@@ -54,14 +54,14 @@ public class SampleSimpleApplicationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultSettings() throws Exception {
|
||||
void testDefaultSettings() throws Exception {
|
||||
SampleSimpleApplication.main(new String[0]);
|
||||
String output = this.output.toString();
|
||||
assertThat(output).contains("Hello Phil");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommandLineOverrides() throws Exception {
|
||||
void testCommandLineOverrides() throws Exception {
|
||||
SampleSimpleApplication.main(new String[] { "--name=Gordon", "--duration=1m" });
|
||||
String output = this.output.toString();
|
||||
assertThat(output).contains("Hello Gordon for 60 seconds");
|
||||
|
||||
@@ -16,13 +16,11 @@
|
||||
|
||||
package sample.simple;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -31,15 +29,14 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public class SpringTestSampleSimpleApplicationTests {
|
||||
class SpringTestSampleSimpleApplicationTests {
|
||||
|
||||
@Autowired
|
||||
ApplicationContext ctx;
|
||||
|
||||
@Test
|
||||
public void testContextLoads() {
|
||||
void testContextLoads() {
|
||||
assertThat(this.ctx).isNotNull();
|
||||
assertThat(this.ctx.containsBean("helloWorldService")).isTrue();
|
||||
assertThat(this.ctx.containsBean("sampleSimpleApplication")).isTrue();
|
||||
|
||||
Reference in New Issue
Block a user