Commit 808b373d authored by Andy Wilkinson's avatar Andy Wilkinson

Merge branch '2.1.x'

Closes gh-17552
parents 9d85dbad 9dabc0e1
...@@ -36,11 +36,12 @@ class MockMvcPrintOnlyOnFailureTestExecutionListener extends AbstractTestExecuti ...@@ -36,11 +36,12 @@ class MockMvcPrintOnlyOnFailureTestExecutionListener extends AbstractTestExecuti
@Override @Override
public void afterTestMethod(TestContext testContext) throws Exception { public void afterTestMethod(TestContext testContext) throws Exception {
if (testContext.getTestException() != null) { DeferredLinesWriter writer = DeferredLinesWriter.get(testContext.getApplicationContext());
DeferredLinesWriter writer = DeferredLinesWriter.get(testContext.getApplicationContext()); if (writer != null) {
if (writer != null) { if (testContext.getTestException() != null) {
writer.writeDeferredResult(); writer.writeDeferredResult();
} }
writer.clear();
} }
} }
......
...@@ -253,6 +253,10 @@ public class SpringBootMockMvcBuilderCustomizer implements MockMvcBuilderCustomi ...@@ -253,6 +253,10 @@ public class SpringBootMockMvcBuilderCustomizer implements MockMvcBuilderCustomi
} }
} }
void clear() {
this.lines.clear();
}
} }
/** /**
......
...@@ -16,7 +16,9 @@ ...@@ -16,7 +16,9 @@
package org.springframework.boot.test.autoconfigure.web.servlet.mockmvc; package org.springframework.boot.test.autoconfigure.web.servlet.mockmvc;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.platform.engine.discovery.DiscoverySelectors; import org.junit.platform.engine.discovery.DiscoverySelectors;
...@@ -43,6 +45,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. ...@@ -43,6 +45,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
* @author Andy Wilkinson * @author Andy Wilkinson
*/ */
@ExtendWith(OutputCaptureExtension.class) @ExtendWith(OutputCaptureExtension.class)
@TestMethodOrder(MethodOrderer.Alphanumeric.class)
class WebMvcTestPrintDefaultIntegrationTests { class WebMvcTestPrintDefaultIntegrationTests {
@Test @Test
...@@ -54,7 +57,7 @@ class WebMvcTestPrintDefaultIntegrationTests { ...@@ -54,7 +57,7 @@ class WebMvcTestPrintDefaultIntegrationTests {
@Test @Test
void shouldPrint(CapturedOutput output) throws Throwable { void shouldPrint(CapturedOutput output) throws Throwable {
executeTests(ShouldPrint.class); executeTests(ShouldPrint.class);
assertThat(output).contains("HTTP Method"); assertThat(output).containsOnlyOnce("HTTP Method");
} }
private void executeTests(Class<?> testClass) throws Throwable { private void executeTests(Class<?> testClass) throws Throwable {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment