Repackage output capture and always use extension declaratively

Closes gh-17029
This commit is contained in:
Andy Wilkinson
2019-05-31 10:03:02 +01:00
parent d11d5ceb29
commit 0644a79401
69 changed files with 584 additions and 657 deletions

View File

@@ -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