Skip to content

Commit 08e22c5

Browse files
committed
Polishing.
Reformat code. See #3414 Original pull request: #3415
1 parent 926c22b commit 08e22c5

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

src/main/java/org/springframework/data/aot/ManagedTypesBeanRegistrationAotProcessor.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,11 @@
5454
*/
5555
public class ManagedTypesBeanRegistrationAotProcessor implements BeanRegistrationAotProcessor, EnvironmentAware {
5656

57+
private static final Lazy<Environment> DEFAULT_ENVIRONMENT = Lazy.of(StandardEnvironment::new);
58+
5759
private final Log logger = LogFactory.getLog(getClass());
60+
5861
private @Nullable String moduleIdentifier;
59-
private static final Lazy<Environment> DEFAULT_ENVIRONMENT = Lazy.of(StandardEnvironment::new);
6062
private @Nullable Environment environment = null;
6163

6264
public void setModuleIdentifier(@Nullable String moduleIdentifier) {
@@ -195,12 +197,14 @@ protected Environment getConfiguredEnvironmentOrTryToResolveOne(RegisteredBean r
195197

196198
if (registeredBean.getBeanFactory() instanceof EnvironmentCapable ec) {
197199
return ec.getEnvironment();
198-
} else {
199-
String[] beanNamesForType = registeredBean.getBeanFactory().getBeanNamesForType(Environment.class);
200-
if (!ObjectUtils.isEmpty(beanNamesForType)) {
201-
return registeredBean.getBeanFactory().getBean(beanNamesForType[0], Environment.class);
202-
}
203200
}
201+
202+
String[] beanNamesForType = registeredBean.getBeanFactory().getBeanNamesForType(Environment.class);
203+
if (!ObjectUtils.isEmpty(beanNamesForType)) {
204+
return registeredBean.getBeanFactory().getBean(beanNamesForType[0], Environment.class);
205+
}
206+
204207
return DEFAULT_ENVIRONMENT.get();
205208
}
209+
206210
}

src/test/java/org/springframework/data/aot/ManagedTypesBeanRegistrationAotProcessorUnitTests.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package org.springframework.data.aot;
1717

1818
import static org.assertj.core.api.Assertions.*;
19-
import static org.mockito.ArgumentMatchers.*;
2019
import static org.mockito.Mockito.*;
2120

2221
import java.util.Arrays;
@@ -28,6 +27,7 @@
2827
import org.junit.jupiter.api.BeforeEach;
2928
import org.junit.jupiter.api.Test;
3029
import org.mockito.Mockito;
30+
3131
import org.springframework.aot.generate.GenerationContext;
3232
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
3333
import org.springframework.aot.test.generate.TestGenerationContext;
@@ -91,7 +91,7 @@ void processesBeanDefinitionIfPossibleWithoutLoadingTheBean() {
9191

9292
createPostProcessor("commons").processAheadOfTime(RegisteredBean.of(beanFactory, "commons.managed-types"));
9393

94-
verify(beanFactory, never()).getBean(eq("commons.managed-types"), eq(ManagedTypes.class));
94+
verify(beanFactory, never()).getBean("commons.managed-types", ManagedTypes.class);
9595
}
9696

9797
@Test // GH-2593
@@ -128,7 +128,7 @@ void processesMatchingSubtypeBeanByAttemptingToLoadItIfNoMatchingConstructorArgu
128128

129129
createPostProcessor("commons").processAheadOfTime(RegisteredBean.of(beanFactory, "commons.managed-types"));
130130

131-
verify(beanFactory).getBean(eq("commons.managed-types"), eq(ManagedTypes.class));
131+
verify(beanFactory).getBean("commons.managed-types", ManagedTypes.class);
132132
}
133133

134134
@Test // GH-2593
@@ -157,8 +157,7 @@ void ignoresBeanNotMatchingPrefix() {
157157
@Test // GH-2593
158158
void returnsEmptyContributionWhenBeanCannotBeLoaded() {
159159

160-
doThrow(new BeanCreationException("o_O")).when(beanFactory).getBean(eq("commons.managed-types"),
161-
eq(ManagedTypes.class));
160+
doThrow(new BeanCreationException("o_O")).when(beanFactory).getBean("commons.managed-types", ManagedTypes.class);
162161

163162
beanFactory.registerBeanDefinition("commons.managed-types", myManagedTypesDefinition);
164163

@@ -170,7 +169,7 @@ void returnsEmptyContributionWhenBeanCannotBeLoaded() {
170169
contribution.applyTo(generationContext, null);
171170

172171
assertThat(generationContext.getRuntimeHints().reflection().typeHints()).isEmpty();
173-
verify(beanFactory).getBean(eq("commons.managed-types"), eq(ManagedTypes.class));
172+
verify(beanFactory).getBean("commons.managed-types", ManagedTypes.class);
174173
}
175174

176175
@Test // GH-2680
@@ -282,7 +281,7 @@ void usesConfiguredEnvironment() {
282281

283282
contribution.applyTo(new TestGenerationContext(Object.class), null);
284283

285-
verify(env).getProperty(eq("spring.aot.data.accessors.enabled"), eq(Boolean.class), eq(true));
284+
verify(env).getProperty("spring.aot.data.accessors.enabled", Boolean.class, true);
286285
}
287286

288287
@Test // GH-3414
@@ -299,7 +298,7 @@ void usesUsesEnvironmentFromBeanIfNotSet() {
299298

300299
contribution.applyTo(new TestGenerationContext(Object.class), null);
301300

302-
verify(env).getProperty(eq("spring.aot.data.accessors.enabled"), eq(Boolean.class), eq(true));
301+
verify(env).getProperty("spring.aot.data.accessors.enabled", Boolean.class, true);
303302
}
304303

305304
private ManagedTypesBeanRegistrationAotProcessor createPostProcessor(String moduleIdentifier) {

0 commit comments

Comments
 (0)