Align with breaking changes in spring-test

See gh-31241
This commit is contained in:
Andy Wilkinson 2022-06-26 09:55:36 +01:00
parent eca9343675
commit ac59b5781f
4 changed files with 22 additions and 21 deletions

View File

@ -16,8 +16,8 @@
package org.springframework.boot.test.autoconfigure;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.ArrayList;
import java.util.List;
import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport;
import org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportMessage;
@ -64,12 +64,12 @@ public class SpringBootDependencyInjectionTestExecutionListener extends Dependen
static class PostProcessor implements DefaultTestExecutionListenersPostProcessor {
@Override
public Set<Class<? extends TestExecutionListener>> postProcessDefaultTestExecutionListeners(
Set<Class<? extends TestExecutionListener>> listeners) {
Set<Class<? extends TestExecutionListener>> updated = new LinkedHashSet<>(listeners.size());
for (Class<? extends TestExecutionListener> listener : listeners) {
updated.add(listener.equals(DependencyInjectionTestExecutionListener.class)
? SpringBootDependencyInjectionTestExecutionListener.class : listener);
public List<TestExecutionListener> postProcessDefaultTestExecutionListeners(
List<TestExecutionListener> listeners) {
List<TestExecutionListener> updated = new ArrayList<>();
for (TestExecutionListener listener : listeners) {
updated.add((listener instanceof DependencyInjectionTestExecutionListener)
? new SpringBootDependencyInjectionTestExecutionListener() : listener);
}
return updated;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2022 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.
@ -16,14 +16,15 @@
package org.springframework.boot.test.context;
import java.util.Set;
import java.util.List;
import org.springframework.test.context.TestExecutionListener;
/**
* Callback interface trigger from {@link SpringBootTestContextBootstrapper} that can be
* used to post-process the list of default {@link TestExecutionListener} classes to be
* used by a test. Can be used to add or remove existing listener classes.
* used to post-process the list of default {@link TestExecutionListener
* TestExecutionListeners} to be used by a test. Can be used to add or remove existing
* listeners.
*
* @author Phillip Webb
* @since 1.4.1
@ -33,11 +34,12 @@ import org.springframework.test.context.TestExecutionListener;
public interface DefaultTestExecutionListenersPostProcessor {
/**
* Post process the list of default {@link TestExecutionListener} classes to be used.
* Post process the list of default {@link TestExecutionListener listeners} to be
* used.
* @param listeners the source listeners
* @return the actual listeners that should be used
* @since 3.0.0
*/
Set<Class<? extends TestExecutionListener>> postProcessDefaultTestExecutionListeners(
Set<Class<? extends TestExecutionListener>> listeners);
List<TestExecutionListener> postProcessDefaultTestExecutionListeners(List<TestExecutionListener> listeners);
}

View File

@ -110,8 +110,8 @@ public class SpringBootTestContextBootstrapper extends DefaultTestContextBootstr
}
@Override
protected Set<Class<? extends TestExecutionListener>> getDefaultTestExecutionListenerClasses() {
Set<Class<? extends TestExecutionListener>> listeners = super.getDefaultTestExecutionListenerClasses();
protected List<TestExecutionListener> getDefaultTestExecutionListeners() {
List<TestExecutionListener> listeners = new ArrayList<>(super.getDefaultTestExecutionListeners());
List<DefaultTestExecutionListenersPostProcessor> postProcessors = SpringFactoriesLoader
.loadFactories(DefaultTestExecutionListenersPostProcessor.class, getClass().getClassLoader());
for (DefaultTestExecutionListenersPostProcessor postProcessor : postProcessors) {

View File

@ -16,7 +16,7 @@
package org.springframework.boot.test.context.bootstrap;
import java.util.Set;
import java.util.List;
import org.springframework.boot.test.context.DefaultTestExecutionListenersPostProcessor;
import org.springframework.test.context.TestContext;
@ -31,9 +31,8 @@ import org.springframework.test.context.support.AbstractTestExecutionListener;
public class TestDefaultTestExecutionListenersPostProcessor implements DefaultTestExecutionListenersPostProcessor {
@Override
public Set<Class<? extends TestExecutionListener>> postProcessDefaultTestExecutionListeners(
Set<Class<? extends TestExecutionListener>> listeners) {
listeners.add(ExampleTestExecutionListener.class);
public List<TestExecutionListener> postProcessDefaultTestExecutionListeners(List<TestExecutionListener> listeners) {
listeners.add(new ExampleTestExecutionListener());
return listeners;
}