Skip to content

Commit

Permalink
Polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoeller committed Nov 16, 2023
1 parent c187846 commit e5f04e5
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,20 @@
*/
class AspectJBeanFactoryInitializationAotProcessor implements BeanFactoryInitializationAotProcessor {

private static final boolean aspectJPresent = ClassUtils.isPresent(
"org.aspectj.lang.annotation.Pointcut", AspectJBeanFactoryInitializationAotProcessor.class.getClassLoader());
private static final boolean aspectJPresent = ClassUtils.isPresent("org.aspectj.lang.annotation.Pointcut",
AspectJBeanFactoryInitializationAotProcessor.class.getClassLoader());


@Nullable
@Override
@Nullable
public BeanFactoryInitializationAotContribution processAheadOfTime(ConfigurableListableBeanFactory beanFactory) {
if (aspectJPresent) {
return AspectDelegate.processAheadOfTime(beanFactory);
}
return null;
}


/**
* Inner class to avoid a hard dependency on AspectJ at runtime.
*/
Expand All @@ -61,9 +63,8 @@ private static class AspectDelegate {
private static AspectContribution processAheadOfTime(ConfigurableListableBeanFactory beanFactory) {
BeanFactoryAspectJAdvisorsBuilder builder = new BeanFactoryAspectJAdvisorsBuilder(beanFactory);
List<Advisor> advisors = builder.buildAspectJAdvisors();
return advisors.isEmpty() ? null : new AspectContribution(advisors);
return (advisors.isEmpty() ? null : new AspectContribution(advisors));
}

}


Expand All @@ -84,7 +85,6 @@ public void applyTo(GenerationContext generationContext, BeanFactoryInitializati
}
}
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,10 @@ public static final class Builder {

private final List<String> fileExtensions = new ArrayList<>();


private Builder() {
// no-op
}


/**
* Consider the specified classpath locations.
* <p>A location can either be a special {@value ResourceUtils#CLASSPATH_URL_PREFIX}
Expand Down Expand Up @@ -254,7 +252,6 @@ private FilePatternResourceHintsRegistrar build() {
public void registerHints(ResourceHints hints, @Nullable ClassLoader classLoader) {
build().registerHints(hints, classLoader);
}

}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 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 @@ -51,8 +51,7 @@ public final class CharSequenceEncoder extends AbstractEncoder<CharSequence> {
*/
public static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;

private final ConcurrentMap<Charset, Float> charsetToMaxBytesPerChar =
new ConcurrentHashMap<>(3);
private final ConcurrentMap<Charset, Float> charsetToMaxBytesPerChar = new ConcurrentHashMap<>(3);


private CharSequenceEncoder(MimeType... mimeTypes) {
Expand Down Expand Up @@ -105,8 +104,8 @@ public DataBuffer encodeValue(CharSequence charSequence, DataBufferFactory buffe
}

int calculateCapacity(CharSequence sequence, Charset charset) {
float maxBytesPerChar = this.charsetToMaxBytesPerChar
.computeIfAbsent(charset, cs -> cs.newEncoder().maxBytesPerChar());
float maxBytesPerChar = this.charsetToMaxBytesPerChar.computeIfAbsent(charset,
cs -> cs.newEncoder().maxBytesPerChar());
float maxBytesForSequence = sequence.length() * maxBytesPerChar;
return (int) Math.ceil(maxBytesForSequence);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ void relativeResourcesAreEqual() throws Exception {
Resource relative = resource.createRelative("subdir");
assertThat(relative).isEqualTo(new ClassPathResource("dir/subdir"));
}

}


@Nested
class GetInputStream {

Expand Down Expand Up @@ -151,9 +151,9 @@ private static void assertExceptionContainsAbsolutePath(ClassPathResource resour
.isThrownBy(resource::getInputStream)
.withMessageContaining(ABSOLUTE_PATH_TO_NONEXISTENT_RESOURCE);
}

}


@Nested
class GetDescription {

Expand Down Expand Up @@ -190,9 +190,9 @@ void withClassLoaderConstructorAndLeadingSlash() {
private static void assertDescription(ClassPathResource resource) {
assertThat(resource.getDescription()).isEqualTo("class path resource [%s]", ABSOLUTE_PATH_TO_NONEXISTENT_RESOURCE);
}

}


@Nested
class GetPath {

Expand All @@ -209,9 +209,9 @@ void convertsToAbsolutePathForClassRelativeAccess() {
assertThat(((ClassPathResource) new ClassPathResource("", getClass()).createRelative("/test.html")).getPath()).isEqualTo("test.html");
assertThat(((ClassPathResource) new ClassPathResource("", getClass()).createRelative("test.html")).getPath()).isEqualTo(PACKAGE_PATH + "/test.html");
}

}


@Test
void directoryNotReadable() throws Exception {
Resource fileDir = new ClassPathResource("org/springframework/core");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ void hasDescription() {
Resource resource = new ByteArrayResource("testString".getBytes(), "my description");
assertThat(resource.getDescription().contains("my description")).isTrue();
}

}


@Nested
class InputStreamResourceTests {

Expand Down Expand Up @@ -215,6 +215,7 @@ void hasDescription() {
}
}


@Nested
class FileSystemResourceTests {

Expand Down Expand Up @@ -286,6 +287,7 @@ private void assertUrlAndUriBehavior(Resource resource) throws IOException {
}
}


@Nested
class UrlResourceTests {

Expand Down Expand Up @@ -421,6 +423,7 @@ public MockResponse dispatch(RecordedRequest request) throws InterruptedExceptio
}
}


@Nested
class AbstractResourceTests {

Expand Down Expand Up @@ -467,7 +470,6 @@ public String getDescription() {
};
assertThat(resource.contentLength()).isEqualTo(3L);
}

}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 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 @@ -39,6 +39,7 @@ public DataBufferFactory createDataBufferFactory() {
}
}


