|
|
@ -1,5 +1,5 @@
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Copyright 2012-2022 the original author or authors.
|
|
|
|
* Copyright 2012-2023 the original author or authors.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
@ -33,7 +33,9 @@ import org.springframework.util.ClassUtils;
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public class RestDocsTestExecutionListener extends AbstractTestExecutionListener {
|
|
|
|
public class RestDocsTestExecutionListener extends AbstractTestExecutionListener {
|
|
|
|
|
|
|
|
|
|
|
|
private static final String REST_DOCS_CLASS = "org.springframework.restdocs.ManualRestDocumentation";
|
|
|
|
private static final boolean REST_DOCS_PRESENT = ClassUtils.isPresent(
|
|
|
|
|
|
|
|
"org.springframework.restdocs.ManualRestDocumentation",
|
|
|
|
|
|
|
|
RestDocsTestExecutionListener.class.getClassLoader());
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public int getOrder() {
|
|
|
|
public int getOrder() {
|
|
|
@ -42,22 +44,18 @@ public class RestDocsTestExecutionListener extends AbstractTestExecutionListener
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void beforeTestMethod(TestContext testContext) throws Exception {
|
|
|
|
public void beforeTestMethod(TestContext testContext) throws Exception {
|
|
|
|
if (restDocsIsPresent()) {
|
|
|
|
if (REST_DOCS_PRESENT) {
|
|
|
|
new DocumentationHandler().beforeTestMethod(testContext);
|
|
|
|
new DocumentationHandler().beforeTestMethod(testContext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void afterTestMethod(TestContext testContext) throws Exception {
|
|
|
|
public void afterTestMethod(TestContext testContext) throws Exception {
|
|
|
|
if (restDocsIsPresent()) {
|
|
|
|
if (REST_DOCS_PRESENT) {
|
|
|
|
new DocumentationHandler().afterTestMethod(testContext);
|
|
|
|
new DocumentationHandler().afterTestMethod(testContext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private boolean restDocsIsPresent() {
|
|
|
|
|
|
|
|
return ClassUtils.isPresent(REST_DOCS_CLASS, getClass().getClassLoader());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static class DocumentationHandler {
|
|
|
|
private static class DocumentationHandler {
|
|
|
|
|
|
|
|
|
|
|
|
private void beforeTestMethod(TestContext testContext) {
|
|
|
|
private void beforeTestMethod(TestContext testContext) {
|
|
|
|