Skip to content

Commit

Permalink
Merge branch '2.7.x' into 3.0.x
Browse files Browse the repository at this point in the history
Closes gh-34869
  • Loading branch information
snicoll committed Apr 5, 2023
2 parents 378b468 + da84e41 commit ace8cff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -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");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -33,7 +33,9 @@
*/
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
public int getOrder() {
Expand All @@ -42,22 +44,18 @@ public int getOrder() {

@Override
public void beforeTestMethod(TestContext testContext) throws Exception {
if (restDocsIsPresent()) {
if (REST_DOCS_PRESENT) {
new DocumentationHandler().beforeTestMethod(testContext);
}
}

@Override
public void afterTestMethod(TestContext testContext) throws Exception {
if (restDocsIsPresent()) {
if (REST_DOCS_PRESENT) {
new DocumentationHandler().afterTestMethod(testContext);
}
}

private boolean restDocsIsPresent() {
return ClassUtils.isPresent(REST_DOCS_CLASS, getClass().getClassLoader());
}

private static class DocumentationHandler {

private void beforeTestMethod(TestContext testContext) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -33,7 +33,9 @@
*/
public class MockWebServiceServerTestExecutionListener extends AbstractTestExecutionListener {

private static final String MOCK_SERVER_CLASS = "org.springframework.ws.test.client.MockWebServiceServer";
private static final boolean MOCK_SERVER_PRESENT = ClassUtils.isPresent(
"org.springframework.ws.test.client.MockWebServiceServer",
MockWebServiceServerTestExecutionListener.class.getClassLoader());

@Override
public int getOrder() {
Expand All @@ -42,7 +44,7 @@ public int getOrder() {

@Override
public void afterTestMethod(TestContext testContext) {
if (isMockWebServiceServerPresent()) {
if (MOCK_SERVER_PRESENT) {
ApplicationContext applicationContext = testContext.getApplicationContext();
String[] names = applicationContext.getBeanNamesForType(MockWebServiceServer.class, false, false);
for (String name : names) {
Expand All @@ -53,8 +55,4 @@ public void afterTestMethod(TestContext testContext) {
}
}

private boolean isMockWebServiceServerPresent() {
return ClassUtils.isPresent(MOCK_SERVER_CLASS, getClass().getClassLoader());
}

}

0 comments on commit ace8cff

Please sign in to comment.