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,28 +16,28 @@
|
||||
|
||||
package sample.profile;
|
||||
|
||||
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;
|
||||
|
||||
public class SampleProfileApplicationTests {
|
||||
class SampleProfileApplicationTests {
|
||||
|
||||
@Rule
|
||||
public final OutputCapture output = new OutputCapture();
|
||||
@RegisterExtension
|
||||
OutputCapture output = new OutputCapture();
|
||||
|
||||
private String profiles;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void before() {
|
||||
this.profiles = System.getProperty("spring.profiles.active");
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void after() {
|
||||
if (this.profiles != null) {
|
||||
System.setProperty("spring.profiles.active", this.profiles);
|
||||
@@ -48,20 +48,20 @@ public class SampleProfileApplicationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultProfile() throws Exception {
|
||||
void testDefaultProfile() throws Exception {
|
||||
SampleProfileApplication.main(new String[0]);
|
||||
assertThat(this.output.toString()).contains("Hello Phil");
|
||||
assertThat(this.output).contains("Hello Phil");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGoodbyeProfile() throws Exception {
|
||||
void testGoodbyeProfile() throws Exception {
|
||||
System.setProperty("spring.profiles.active", "goodbye");
|
||||
SampleProfileApplication.main(new String[0]);
|
||||
assertThat(this.output.toString()).contains("Goodbye Everyone");
|
||||
assertThat(this.output).contains("Goodbye Everyone");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenericProfile() throws Exception {
|
||||
void testGenericProfile() throws Exception {
|
||||
/*
|
||||
* 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
|
||||
@@ -70,14 +70,14 @@ public class SampleProfileApplicationTests {
|
||||
*/
|
||||
System.setProperty("spring.profiles.active", "generic");
|
||||
SampleProfileApplication.main(new String[0]);
|
||||
assertThat(this.output.toString()).contains("Bonjour Phil");
|
||||
assertThat(this.output).contains("Bonjour Phil");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGoodbyeProfileFromCommandline() throws Exception {
|
||||
void testGoodbyeProfileFromCommandline() throws Exception {
|
||||
SampleProfileApplication
|
||||
.main(new String[] { "--spring.profiles.active=goodbye" });
|
||||
assertThat(this.output.toString()).contains("Goodbye Everyone");
|
||||
assertThat(this.output).contains("Goodbye Everyone");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user