Introduce Checkstyle rule for separator symbol location

This commit is contained in:
Sam Brannen
2025-03-19 15:35:35 +01:00
parent 18c3b637e4
commit 208d52d852
97 changed files with 378 additions and 403 deletions

View File

@@ -102,8 +102,8 @@ public class DefaultMethodReference implements MethodReference {
TypeName argumentType = argumentTypes[i];
CodeBlock argumentCode = argumentCodeGenerator.generateCode(argumentType);
if (argumentCode == null) {
throw new IllegalArgumentException("Could not generate code for " + this
+ ": parameter " + i + " of type " + argumentType + " is not supported");
throw new IllegalArgumentException("Could not generate code for " + this +
": parameter " + i + " of type " + argumentType + " is not supported");
}
arguments.add(argumentCode);
}

View File

@@ -192,9 +192,9 @@ public interface GeneratedFiles {
private static void validatePackage(String packageName, String className) {
if (!StringUtils.hasLength(packageName)) {
throw new IllegalArgumentException("Could not add '" + className + "', "
+ "processing classes in the default package is not supported. "
+ "Did you forget to add a package statement?");
throw new IllegalArgumentException("Could not add '" + className + "', " +
"processing classes in the default package is not supported. " +
"Did you forget to add a package statement?");
}
}

View File

@@ -240,8 +240,8 @@ public abstract class ValueCodeGeneratorDelegates {
if (escaped != null) {
return escaped;
}
return (!Character.isISOControl(ch)) ? Character.toString(ch)
: String.format("\\u%04x", (int) ch);
return (!Character.isISOControl(ch)) ? Character.toString(ch) :
String.format("\\u%04x", (int) ch);
}
}

View File

@@ -108,8 +108,8 @@ public class BindingReflectionHintsRegistrar {
registerPropertyHints(hints, seen, method, 0);
}
else if ((methodName.startsWith("get") && method.getParameterCount() == 0 && method.getReturnType() != void.class) ||
(methodName.startsWith("is") && method.getParameterCount() == 0
&& ClassUtils.resolvePrimitiveIfNecessary(method.getReturnType()) == Boolean.class)) {
(methodName.startsWith("is") && method.getParameterCount() == 0 &&
ClassUtils.resolvePrimitiveIfNecessary(method.getReturnType()) == Boolean.class)) {
registerPropertyHints(hints, seen, method, -1);
}
}

View File

@@ -375,8 +375,8 @@ final class TypeMappedAnnotation<A extends Annotation> extends AbstractMergedAnn
private Object getRequiredValue(int attributeIndex, String attributeName) {
Object value = getValue(attributeIndex, Object.class);
if (value == null) {
throw new NoSuchElementException("No element at attribute index "
+ attributeIndex + " for name " + attributeName);
throw new NoSuchElementException("No element at attribute index " +
attributeIndex + " for name " + attributeName);
}
return value;
}

View File

