Repackage output capture and always use extension declaratively
Closes gh-17029
This commit is contained in:
@@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user