Skip to content

Commit

Permalink
Make RuntimeHints predicates more explicit
Browse files Browse the repository at this point in the history
This commit narrows method invocation wherever applicable as the default
is 'introspect' only.
  • Loading branch information
snicoll committed Jan 11, 2025
1 parent 328f670 commit 46a499b
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2025 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.
Expand Down Expand Up @@ -38,7 +38,7 @@ void shouldRegisterHints() {
RuntimeHints runtimeHints = new RuntimeHints();
new CloudFoundryWebFluxEndpointHandlerMappingRuntimeHints().registerHints(runtimeHints,
getClass().getClassLoader());
assertThat(RuntimeHintsPredicates.reflection().onMethod(CloudFoundryLinksHandler.class, "links"))
assertThat(RuntimeHintsPredicates.reflection().onMethod(CloudFoundryLinksHandler.class, "links").invoke())
.accepts(runtimeHints);
assertThat(RuntimeHintsPredicates.reflection().onType(Link.class)).accepts(runtimeHints);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2025 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.
Expand Down Expand Up @@ -38,7 +38,7 @@ void shouldRegisterHints() {
RuntimeHints runtimeHints = new RuntimeHints();
new CloudFoundryWebEndpointServletHandlerMappingRuntimeHints().registerHints(runtimeHints,
getClass().getClassLoader());
assertThat(RuntimeHintsPredicates.reflection().onMethod(CloudFoundryLinksHandler.class, "links"))
assertThat(RuntimeHintsPredicates.reflection().onMethod(CloudFoundryLinksHandler.class, "links").invoke())
.accepts(runtimeHints);
assertThat(RuntimeHintsPredicates.reflection().onType(Link.class)).accepts(runtimeHints);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2025 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.
Expand Down Expand Up @@ -37,7 +37,7 @@ class WebFluxEndpointHandlerMappingTests {
void shouldRegisterHints() {
RuntimeHints runtimeHints = new RuntimeHints();
new WebFluxEndpointHandlerMappingRuntimeHints().registerHints(runtimeHints, getClass().getClassLoader());
assertThat(RuntimeHintsPredicates.reflection().onMethod(WebFluxLinksHandler.class, "links"))
assertThat(RuntimeHintsPredicates.reflection().onMethod(WebFluxLinksHandler.class, "links").invoke())
.accepts(runtimeHints);
assertThat(RuntimeHintsPredicates.reflection().onType(Link.class)).accepts(runtimeHints);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2025 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.
Expand Down Expand Up @@ -37,7 +37,7 @@ class WebMvcEndpointHandlerMappingTests {
void shouldRegisterHints() {
RuntimeHints runtimeHints = new RuntimeHints();
new WebMvcEndpointHandlerMappingRuntimeHints().registerHints(runtimeHints, getClass().getClassLoader());
assertThat(RuntimeHintsPredicates.reflection().onMethod(WebMvcLinksHandler.class, "links"))
assertThat(RuntimeHintsPredicates.reflection().onMethod(WebMvcLinksHandler.class, "links").invoke())
.accepts(runtimeHints);
assertThat(RuntimeHintsPredicates.reflection().onType(Link.class)).accepts(runtimeHints);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2025 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.
Expand Down Expand Up @@ -164,13 +164,17 @@ void registersRuntimeHintsForClassesSerializedToJson() {
new ReflectiveRuntimeHintsRegistrar().registerRuntimeHints(runtimeHints, LoggersEndpoint.class);
ReflectionHintsPredicates reflection = RuntimeHintsPredicates.reflection();
assertThat(reflection.onType(LoggerLevelsDescriptor.class)).accepts(runtimeHints);
assertThat(reflection.onMethod(LoggerLevelsDescriptor.class, "getConfiguredLevel")).accepts(runtimeHints);
assertThat(reflection.onMethod(LoggerLevelsDescriptor.class, "getConfiguredLevel").invoke())
.accepts(runtimeHints);
assertThat(reflection.onType(SingleLoggerLevelsDescriptor.class)).accepts(runtimeHints);
assertThat(reflection.onMethod(SingleLoggerLevelsDescriptor.class, "getEffectiveLevel")).accepts(runtimeHints);
assertThat(reflection.onMethod(SingleLoggerLevelsDescriptor.class, "getConfiguredLevel")).accepts(runtimeHints);
assertThat(reflection.onMethod(SingleLoggerLevelsDescriptor.class, "getEffectiveLevel").invoke())
.accepts(runtimeHints);
assertThat(reflection.onMethod(SingleLoggerLevelsDescriptor.class, "getConfiguredLevel").invoke())
.accepts(runtimeHints);
assertThat(reflection.onType(GroupLoggerLevelsDescriptor.class)).accepts(runtimeHints);
assertThat(reflection.onMethod(GroupLoggerLevelsDescriptor.class, "getMembers")).accepts(runtimeHints);
assertThat(reflection.onMethod(GroupLoggerLevelsDescriptor.class, "getConfiguredLevel")).accepts(runtimeHints);
assertThat(reflection.onMethod(GroupLoggerLevelsDescriptor.class, "getMembers").invoke()).accepts(runtimeHints);
assertThat(reflection.onMethod(GroupLoggerLevelsDescriptor.class, "getConfiguredLevel").invoke())
.accepts(runtimeHints);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2025 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.
Expand Down Expand Up @@ -55,7 +55,7 @@ void hazelcastCacheProvider() {
void shouldRegisterHints() {
RuntimeHints runtimeHints = new RuntimeHints();
new HazelcastCacheMeterBinderProviderRuntimeHints().registerHints(runtimeHints, getClass().getClassLoader());
assertThat(RuntimeHintsPredicates.reflection().onMethod(HazelcastCache.class, "getNativeCache"))
assertThat(RuntimeHintsPredicates.reflection().onMethod(HazelcastCache.class, "getNativeCache").invoke())
.accepts(runtimeHints);
assertThat(RuntimeHintsPredicates.reflection().onType(HazelcastCacheMetrics.class)).accepts(runtimeHints);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2025 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.
Expand Down Expand Up @@ -285,10 +285,10 @@ void shouldRegisterHints() {
RuntimeHints hints = new RuntimeHints();
new HttpMessageConvertersAutoConfigurationRuntimeHints().registerHints(hints, getClass().getClassLoader());
assertThat(RuntimeHintsPredicates.reflection().onType(Encoding.class)).accepts(hints);
assertThat(RuntimeHintsPredicates.reflection().onMethod(Encoding.class, "getCharset")).accepts(hints);
assertThat(RuntimeHintsPredicates.reflection().onMethod(Encoding.class, "setCharset")).accepts(hints);
assertThat(RuntimeHintsPredicates.reflection().onMethod(Encoding.class, "isForce")).accepts(hints);
assertThat(RuntimeHintsPredicates.reflection().onMethod(Encoding.class, "setForce")).accepts(hints);
assertThat(RuntimeHintsPredicates.reflection().onMethod(Encoding.class, "getCharset").invoke()).accepts(hints);
assertThat(RuntimeHintsPredicates.reflection().onMethod(Encoding.class, "setCharset").invoke()).accepts(hints);
assertThat(RuntimeHintsPredicates.reflection().onMethod(Encoding.class, "isForce").invoke()).accepts(hints);
assertThat(RuntimeHintsPredicates.reflection().onMethod(Encoding.class, "setForce").invoke()).accepts(hints);
assertThat(RuntimeHintsPredicates.reflection().onMethod(Encoding.class, "shouldForce")).rejects(hints);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2024 the original author or authors.
* Copyright 2012-2025 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.
Expand Down Expand Up @@ -52,11 +52,11 @@ void shouldRegisterHints() {
RuntimeHints hints = new RuntimeHints();
new ApplicationPropertiesRuntimeHints().registerHints(hints, getClass().getClassLoader());
assertThat(RuntimeHintsPredicates.reflection().onType(ApplicationProperties.class)).accepts(hints);
assertThat(RuntimeHintsPredicates.reflection().onMethod(ApplicationProperties.class, "setBannerMode"))
assertThat(RuntimeHintsPredicates.reflection().onMethod(ApplicationProperties.class, "setBannerMode").invoke())
.accepts(hints);
assertThat(RuntimeHintsPredicates.reflection().onMethod(ApplicationProperties.class, "getSources"))
assertThat(RuntimeHintsPredicates.reflection().onMethod(ApplicationProperties.class, "getSources").invoke())
.accepts(hints);
assertThat(RuntimeHintsPredicates.reflection().onMethod(ApplicationProperties.class, "setSources"))
assertThat(RuntimeHintsPredicates.reflection().onMethod(ApplicationProperties.class, "setSources").invoke())
.accepts(hints);
assertThat(RuntimeHintsPredicates.reflection().onMethod(ApplicationProperties.class, "getBannerMode"))
.rejects(hints);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2025 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.
Expand Down Expand Up @@ -38,7 +38,8 @@ void shouldRegisterHints() {
assertThat(RuntimeHintsPredicates.reflection().onType(ConfigDataProperties.class)).accepts(hints);
assertThat(RuntimeHintsPredicates.reflection().onType(ConfigDataLocation.class)).accepts(hints);
assertThat(RuntimeHintsPredicates.reflection().onType(Activate.class)).accepts(hints);
assertThat(RuntimeHintsPredicates.reflection().onMethod(ConfigDataLocation.class, "of")).accepts(hints);
assertThat(RuntimeHintsPredicates.reflection().onMethod(ConfigDataLocation.class, "of").invoke())
.accepts(hints);
}

}

0 comments on commit 46a499b

Please sign in to comment.