@@ -71,8 +71,8 @@ public class ResourceRegionEncoder extends AbstractEncoder<ResourceRegion> {
@Override
public boolean canEncode(ResolvableType elementType, @Nullable MimeType mimeType) {
return super.canEncode(elementType, mimeType)
&& ResourceRegion.class.isAssignableFrom(elementType.toClass());
return super.canEncode(elementType, mimeType) &&
ResourceRegion.class.isAssignableFrom(elementType.toClass());
}
@Override

View File

@@ -472,8 +472,8 @@ public class SpringFactoriesLoader {
private static <T> void makeAccessible(Constructor<T> constructor,
KFunction<T> kotlinConstructor) {
if ((!Modifier.isPublic(constructor.getModifiers())
|| !Modifier.isPublic(constructor.getDeclaringClass().getModifiers()))) {
if ((!Modifier.isPublic(constructor.getModifiers()) ||
!Modifier.isPublic(constructor.getDeclaringClass().getModifiers()))) {
KCallablesJvm.setAccessible(kotlinConstructor, true);
}
}

View File

@@ -275,8 +275,8 @@ public class AntPathMatcher implements PathMatcher {
if (!matchStrings(pattDir, pathDirs[pathIdxEnd], uriTemplateVariables)) {
return false;
}
if (pattIdxEnd == (pattDirs.length - 1)
&& pattern.endsWith(this.pathSeparator) != path.endsWith(this.pathSeparator)) {
if (pattIdxEnd == (pattDirs.length - 1) &&
pattern.endsWith(this.pathSeparator) != path.endsWith(this.pathSeparator)) {
return false;
}
pattIdxEnd--;

View File

@@ -557,9 +557,7 @@ public final class ConcurrentLruCache<K, V> {
}
private boolean contains(Node<K, V> e) {
return (e.getPrevious() != null)
|| (e.getNext() != null)
|| (e == this.first);
return (e.getPrevious() != null) || (e.getNext() != null) || (e == this.first);
}
private void linkLast(final Node<K, V> e) {

View File

@@ -71,8 +71,8 @@ class GeneratedFilesTests {
TypeSpec helloWorld = TypeSpec.classBuilder("HelloWorld").build();
JavaFile javaFile = JavaFile.builder("", helloWorld).build();
assertThatIllegalArgumentException().isThrownBy(() -> this.generatedFiles.addSourceFile(javaFile))
.withMessage("Could not add 'HelloWorld', processing classes in the "
+ "default package is not supported. Did you forget to add a package statement?");
.withMessage("Could not add 'HelloWorld', processing classes in the " +
"default package is not supported. Did you forget to add a package statement?");
}
@Test
@@ -92,8 +92,8 @@ class GeneratedFilesTests {
void addSourceFileWithCharSequenceWhenClassNameIsInTheDefaultPackageThrowsException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> this.generatedFiles.addSourceFile("HelloWorld", "{}"))
.withMessage("Could not add 'HelloWorld', processing classes in the "
+ "default package is not supported. Did you forget to add a package statement?");
.withMessage("Could not add 'HelloWorld', processing classes in the " +
"default package is not supported. Did you forget to add a package statement?");
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-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.
@@ -64,20 +64,17 @@ import static org.mockito.Mockito.verifyNoInteractions;
*/
class ValueCodeGeneratorTests {
@Nested
class ConfigurationTests {
@Test
void createWithListOfDelegatesInvokeThemInOrder() {
Delegate first = mock(Delegate.class);
Delegate second = mock(Delegate.class);
Delegate third = mock(Delegate.class);
ValueCodeGenerator codeGenerator = ValueCodeGenerator
.with(List.of(first, second, third));
Delegate first = mock();
Delegate second = mock();
Delegate third = mock();
ValueCodeGenerator codeGenerator = ValueCodeGenerator.with(List.of(first, second, third));
Object value = "";
given(third.generateCode(codeGenerator, value))
.willReturn(CodeBlock.of("test"));
given(third.generateCode(codeGenerator, value)).willReturn(CodeBlock.of("test"));
CodeBlock code = codeGenerator.generateCode(value);
assertThat(code).hasToString("test");
InOrder ordered = inOrder(first, second, third);
@@ -88,13 +85,11 @@ class ValueCodeGeneratorTests {
@Test
void generateCodeWithMatchingDelegateStops() {
Delegate first = mock(Delegate.class);
Delegate second = mock(Delegate.class);
ValueCodeGenerator codeGenerator = ValueCodeGenerator
.with(List.of(first, second));
Delegate first = mock();
Delegate second = mock();
ValueCodeGenerator codeGenerator = ValueCodeGenerator.with(List.of(first, second));
Object value = "";
given(first.generateCode(codeGenerator, value))
.willReturn(CodeBlock.of("test"));
given(first.generateCode(codeGenerator, value)).willReturn(CodeBlock.of("test"));
CodeBlock code = codeGenerator.generateCode(value);
assertThat(code).hasToString("test");
verify(first).generateCode(codeGenerator, value);
@@ -198,7 +193,6 @@ class ValueCodeGeneratorTests {
assertThat(generateCode("test")).hasToString("\"test\"");
}
@Test
void generateWhenStringWithCarriageReturn() {
assertThat(generateCode("test\n")).isEqualTo(CodeBlock.of("$S", "test\n"));
@@ -285,9 +279,9 @@ class ValueCodeGeneratorTests {
ResolvableType resolvableType = ResolvableType.forClassWithGenerics(Map.class,
ResolvableType.forClass(Integer.class), stringList);
assertThat(resolve(generateCode(resolvableType)))
.hasImport(ResolvableType.class, List.class, Map.class).hasValueCode(
"ResolvableType.forClassWithGenerics(Map.class, ResolvableType.forClass(Integer.class), "
+ "ResolvableType.forClassWithGenerics(List.class, String.class))");
.hasImport(ResolvableType.class, List.class, Map.class).hasValueCode("""
ResolvableType.forClassWithGenerics(Map.class, ResolvableType.forClass(Integer.class), \
ResolvableType.forClassWithGenerics(List.class, String.class))""");
}
@Test

View File

@@ -216,10 +216,10 @@ class ReflectionHintsTests {
typeHint -> typeHint.withMembers(MemberCategory.INTROSPECT_PUBLIC_METHODS));
assertThat(this.reflectionHints.typeHints()).hasSize(2)
.noneMatch(typeHint -> typeHint.getType().getCanonicalName().equals(Serializable.class.getCanonicalName()))
.anyMatch(typeHint -> typeHint.getType().getCanonicalName().equals(SecondInterface.class.getCanonicalName())
&& typeHint.getMemberCategories().contains(MemberCategory.INTROSPECT_PUBLIC_METHODS))
.anyMatch(typeHint -> typeHint.getType().getCanonicalName().equals(FirstInterface.class.getCanonicalName())
&& typeHint.getMemberCategories().contains(MemberCategory.INTROSPECT_PUBLIC_METHODS));
.anyMatch(typeHint -> typeHint.getType().getCanonicalName().equals(SecondInterface.class.getCanonicalName()) &&
typeHint.getMemberCategories().contains(MemberCategory.INTROSPECT_PUBLIC_METHODS))
.anyMatch(typeHint -> typeHint.getType().getCanonicalName().equals(FirstInterface.class.getCanonicalName()) &&
typeHint.getMemberCategories().contains(MemberCategory.INTROSPECT_PUBLIC_METHODS));
}
private void assertTestTypeMethodHints(Consumer<ExecutableHint> methodHint) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-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.
@@ -54,27 +54,24 @@ class AnnotationTypeMappingsTests {
AnnotationTypeMappings mappings = AnnotationTypeMappings.forAnnotationType(SimpleAnnotation.class);
assertThat(mappings.size()).isEqualTo(1);
assertThat(mappings.get(0).getAnnotationType()).isEqualTo(SimpleAnnotation.class);
assertThat(getAll(mappings)).flatExtracting(
AnnotationTypeMapping::getAnnotationType).containsExactly(SimpleAnnotation.class);
assertThat(getAll(mappings)).flatExtracting(AnnotationTypeMapping::getAnnotationType)
.containsExactly(SimpleAnnotation.class);
}
@Test
void forAnnotationTypeWhenMetaAnnotationsReturnsMappings() {
AnnotationTypeMappings mappings = AnnotationTypeMappings.forAnnotationType(MetaAnnotated.class);
assertThat(mappings.size()).isEqualTo(6);
assertThat(getAll(mappings)).flatExtracting(
AnnotationTypeMapping::getAnnotationType).containsExactly(
MetaAnnotated.class, A.class, B.class, AA.class, AB.class,
ABC.class);
assertThat(getAll(mappings)).flatExtracting(AnnotationTypeMapping::getAnnotationType)
.containsExactly(MetaAnnotated.class, A.class, B.class, AA.class, AB.class, ABC.class);
}
@Test
void forAnnotationTypeWhenHasRepeatingMetaAnnotationReturnsMapping() {
AnnotationTypeMappings mappings = AnnotationTypeMappings.forAnnotationType(WithRepeatedMetaAnnotations.class);
assertThat(mappings.size()).isEqualTo(3);
assertThat(getAll(mappings)).flatExtracting(
AnnotationTypeMapping::getAnnotationType).containsExactly(
WithRepeatedMetaAnnotations.class, Repeating.class, Repeating.class);
assertThat(getAll(mappings)).flatExtracting(AnnotationTypeMapping::getAnnotationType)
.containsExactly(WithRepeatedMetaAnnotations.class, Repeating.class, Repeating.class);
}
@Test
@@ -89,56 +86,52 @@ class AnnotationTypeMappingsTests {
void forAnnotationTypeWhenSelfAnnotatedReturnsMapping() {
AnnotationTypeMappings mappings = AnnotationTypeMappings.forAnnotationType(SelfAnnotated.class);
assertThat(mappings.size()).isEqualTo(1);
assertThat(getAll(mappings)).flatExtracting(
AnnotationTypeMapping::getAnnotationType).containsExactly(SelfAnnotated.class);
assertThat(getAll(mappings)).flatExtracting(AnnotationTypeMapping::getAnnotationType)
.containsExactly(SelfAnnotated.class);
}
@Test
void forAnnotationTypeWhenFormsLoopReturnsMapping() {
AnnotationTypeMappings mappings = AnnotationTypeMappings.forAnnotationType(LoopA.class);
assertThat(mappings.size()).isEqualTo(2);
assertThat(getAll(mappings)).flatExtracting(
AnnotationTypeMapping::getAnnotationType).containsExactly(LoopA.class, LoopB.class);
assertThat(getAll(mappings)).flatExtracting(AnnotationTypeMapping::getAnnotationType)
.containsExactly(LoopA.class, LoopB.class);
}
@Test
void forAnnotationTypeWhenHasAliasForWithBothValueAndAttributeThrowsException() {
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
AnnotationTypeMappings.forAnnotationType(AliasForWithBothValueAndAttribute.class))
.withMessage("In @AliasFor declared on attribute 'test' in annotation ["
+ AliasForWithBothValueAndAttribute.class.getName()
+ "], attribute 'attribute' and its alias 'value' are present with values of 'foo' and 'bar', but only one is permitted.");
assertThatExceptionOfType(AnnotationConfigurationException.class)
.isThrownBy(() -> AnnotationTypeMappings.forAnnotationType(AliasForWithBothValueAndAttribute.class))
.withMessage("In @AliasFor declared on attribute 'test' in annotation [%s], attribute 'attribute' " +
"and its alias 'value' are present with values of 'foo' and 'bar', but only one is permitted.",
AliasForWithBothValueAndAttribute.class.getName());
}
@Test
void forAnnotationTypeWhenAliasForToSelfNonExistingAttribute() {
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
AnnotationTypeMappings.forAnnotationType(AliasForToSelfNonExistingAttribute.class))
.withMessage("@AliasFor declaration on attribute 'test' in annotation ["
+ AliasForToSelfNonExistingAttribute.class.getName()
+ "] declares an alias for 'missing' which is not present.");
assertThatExceptionOfType(AnnotationConfigurationException.class)
.isThrownBy(() -> AnnotationTypeMappings.forAnnotationType(AliasForToSelfNonExistingAttribute.class))
.withMessage("@AliasFor declaration on attribute 'test' in annotation [%s] " +
"declares an alias for 'missing' which is not present.",
AliasForToSelfNonExistingAttribute.class.getName());
}
@Test
void forAnnotationTypeWhenAliasForToOtherNonExistingAttribute() {
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
AnnotationTypeMappings.forAnnotationType(AliasForToOtherNonExistingAttribute.class))
.withMessage("Attribute 'test' in annotation ["
+ AliasForToOtherNonExistingAttribute.class.getName()
+ "] is declared as an @AliasFor nonexistent "
+ "attribute 'missing' in annotation ["
+ AliasForToOtherNonExistingAttributeTarget.class.getName()
+ "].");
assertThatExceptionOfType(AnnotationConfigurationException.class)
.isThrownBy(() -> AnnotationTypeMappings.forAnnotationType(AliasForToOtherNonExistingAttribute.class))
.withMessage("Attribute 'test' in annotation [%s] is declared as an @AliasFor nonexistent " +
"attribute 'missing' in annotation [%s].", AliasForToOtherNonExistingAttribute.class.getName(),
AliasForToOtherNonExistingAttributeTarget.class.getName());
}
@Test
void forAnnotationTypeWhenAliasForToSelf() {
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
AnnotationTypeMappings.forAnnotationType(AliasForToSelf.class))
.withMessage("@AliasFor declaration on attribute 'test' in annotation ["
+ AliasForToSelf.class.getName()
+ "] points to itself. Specify 'annotation' to point to "
+ "a same-named attribute on a meta-annotation.");
assertThatExceptionOfType(AnnotationConfigurationException.class)
.isThrownBy(() -> AnnotationTypeMappings.forAnnotationType(AliasForToSelf.class))
.withMessage("@AliasFor declaration on attribute 'test' in annotation [%s] points to itself. " +
"Specify 'annotation' to point to a same-named attribute on a meta-annotation.",
AliasForToSelf.class.getName());
}
@Test
@@ -152,13 +145,12 @@ class AnnotationTypeMappingsTests {
@Test
void forAnnotationTypeWhenAliasForWithIncompatibleReturnTypes() {
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
AnnotationTypeMappings.forAnnotationType(AliasForWithIncompatibleReturnTypes.class))
.withMessage("Misconfigured aliases: attribute 'test' in annotation ["
+ AliasForWithIncompatibleReturnTypes.class.getName()
+ "] and attribute 'test' in annotation ["
+ AliasForWithIncompatibleReturnTypesTarget.class.getName()
+ "] must declare the same return type.");
assertThatExceptionOfType(AnnotationConfigurationException.class)
.isThrownBy(() -> AnnotationTypeMappings.forAnnotationType(AliasForWithIncompatibleReturnTypes.class))
.withMessage("Misconfigured aliases: attribute 'test' in annotation [%s] and attribute 'test' " +
"in annotation [%s] must declare the same return type.",
AliasForWithIncompatibleReturnTypes.class.getName(),
AliasForWithIncompatibleReturnTypesTarget.class.getName());
}
@Test
@@ -166,9 +158,8 @@ class AnnotationTypeMappingsTests {
String annotationType = AliasForToSelfAnnotatedToOtherAttribute.class.getName();
assertThatExceptionOfType(AnnotationConfigurationException.class)
.isThrownBy(() -> AnnotationTypeMappings.forAnnotationType(AliasForToSelfAnnotatedToOtherAttribute.class))
.withMessage("Attribute 'b' in annotation [" + annotationType
+ "] must be declared as an @AliasFor attribute 'a' in annotation [" + annotationType
+ "], not attribute 'c' in annotation [" + annotationType + "].");
.withMessage("Attribute 'b' in annotation [%1$s] must be declared as an @AliasFor attribute 'a' in " +
"annotation [%1$s], not attribute 'c' in annotation [%1$s].", annotationType);
}
@Test
@@ -182,53 +173,45 @@ class AnnotationTypeMappingsTests {
String metaAnnotationName = AliasPair.class.getName();
assertThatExceptionOfType(AnnotationConfigurationException.class)
.isThrownBy(() -> AnnotationTypeMappings.forAnnotationType(annotationType))
.withMessage("Attribute 'b' in annotation [" + annotationName
+ "] must be declared as an @AliasFor attribute 'a' in annotation [" + annotationName
+ "], not attribute '" + overriddenAttribute + "' in annotation [" + metaAnnotationName + "].");
.withMessage("Attribute 'b' in annotation [" + annotationName +
"] must be declared as an @AliasFor attribute 'a' in annotation [" + annotationName +
"], not attribute '" + overriddenAttribute + "' in annotation [" + metaAnnotationName + "].");
}
@Test
void forAnnotationTypeWhenAliasForNonMetaAnnotated() {
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
AnnotationTypeMappings.forAnnotationType(AliasForNonMetaAnnotated.class))
.withMessage("@AliasFor declaration on attribute 'test' in annotation ["
+ AliasForNonMetaAnnotated.class.getName()
+ "] declares an alias for attribute 'test' in annotation ["
+ AliasForNonMetaAnnotatedTarget.class.getName()
+ "] which is not meta-present.");
assertThatExceptionOfType(AnnotationConfigurationException.class)
.isThrownBy(() -> AnnotationTypeMappings.forAnnotationType(AliasForNonMetaAnnotated.class))
.withMessage("@AliasFor declaration on attribute 'test' in annotation [" + AliasForNonMetaAnnotated.class.getName() +
"] declares an alias for attribute 'test' in annotation [" + AliasForNonMetaAnnotatedTarget.class.getName() +
"] which is not meta-present.");
}
@Test
void forAnnotationTypeWhenAliasForSelfWithDifferentDefaults() {
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
AnnotationTypeMappings.forAnnotationType(AliasForSelfWithDifferentDefaults.class))
.withMessage("Misconfigured aliases: attribute 'a' in annotation ["
+ AliasForSelfWithDifferentDefaults.class.getName()
+ "] and attribute 'b' in annotation ["
+ AliasForSelfWithDifferentDefaults.class.getName()
+ "] must declare the same default value.");
assertThatExceptionOfType(AnnotationConfigurationException.class)
.isThrownBy(() -> AnnotationTypeMappings.forAnnotationType(AliasForSelfWithDifferentDefaults.class))
.withMessage("Misconfigured aliases: attribute 'a' in annotation [" + AliasForSelfWithDifferentDefaults.class.getName() +
"] and attribute 'b' in annotation [" + AliasForSelfWithDifferentDefaults.class.getName() +
"] must declare the same default value.");
}
@Test
void forAnnotationTypeWhenAliasForSelfWithMissingDefault() {
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
AnnotationTypeMappings.forAnnotationType(AliasForSelfWithMissingDefault.class))
.withMessage("Misconfigured aliases: attribute 'a' in annotation ["
+ AliasForSelfWithMissingDefault.class.getName()
+ "] and attribute 'b' in annotation ["
+ AliasForSelfWithMissingDefault.class.getName()
+ "] must declare default values.");
assertThatExceptionOfType(AnnotationConfigurationException.class)
.isThrownBy(() -> AnnotationTypeMappings.forAnnotationType(AliasForSelfWithMissingDefault.class))
.withMessage("Misconfigured aliases: attribute 'a' in annotation [" + AliasForSelfWithMissingDefault.class.getName() +
"] and attribute 'b' in annotation [" + AliasForSelfWithMissingDefault.class.getName() +
"] must declare default values.");
}
@Test
void forAnnotationTypeWhenAliasWithExplicitMirrorAndDifferentDefaults() {
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
AnnotationTypeMappings.forAnnotationType(AliasWithExplicitMirrorAndDifferentDefaults.class))
.withMessage("Misconfigured aliases: attribute 'a' in annotation ["
+ AliasWithExplicitMirrorAndDifferentDefaults.class.getName()
+ "] and attribute 'c' in annotation ["
+ AliasWithExplicitMirrorAndDifferentDefaults.class.getName()
+ "] must declare the same default value.");
assertThatExceptionOfType(AnnotationConfigurationException.class)
.isThrownBy(() -> AnnotationTypeMappings.forAnnotationType(AliasWithExplicitMirrorAndDifferentDefaults.class))
.withMessage("Misconfigured aliases: attribute 'a' in annotation [" + AliasWithExplicitMirrorAndDifferentDefaults.class.getName() +
"] and attribute 'c' in annotation [" + AliasWithExplicitMirrorAndDifferentDefaults.class.getName() +
"] must declare the same default value.");
}
@Test
@@ -375,18 +358,16 @@ class AnnotationTypeMappingsTests {
@Test
void resolveMirrorsWhenHasDifferentValuesThrowsException() {
AnnotationTypeMapping mapping = AnnotationTypeMappings.forAnnotationType(AliasPair.class).get(0);
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
resolveMirrorSets(mapping, WithDifferentValueAliasPair.class, AliasPair.class))
.withMessage("Different @AliasFor mirror values for annotation ["
+ AliasPair.class.getName() + "] declared on "
+ WithDifferentValueAliasPair.class.getName()
+ "; attribute 'a' and its alias 'b' are declared with values of [test1] and [test2].");
assertThatExceptionOfType(AnnotationConfigurationException.class)
.isThrownBy(() -> resolveMirrorSets(mapping, WithDifferentValueAliasPair.class, AliasPair.class))
.withMessage("Different @AliasFor mirror values for annotation [" + AliasPair.class.getName() + "] declared on " +
WithDifferentValueAliasPair.class.getName() +
"; attribute 'a' and its alias 'b' are declared with values of [test1] and [test2].");
}
@Test
void resolveMirrorsWhenHasWithMultipleRoutesToAliasReturnsMirrors() {
AnnotationTypeMappings mappings = AnnotationTypeMappings.forAnnotationType(
MultipleRoutesToAliasA.class);
AnnotationTypeMappings mappings = AnnotationTypeMappings.forAnnotationType(MultipleRoutesToAliasA.class);
AnnotationTypeMapping mappingsA = getMapping(mappings, MultipleRoutesToAliasA.class);
assertThat(mappingsA.getMirrorSets().size()).isZero();
AnnotationTypeMapping mappingsB = getMapping(mappings, MultipleRoutesToAliasB.class);
@@ -397,8 +378,7 @@ class AnnotationTypeMappingsTests {
@Test
void getAliasMappingWhenHasWithMultipleRoutesToAliasReturnsMappedAttributes() {
AnnotationTypeMappings mappings = AnnotationTypeMappings.forAnnotationType(
MultipleRoutesToAliasA.class);
AnnotationTypeMappings mappings = AnnotationTypeMappings.forAnnotationType(MultipleRoutesToAliasA.class);
AnnotationTypeMapping mappingsA = getMapping(mappings, MultipleRoutesToAliasA.class);
assertThat(getAliasMapping(mappingsA, 0)).isNull();
AnnotationTypeMapping mappingsB = getMapping(mappings, MultipleRoutesToAliasB.class);

View File

@@ -925,8 +925,8 @@ class AnnotationUtilsTests {
Map<String, Object> map = Collections.singletonMap(VALUE, 42L);
assertThatIllegalStateException().isThrownBy(() ->
synthesizeAnnotation(map, Component.class, null).value())
.withMessageContaining("Attribute 'value' in annotation org.springframework.core.testfixture.stereotype.Component "
+ "should be compatible with java.lang.String but a java.lang.Long value was returned");
.withMessageContaining("Attribute 'value' in annotation org.springframework.core.testfixture.stereotype.Component " +
"should be compatible with java.lang.String but a java.lang.Long value was returned");
}
@Test

View File

@@ -120,9 +120,7 @@ class MergedAnnotationClassLoaderTests {
@Override
protected boolean isEligibleForOverriding(String className) {
return WITH_TEST_ANNOTATION.equals(className)
|| TEST_ANNOTATION.equals(className)
|| TEST_REFERENCE.equals(className);
return WITH_TEST_ANNOTATION.equals(className) || TEST_ANNOTATION.equals(className) || TEST_REFERENCE.equals(className);
}
}

View File

@@ -171,8 +171,7 @@ class MergedAnnotationsCollectionTests {
void getWithSelectorReturnsSelected() {
MergedAnnotations annotations = getMultiRoute1();
MergedAnnotationSelector<MultiRouteTarget> deepest = (existing,
candidate) -> candidate.getDistance() > existing.getDistance() ? candidate
: existing;
candidate) -> candidate.getDistance() > existing.getDistance() ? candidate : existing;
assertThat(annotations.get(MultiRouteTarget.class, null, deepest).getString(
MergedAnnotation.VALUE)).isEqualTo("111");
}

View File

@@ -99,8 +99,8 @@ class SpringFactoriesLoaderTests {
void loadWhenIncompatibleTypeThrowsException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> SpringFactoriesLoader.forDefaultResourceLocation().load(String.class))
.withMessageContaining("Unable to instantiate factory class "
+ "[org.springframework.core.io.support.MyDummyFactory1] for factory type [java.lang.String]");
.withMessageContaining("Unable to instantiate factory class " +
"[org.springframework.core.io.support.MyDummyFactory1] for factory type [java.lang.String]");
}
@Test
@@ -127,8 +127,8 @@ class SpringFactoriesLoaderTests {
assertThatIllegalArgumentException()
.isThrownBy(() -> SpringFactoriesLoader.forDefaultResourceLocation(LimitedClassLoader.multipleArgumentFactories)
.load(DummyFactory.class, resolver))
.withMessageContaining("Unable to instantiate factory class "
+ "[org.springframework.core.io.support.MultipleConstructorArgsDummyFactory] for factory type [org.springframework.core.io.support.DummyFactory]")
.withMessageContaining("Unable to instantiate factory class " +
"[org.springframework.core.io.support.MultipleConstructorArgsDummyFactory] for factory type [org.springframework.core.io.support.DummyFactory]")
.havingRootCause().withMessageContaining("Class [org.springframework.core.io.support.MultipleConstructorArgsDummyFactory] has no suitable constructor");
}

View File

@@ -218,8 +218,8 @@ abstract class AbstractStaxXMLReaderTests {
@Override
public Object[] adaptArguments(Object[] arguments) {
if (arguments.length == 3 && arguments[0] instanceof char[]
&& arguments[1] instanceof Integer && arguments[2] instanceof Integer) {
if (arguments.length == 3 && arguments[0] instanceof char[] &&
arguments[1] instanceof Integer && arguments[2] instanceof Integer) {
return new Object[] {new String((char[]) arguments[0], (Integer) arguments[1], (Integer) arguments[2])};
}
return arguments;
@@ -271,10 +271,10 @@ abstract class AbstractStaxXMLReaderTests {
for (int i = 0; i < other.getLength(); i++) {
boolean found = false;
for (int j = 0; j < attributes.getLength(); j++) {
if (other.getURI(i).equals(attributes.getURI(j))
&& other.getQName(i).equals(attributes.getQName(j))
&& other.getType(i).equals(attributes.getType(j))
&& other.getValue(i).equals(attributes.getValue(j))) {
if (other.getURI(i).equals(attributes.getURI(j)) &&
other.getQName(i).equals(attributes.getQName(j)) &&
other.getType(i).equals(attributes.getType(j)) &&
other.getValue(i).equals(attributes.getValue(j))) {
found = true;
break;
}