From ac59b5781f30d98b8873fd0dc0010a5dbb9ccf5b Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Sun, 26 Jun 2022 09:55:36 +0100 Subject: [PATCH] Align with breaking changes in spring-test See gh-31241 --- ...DependencyInjectionTestExecutionListener.java | 16 ++++++++-------- ...faultTestExecutionListenersPostProcessor.java | 16 +++++++++------- .../SpringBootTestContextBootstrapper.java | 4 ++-- ...faultTestExecutionListenersPostProcessor.java | 7 +++---- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/SpringBootDependencyInjectionTestExecutionListener.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/SpringBootDependencyInjectionTestExecutionListener.java index 2a40bee9ad9..79da370fdbc 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/SpringBootDependencyInjectionTestExecutionListener.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/SpringBootDependencyInjectionTestExecutionListener.java @@ -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> postProcessDefaultTestExecutionListeners( - Set> listeners) { - Set> updated = new LinkedHashSet<>(listeners.size()); - for (Class listener : listeners) { - updated.add(listener.equals(DependencyInjectionTestExecutionListener.class) - ? SpringBootDependencyInjectionTestExecutionListener.class : listener); + public List postProcessDefaultTestExecutionListeners( + List listeners) { + List updated = new ArrayList<>(); + for (TestExecutionListener listener : listeners) { + updated.add((listener instanceof DependencyInjectionTestExecutionListener) + ? new SpringBootDependencyInjectionTestExecutionListener() : listener); } return updated; } diff --git a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/DefaultTestExecutionListenersPostProcessor.java b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/DefaultTestExecutionListenersPostProcessor.java index f6ec50f7302..4b67232419a 100644 --- a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/DefaultTestExecutionListenersPostProcessor.java +++ b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/DefaultTestExecutionListenersPostProcessor.java @@ -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> postProcessDefaultTestExecutionListeners( - Set> listeners); + List postProcessDefaultTestExecutionListeners(List listeners); } diff --git a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootTestContextBootstrapper.java b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootTestContextBootstrapper.java index c89ae886da4..56a4f057c7f 100644 --- a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootTestContextBootstrapper.java +++ b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootTestContextBootstrapper.java @@ -110,8 +110,8 @@ public class SpringBootTestContextBootstrapper extends DefaultTestContextBootstr } @Override - protected Set> getDefaultTestExecutionListenerClasses() { - Set> listeners = super.getDefaultTestExecutionListenerClasses(); + protected List getDefaultTestExecutionListeners() { + List listeners = new ArrayList<>(super.getDefaultTestExecutionListeners()); List postProcessors = SpringFactoriesLoader .loadFactories(DefaultTestExecutionListenersPostProcessor.class, getClass().getClassLoader()); for (DefaultTestExecutionListenersPostProcessor postProcessor : postProcessors) { diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/bootstrap/TestDefaultTestExecutionListenersPostProcessor.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/bootstrap/TestDefaultTestExecutionListenersPostProcessor.java index 7aad5701fb4..170c9f63e22 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/bootstrap/TestDefaultTestExecutionListenersPostProcessor.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/bootstrap/TestDefaultTestExecutionListenersPostProcessor.java @@ -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> postProcessDefaultTestExecutionListeners( - Set> listeners) { - listeners.add(ExampleTestExecutionListener.class); + public List postProcessDefaultTestExecutionListeners(List listeners) { + listeners.add(new ExampleTestExecutionListener()); return listeners; }