@Nested
class UnpooledByteBufAllocatorWithPreferDirectFalseTests implements PooledDataBufferTestingTrait {

Expand All @@ -48,6 +49,7 @@ public DataBufferFactory createDataBufferFactory() {
}
}


@Nested
class PooledByteBufAllocatorWithPreferDirectTrueTests implements PooledDataBufferTestingTrait {

Expand All @@ -57,6 +59,7 @@ public DataBufferFactory createDataBufferFactory() {
}
}


@Nested
class PooledByteBufAllocatorWithPreferDirectFalseTests implements PooledDataBufferTestingTrait {

Expand All @@ -66,6 +69,7 @@ public DataBufferFactory createDataBufferFactory() {
}
}


interface PooledDataBufferTestingTrait {

DataBufferFactory createDataBufferFactory();
Expand All @@ -92,7 +96,6 @@ default void tooManyReleases() {
buffer.release();
assertThatIllegalStateException().isThrownBy(buffer::release);
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ class PropertySourceProcessorTests {
private static final String PROPS_FILE = ClassUtils.classPackageAsResourcePath(PropertySourceProcessorTests.class) + "/test.properties";

private final StandardEnvironment environment = new StandardEnvironment();

private final ResourceLoader resourceLoader = new DefaultResourceLoader();

private final PropertySourceProcessor processor = new PropertySourceProcessor(environment, resourceLoader);


Expand All @@ -59,12 +61,14 @@ void checkInitialPropertySources() {

@Test
void processorRegistersPropertySource() throws Exception {
PropertySourceDescriptor descriptor = new PropertySourceDescriptor(List.of(PROPS_FILE), false, null, DefaultPropertySourceFactory.class, null);
PropertySourceDescriptor descriptor = new PropertySourceDescriptor(
List.of(PROPS_FILE), false, null, DefaultPropertySourceFactory.class, null);
processor.processPropertySource(descriptor);
assertThat(environment.getPropertySources()).hasSize(3);
assertThat(environment.getProperty("enigma")).isEqualTo("42");
}


@Nested
class FailOnErrorTests {

Expand All @@ -86,9 +90,9 @@ private void assertProcessorFailsOnError(
assertThatExceptionOfType(exceptionType).isThrownBy(() -> processor.processPropertySource(descriptor));
assertThat(environment.getPropertySources()).hasSize(2);
}

}


@Nested
class IgnoreResourceNotFoundTests {

Expand Down Expand Up @@ -127,7 +131,6 @@ private void assertProcessorIgnoresFailure(Class<? extends PropertySourceFactory
assertThatNoException().isThrownBy(() -> processor.processPropertySource(descriptor));
assertThat(environment.getPropertySources()).hasSize(2);
}

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ void handleMessageReturnsHandlerThatAcceptsMessage() {
assertThat(messages).hasSize(1);
assertThat(messages.get(0)).startsWith("Unable to instantiate factory class");
}

}


Expand Down Expand Up @@ -292,9 +291,9 @@ void andResolverReturnsComposite() {
assertThat(resolver.resolve(Integer.class)).isEqualTo(123);
assertThat(resolver.resolve(Long.class)).isEqualTo(234L);
}

}


@Nested
class FactoryInstantiatorTests {

Expand Down Expand Up @@ -350,14 +349,12 @@ void multiplePackagePrivateConstructorsThrowsException() {
}

static class DefaultConstructor {

}

static class SingleConstructor {

SingleConstructor(String arg) {
}

}

static class MultiplePrivateAndSinglePublicConstructor {
Expand All @@ -368,7 +365,6 @@ public MultiplePrivateAndSinglePublicConstructor(String arg) {

private MultiplePrivateAndSinglePublicConstructor(String arg, boolean extra) {
}

}

static class MultiplePackagePrivateAndSinglePublicConstructor {
Expand All @@ -379,22 +375,18 @@ public MultiplePackagePrivateAndSinglePublicConstructor(String arg) {

MultiplePackagePrivateAndSinglePublicConstructor(String arg, boolean extra) {
}

}


static class SinglePackagePrivateConstructor {

SinglePackagePrivateConstructor(String arg) {
}

}

static class SinglePrivateConstructor {

private SinglePrivateConstructor(String arg) {
}

}

static class MultiplePackagePrivateConstructors {
Expand All @@ -405,11 +397,10 @@ static class MultiplePackagePrivateConstructors {

MultiplePackagePrivateConstructors(String arg, boolean extra) {
}

}

}


private static class LimitedClassLoader extends URLClassLoader {

private static final ClassLoader constructorArgumentFactories = new LimitedClassLoader("constructor-argument-factories");
Expand All @@ -428,7 +419,6 @@ private static URL toUrl(String location) {
throw new IllegalStateException(ex);
}
}

}

}

0 comments on commit e5f04e5

Please sign in to comment.