Skip to content

Polish #46785

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Polish #46785

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void setup(@TempDir Path projectDir) {
@Test
void whenPackagesAreTangledTaskFailsAndWritesAReport() throws IOException {
runGradleWithCompiledClasses("tangled",
shouldHaveFailureReportWithMessage("slices matching '(**)' should be free of cycles"));
shouldHaveFailureReportWithMessages("slices matching '(**)' should be free of cycles"));
}

@Test
Expand All @@ -67,15 +67,15 @@ void whenPackagesAreNotTangledTaskSucceedsAndWritesAnEmptyReport() throws IOExce
@Test
void whenBeanPostProcessorBeanMethodIsNotStaticTaskFailsAndWritesAReport() throws IOException {
runGradleWithCompiledClasses("bpp/nonstatic",
shouldHaveFailureReportWithMessage(
shouldHaveFailureReportWithMessages(
"methods that are annotated with @Bean and have raw return type assignable "
+ "to org.springframework.beans.factory.config.BeanPostProcessor"));
}

@Test
void whenBeanPostProcessorBeanMethodIsStaticAndHasUnsafeParametersTaskFailsAndWritesAReport() throws IOException {
runGradleWithCompiledClasses("bpp/unsafeparameters",
shouldHaveFailureReportWithMessage(
shouldHaveFailureReportWithMessages(
"methods that are annotated with @Bean and have raw return type assignable "
+ "to org.springframework.beans.factory.config.BeanPostProcessor"));
}
Expand All @@ -95,14 +95,14 @@ void whenBeanPostProcessorBeanMethodIsStaticAndHasNoParametersTaskSucceedsAndWri
@Test
void whenBeanFactoryPostProcessorBeanMethodIsNotStaticTaskFailsAndWritesAReport() throws IOException {
runGradleWithCompiledClasses("bfpp/nonstatic",
shouldHaveFailureReportWithMessage("methods that are annotated with @Bean and have raw return "
shouldHaveFailureReportWithMessages("methods that are annotated with @Bean and have raw return "
+ "type assignable to org.springframework.beans.factory.config.BeanFactoryPostProcessor"));
}

@Test
void whenBeanFactoryPostProcessorBeanMethodIsStaticAndHasParametersTaskFailsAndWritesAReport() throws IOException {
runGradleWithCompiledClasses("bfpp/parameters",
shouldHaveFailureReportWithMessage("methods that are annotated with @Bean and have raw return "
shouldHaveFailureReportWithMessages("methods that are annotated with @Bean and have raw return "
+ "type assignable to org.springframework.beans.factory.config.BeanFactoryPostProcessor"));
}

Expand All @@ -114,7 +114,7 @@ void whenBeanFactoryPostProcessorBeanMethodIsStaticAndHasNoParametersTaskSucceed

@Test
void whenClassLoadsResourceUsingResourceUtilsTaskFailsAndWritesReport() throws IOException {
runGradleWithCompiledClasses("resources/loads", shouldHaveFailureReportWithMessage(
runGradleWithCompiledClasses("resources/loads", shouldHaveFailureReportWithMessages(
"no classes should call method where target owner type org.springframework.util.ResourceUtils and target name 'getURL'"));
}

Expand All @@ -130,26 +130,26 @@ void whenClassDoesNotCallObjectsRequireNonNullTaskSucceedsAndWritesAnEmptyReport

@Test
void whenClassCallsObjectsRequireNonNullWithMessageTaskFailsAndWritesReport() throws IOException {
runGradleWithCompiledClasses("objects/requireNonNullWithString", shouldHaveFailureReportWithMessage(
runGradleWithCompiledClasses("objects/requireNonNullWithString", shouldHaveFailureReportWithMessages(
"no classes should call method Objects.requireNonNull(Object, String)"));
}

@Test
void whenClassCallsObjectsRequireNonNullWithSupplierTaskFailsAndWritesReport() throws IOException {
runGradleWithCompiledClasses("objects/requireNonNullWithSupplier", shouldHaveFailureReportWithMessage(
runGradleWithCompiledClasses("objects/requireNonNullWithSupplier", shouldHaveFailureReportWithMessages(
"no classes should call method Objects.requireNonNull(Object, Supplier)"));
}

@Test
void whenClassCallsStringToUpperCaseWithoutLocaleFailsAndWritesReport() throws IOException {
runGradleWithCompiledClasses("string/toUpperCase",
shouldHaveFailureReportWithMessage("because String.toUpperCase(Locale.ROOT) should be used instead"));
shouldHaveFailureReportWithMessages("because String.toUpperCase(Locale.ROOT) should be used instead"));
}

@Test
void whenClassCallsStringToLowerCaseWithoutLocaleFailsAndWritesReport() throws IOException {
runGradleWithCompiledClasses("string/toLowerCase",
shouldHaveFailureReportWithMessage("because String.toLowerCase(Locale.ROOT) should be used instead"));
shouldHaveFailureReportWithMessages("because String.toLowerCase(Locale.ROOT) should be used instead"));
}

@Test
Expand All @@ -164,7 +164,7 @@ void whenClassCallsStringToUpperCaseWithLocaleShouldNotFail() throws IOException

@Test
void whenBeanMethodExposePrivateTypeShouldFailAndWriteReport() throws IOException {
runGradleWithCompiledClasses("beans/privatebean", shouldHaveFailureReportWithMessage(
runGradleWithCompiledClasses("beans/privatebean", shouldHaveFailureReportWithMessages(
"methods that are annotated with @Bean should not return types declared with the PRIVATE modifier,"
+ " as such types are incompatible with Spring AOT processing",
"Method <org.springframework.boot.build.architecture.beans.privatebean.PrivateBean.myBean()> "
Expand All @@ -173,7 +173,7 @@ void whenBeanMethodExposePrivateTypeShouldFailAndWriteReport() throws IOExceptio
}

@Test
void whenBeanMethodExposeNonPrivateTypeeShouldNotFail() throws IOException {
void whenBeanMethodExposeNonPrivateTypeShouldNotFail() throws IOException {
runGradleWithCompiledClasses("beans/regular", shouldHaveEmptyFailureReport());
}

Expand Down Expand Up @@ -207,7 +207,7 @@ IntegrationMBeanExporter integrationMBeanExporter() {
}
}
""");
runGradle(shouldHaveFailureReportWithMessage("methods that are annotated with @Bean and have raw return "
runGradle(shouldHaveFailureReportWithMessages("methods that are annotated with @Bean and have raw return "
+ "type assignable to org.springframework.beans.factory.config.BeanPostProcessor "));
}

Expand All @@ -224,7 +224,7 @@ private Consumer<GradleRunner> shouldHaveEmptyFailureReport() {
};
}

private Consumer<GradleRunner> shouldHaveFailureReportWithMessage(String... messages) {
private Consumer<GradleRunner> shouldHaveFailureReportWithMessages(String... messages) {
return (gradleRunner) -> {
assertThat(gradleRunner.buildAndFail().getOutput()).contains("BUILD FAILED")
.contains("Task :checkArchitectureMain FAILED");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class MyApplication {
private val logger: Log = LogFactory.getLog(MyApplication::class.java)

@RequestMapping("/")
fun hello(): String {
fun home(): String {
logger.info("home() has been called")
return "Hello, World!"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import java.util.HexFormat;

/**
* Utility to decode URL strings. Copied frm Spring Framework's {@code StringUtils} as we
* Utility to decode URL strings. Copied from Spring Framework's {@code StringUtils} as we
* cannot depend on it in the loader.
*
* @author Phillip Webb
Expand Down Expand Up @@ -52,6 +52,7 @@ public static String decode(String source) {
* @param charset the character encoding to use to decode the "<i>{@code %xy}</i>"
* sequences
* @return the decoded value
* @since 4.0.0
*/
public static String decode(String source, Charset charset) {
int length = source.length();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.util.ReflectionTestUtils;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -70,8 +69,7 @@ void shouldAutoConfigureMeterTagAnnotationHandlerWhenValueExpressionResolverIsAv
this.contextRunner.withBean(ValueExpressionResolver.class, () -> mock(ValueExpressionResolver.class))
.run((context) -> {
assertThat(context).hasSingleBean(TimedAspect.class).hasSingleBean(MeterTagAnnotationHandler.class);
assertThat(
ReflectionTestUtils.getField(context.getBean(TimedAspect.class), "meterTagAnnotationHandler"))
assertThat(context.getBean(TimedAspect.class)).extracting("meterTagAnnotationHandler")
.isSameAs(context.getBean(MeterTagAnnotationHandler.class));
});
}
Expand All @@ -83,8 +81,7 @@ void shouldUseUserDefinedMeterTagAnnotationHandler() {
() -> new MeterTagAnnotationHandler(null, null))
.run((context) -> {
assertThat(context).hasSingleBean(TimedAspect.class).hasSingleBean(MeterTagAnnotationHandler.class);
assertThat(
ReflectionTestUtils.getField(context.getBean(TimedAspect.class), "meterTagAnnotationHandler"))
assertThat(context.getBean(TimedAspect.class)).extracting("meterTagAnnotationHandler")
.isSameAs(context.getBean("customMeterTagAnnotationHandler"));
});
}
Expand All @@ -95,8 +92,7 @@ void shouldAutoConfigureCountedMeterTagAnnotationHandlerWhenValueExpressionResol
.run((context) -> {
assertThat(context).hasSingleBean(CountedAspect.class)
.hasSingleBean(CountedMeterTagAnnotationHandler.class);
assertThat(
ReflectionTestUtils.getField(context.getBean(CountedAspect.class), "meterTagAnnotationHandler"))
assertThat(context.getBean(CountedAspect.class)).extracting("meterTagAnnotationHandler")
.isSameAs(context.getBean(CountedMeterTagAnnotationHandler.class));
});
}
Expand All @@ -109,8 +105,7 @@ void shouldUseUserDefinedCountedMeterTagAnnotationHandler() {
.run((context) -> {
assertThat(context).hasSingleBean(CountedAspect.class)
.hasSingleBean(CountedMeterTagAnnotationHandler.class);
assertThat(
ReflectionTestUtils.getField(context.getBean(CountedAspect.class), "meterTagAnnotationHandler"))
assertThat(context.getBean(CountedAspect.class)).extracting("meterTagAnnotationHandler")
.isSameAs(context.getBean(CountedMeterTagAnnotationHandler.class));
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void whenPropertiesMetricTypePrefixIsSetAdapterMetricTypePrefixReturnsIt() {
}

@Test
void whenPropertiesAutoCreateMetricDescriptorsIsSetAdapterAutoCreateMetricDescriptorReturnsIt() {
void whenPropertiesAutoCreateMetricDescriptorsIsSetAdapterAutoCreateMetricDescriptorsReturnsIt() {
StackdriverProperties properties = new StackdriverProperties();
properties.setAutoCreateMetricDescriptors(false);
assertThat(new StackdriverPropertiesConfigAdapter(properties).autoCreateMetricDescriptors()).isFalse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import io.micrometer.tracing.Tracer;
import io.micrometer.tracing.handler.TracingAwareMeterObservationHandler;
import io.micrometer.tracing.handler.TracingObservationHandler;
import org.assertj.core.extractor.Extractors;
import org.assertj.core.api.InstanceOfAssertFactories;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;

Expand Down Expand Up @@ -63,7 +63,6 @@ void isMemberAcceptsMeterObservationHandlerOrTracingObservationHandler() {
}

@Test
@SuppressWarnings("unchecked")
void registerMembersWrapsMeterObservationHandlersAndRegistersDistinctGroups() {
Tracer tracer = mock(Tracer.class);
TracingAndMeterObservationHandlerGroup group = new TracingAndMeterObservationHandlerGroup(tracer);
Expand All @@ -79,16 +78,14 @@ void registerMembersWrapsMeterObservationHandlersAndRegistersDistinctGroups() {
List<ObservationHandler<?>> actualComposites = handlerCaptor.getAllValues();
assertThat(actualComposites).hasSize(2);
ObservationHandler<?> tracingComposite = actualComposites.get(0);
assertThat(tracingComposite).isInstanceOf(FirstMatchingCompositeObservationHandler.class);
List<ObservationHandler<?>> tracingHandlers = (List<ObservationHandler<?>>) Extractors.byName("handlers")
.apply(tracingComposite);
assertThat(tracingHandlers).containsExactly(tracingHandler1, tracingHandler2);
assertThat(tracingComposite).isInstanceOf(FirstMatchingCompositeObservationHandler.class)
.extracting("handlers", InstanceOfAssertFactories.LIST)
.containsExactly(tracingHandler1, tracingHandler2);
ObservationHandler<?> metricsComposite = actualComposites.get(1);
assertThat(metricsComposite).isInstanceOf(FirstMatchingCompositeObservationHandler.class);
List<ObservationHandler<?>> metricsHandlers = (List<ObservationHandler<?>>) Extractors.byName("handlers")
.apply(metricsComposite);
assertThat(metricsHandlers).hasSize(2);
assertThat(metricsHandlers).extracting("delegate").containsExactly(meterHandler1, meterHandler2);
assertThat(metricsComposite).isInstanceOf(FirstMatchingCompositeObservationHandler.class)
.extracting("handlers", InstanceOfAssertFactories.LIST)
.extracting("delegate")
.containsExactly(meterHandler1, meterHandler2);
}

@Test
Expand Down