parent
eca9343675
commit
ac59b5781f
|
@ -16,8 +16,8 @@
|
||||||
|
|
||||||
package org.springframework.boot.test.autoconfigure;
|
package org.springframework.boot.test.autoconfigure;
|
||||||
|
|
||||||
import java.util.LinkedHashSet;
|
import java.util.ArrayList;
|
||||||
import java.util.Set;
|
import java.util.List;
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport;
|
import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport;
|
||||||
import org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportMessage;
|
import org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportMessage;
|
||||||
|
@ -64,12 +64,12 @@ public class SpringBootDependencyInjectionTestExecutionListener extends Dependen
|
||||||
static class PostProcessor implements DefaultTestExecutionListenersPostProcessor {
|
static class PostProcessor implements DefaultTestExecutionListenersPostProcessor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<Class<? extends TestExecutionListener>> postProcessDefaultTestExecutionListeners(
|
public List<TestExecutionListener> postProcessDefaultTestExecutionListeners(
|
||||||
Set<Class<? extends TestExecutionListener>> listeners) {
|
List<TestExecutionListener> listeners) {
|
||||||
Set<Class<? extends TestExecutionListener>> updated = new LinkedHashSet<>(listeners.size());
|
List<TestExecutionListener> updated = new ArrayList<>();
|
||||||
for (Class<? extends TestExecutionListener> listener : listeners) {
|
for (TestExecutionListener listener : listeners) {
|
||||||
updated.add(listener.equals(DependencyInjectionTestExecutionListener.class)
|
updated.add((listener instanceof DependencyInjectionTestExecutionListener)
|
||||||
? SpringBootDependencyInjectionTestExecutionListener.class : listener);
|
? new SpringBootDependencyInjectionTestExecutionListener() : listener);
|
||||||
}
|
}
|
||||||
return updated;
|
return updated;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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");
|
* 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.
|
||||||
|
@ -16,14 +16,15 @@
|
||||||
|
|
||||||
package org.springframework.boot.test.context;
|
package org.springframework.boot.test.context;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.List;
|
||||||
|
|
||||||
import org.springframework.test.context.TestExecutionListener;
|
import org.springframework.test.context.TestExecutionListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback interface trigger from {@link SpringBootTestContextBootstrapper} that can be
|
* Callback interface trigger from {@link SpringBootTestContextBootstrapper} that can be
|
||||||
* used to post-process the list of default {@link TestExecutionListener} classes to be
|
* used to post-process the list of default {@link TestExecutionListener
|
||||||
* used by a test. Can be used to add or remove existing listener classes.
|
* TestExecutionListeners} to be used by a test. Can be used to add or remove existing
|
||||||
|
* listeners.
|
||||||
*
|
*
|
||||||
* @author Phillip Webb
|
* @author Phillip Webb
|
||||||
* @since 1.4.1
|
* @since 1.4.1
|
||||||
|
@ -33,11 +34,12 @@ import org.springframework.test.context.TestExecutionListener;
|
||||||
public interface DefaultTestExecutionListenersPostProcessor {
|
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
|
* @param listeners the source listeners
|
||||||
* @return the actual listeners that should be used
|
* @return the actual listeners that should be used
|
||||||
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
Set<Class<? extends TestExecutionListener>> postProcessDefaultTestExecutionListeners(
|
List<TestExecutionListener> postProcessDefaultTestExecutionListeners(List<TestExecutionListener> listeners);
|
||||||
Set<Class<? extends TestExecutionListener>> listeners);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,8 +110,8 @@ public class SpringBootTestContextBootstrapper extends DefaultTestContextBootstr
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Set<Class<? extends TestExecutionListener>> getDefaultTestExecutionListenerClasses() {
|
protected List<TestExecutionListener> getDefaultTestExecutionListeners() {
|
||||||
Set<Class<? extends TestExecutionListener>> listeners = super.getDefaultTestExecutionListenerClasses();
|
List<TestExecutionListener> listeners = new ArrayList<>(super.getDefaultTestExecutionListeners());
|
||||||
List<DefaultTestExecutionListenersPostProcessor> postProcessors = SpringFactoriesLoader
|
List<DefaultTestExecutionListenersPostProcessor> postProcessors = SpringFactoriesLoader
|
||||||
.loadFactories(DefaultTestExecutionListenersPostProcessor.class, getClass().getClassLoader());
|
.loadFactories(DefaultTestExecutionListenersPostProcessor.class, getClass().getClassLoader());
|
||||||
for (DefaultTestExecutionListenersPostProcessor postProcessor : postProcessors) {
|
for (DefaultTestExecutionListenersPostProcessor postProcessor : postProcessors) {
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
package org.springframework.boot.test.context.bootstrap;
|
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.boot.test.context.DefaultTestExecutionListenersPostProcessor;
|
||||||
import org.springframework.test.context.TestContext;
|
import org.springframework.test.context.TestContext;
|
||||||
|
@ -31,9 +31,8 @@ import org.springframework.test.context.support.AbstractTestExecutionListener;
|
||||||
public class TestDefaultTestExecutionListenersPostProcessor implements DefaultTestExecutionListenersPostProcessor {
|
public class TestDefaultTestExecutionListenersPostProcessor implements DefaultTestExecutionListenersPostProcessor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<Class<? extends TestExecutionListener>> postProcessDefaultTestExecutionListeners(
|
public List<TestExecutionListener> postProcessDefaultTestExecutionListeners(List<TestExecutionListener> listeners) {
|
||||||
Set<Class<? extends TestExecutionListener>> listeners) {
|
listeners.add(new ExampleTestExecutionListener());
|
||||||
listeners.add(ExampleTestExecutionListener.class);
|
|
||||||
return listeners;
|
return listeners;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue