Skip to content

Commit

Permalink
Polish
Browse files Browse the repository at this point in the history
  • Loading branch information
philwebb authored and wilkinsona committed Oct 19, 2023
1 parent fcb75b6 commit 343046d
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,26 @@ class ServiceConnectionContextCustomizerFactory implements ContextCustomizerFact
public ContextCustomizer createContextCustomizer(Class<?> testClass,
List<ContextConfigurationAttributes> configAttributes) {
List<ContainerConnectionSource<?>> sources = new ArrayList<>();
findSources(testClass, sources);
collectSources(testClass, sources);
return new ServiceConnectionContextCustomizer(sources);
}

private void findSources(Class<?> clazz, List<ContainerConnectionSource<?>> sources) {
if (clazz == Object.class || clazz == null) {
private void collectSources(Class<?> candidate, List<ContainerConnectionSource<?>> sources) {
if (candidate == Object.class || candidate == null) {
return;
}
ReflectionUtils.doWithLocalFields(clazz, (field) -> {
ReflectionUtils.doWithLocalFields(candidate, (field) -> {
MergedAnnotations annotations = MergedAnnotations.from(field);
annotations.stream(ServiceConnection.class)
.forEach((annotation) -> sources.add(createSource(field, annotation)));
});
if (TestContextAnnotationUtils.searchEnclosingClass(clazz)) {
findSources(clazz.getEnclosingClass(), sources);
if (TestContextAnnotationUtils.searchEnclosingClass(candidate)) {
collectSources(candidate.getEnclosingClass(), sources);
}
for (Class<?> implementedInterface : clazz.getInterfaces()) {
findSources(implementedInterface, sources);
for (Class<?> implementedInterface : candidate.getInterfaces()) {
collectSources(implementedInterface, sources);
}
findSources(clazz.getSuperclass(), sources);
collectSources(candidate.getSuperclass(), sources);
}

@SuppressWarnings("unchecked")
Expand Down

0 comments on commit 343046d

Please sign in to comment.