Treat the only one default candidate as effectively primary#1
Draft
Pankraz76 wants to merge 1 commit intoPankraz76:mainfrom
Draft
Treat the only one default candidate as effectively primary#1Pankraz76 wants to merge 1 commit intoPankraz76:mainfrom
Pankraz76 wants to merge 1 commit intoPankraz76:mainfrom
Conversation
Close spring-projectsGH-34432 Signed-off-by: Yanming Zhou <zhouyanming@gmail.com>
Owner
Author
|
nice approach looks perfectly fine to me. |
Pankraz76
commented
Feb 17, 2025
| } | ||
| } | ||
| } | ||
| return candidateBeanName; |
Owner
Author
There was a problem hiding this comment.
maybe filtering would highlight the main condition:
.filter(entry -> entry.getValue().isAutowireCandidate() && entry.getValue().isDefaultCandidate())
protected String determineEffectivelyPrimaryCandidate(Map<String, Object> candidates, Class<?> requiredType) {
return candidates.entrySet().stream()
.map(entry -> Map.entry(entry.getKey(), transformedBeanName(entry.getKey())))
.filter(entry -> containsBeanDefinition(entry.getValue()))
.map(entry -> Map.entry(entry.getKey(), getMergedLocalBeanDefinition(entry.getValue())))
.filter(entry -> entry.getValue().isAutowireCandidate() && entry.getValue().isDefaultCandidate())
.map(Map.Entry::getKey)
.reduce((a, b) -> null) // Ensures only one candidate; otherwise, null
.orElse(null);
}
Its although nice, if a method has only has one return statement.
Pankraz76
pushed a commit
that referenced
this pull request
Nov 11, 2025
Historically, @Autowired fields in an enclosing class of a @Nested test class have been injected from the ApplicationContext for the enclosing class. If the enclosing test class and @Nested test class share the same ApplicationContext configuration, things work as developers expect. However, if the enclosing class and @Nested test class have different ApplicationContexts, that can lead to difficult-to-debug scenarios. For example, a bean injected into the enclosing test class will not participate in a test-managed transaction in the @Nested test class (see spring-projectsgh-34576). JUnit Jupiter 5.12 introduced a new ExtensionContextScope feature which allows the SpringExtension to behave the same for @Autowired fields as it already does for @Autowired arguments in lifecycle and test methods. Specifically, if a developer sets the ExtensionContextScope to TEST_METHOD — for example, by configuring the following configuration parameter as a JVM system property or in a `junit-platform.properties` file — the SpringExtension already supports dependency injection from the current, @Nested ApplicationContext in @Autowired fields in an enclosing class of the @Nested test class. junit.jupiter.extensions.testinstantiation.extensioncontextscope.default=test_method However, there are two scenarios that fail as of Spring Framework 6.2.12. 1. @TestConstructor configuration in @Nested class hierarchies. 2. Field injection for bean overrides (such as @MockitoBean) in @Nested class hierarchies. Commit 82c34f7 fixed the SpringExtension to support scenario #2 above. To fix scenario #1, this commit revises BeanOverrideTestExecutionListener's injectField() implementation to look up the fields to inject for the "current test instance" instead of for the "current test class". This commit also introduces tests for both scenarios. See spring-projectsgh-34576 See spring-projectsgh-35676 Closes spring-projectsgh-35680
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Close spring-projectsGH-34432