Polishing

This commit is contained in:
Sam Brannen 2022-06-01 14:57:16 +02:00
parent d9d45cc0b1
commit bc3b3d01ee
12 changed files with 68 additions and 68 deletions

View File

@ -138,6 +138,7 @@ class DefaultBeanRegistrationCodeFragments extends BeanRegistrationCodeFragments
return null;
}
@Override
public CodeBlock generateSetBeanInstanceSupplierCode(
GenerationContext generationContext,
BeanRegistrationCode beanRegistrationCode, CodeBlock instanceSupplierCode,

View File

@ -196,7 +196,7 @@ class BeanDefinitionMethodGeneratorTests {
RootBeanDefinition beanDefinition,
Predicate<String> attributeFilter) {
return super.generateSetBeanDefinitionPropertiesCode(generationContext,
beanRegistrationCode, beanDefinition, name -> "a".equals(name));
beanRegistrationCode, beanDefinition, "a"::equals);
}
};

View File

@ -371,7 +371,7 @@ class BeanDefinitionPropertiesCodeGeneratorTests {
void attributesWhenSomeFiltered() {
this.beanDefinition.setAttribute("a", "A");
this.beanDefinition.setAttribute("b", "B");
Predicate<String> attributeFilter = attribute -> "a".equals(attribute);
Predicate<String> attributeFilter = "a"::equals;
this.generator = new BeanDefinitionPropertiesCodeGenerator(this.hints,
attributeFilter, this.generatedMethods, (name, value) -> null);
testCompiledResult(this.beanDefinition, (actual, compiled) -> {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2022 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.
@ -38,7 +38,7 @@ public class DefaultSingletonBeanRegistryTests {
beanRegistry.registerSingleton("tb", tb);
assertThat(beanRegistry.getSingleton("tb")).isSameAs(tb);
TestBean tb2 = (TestBean) beanRegistry.getSingleton("tb2", () -> new TestBean());
TestBean tb2 = (TestBean) beanRegistry.getSingleton("tb2", TestBean::new);
assertThat(beanRegistry.getSingleton("tb2")).isSameAs(tb2);
assertThat(beanRegistry.getSingleton("tb")).isSameAs(tb);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2022 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.
@ -214,7 +214,7 @@ public class CommonAnnotationBeanPostProcessorTests {
bf.registerBeanDefinition("testBean4", tbd);
bf.registerResolvableDependency(BeanFactory.class, bf);
bf.registerResolvableDependency(INestedTestBean.class, (ObjectFactory<Object>) () -> new NestedTestBean());
bf.registerResolvableDependency(INestedTestBean.class, (ObjectFactory<Object>) NestedTestBean::new);
@SuppressWarnings("deprecation")
org.springframework.beans.factory.config.PropertyPlaceholderConfigurer ppc = new org.springframework.beans.factory.config.PropertyPlaceholderConfigurer();

View File

@ -55,6 +55,8 @@ class ConversionServiceFactoryBeanTests {
void createDefaultConversionServiceWithSupplements() {
ConversionServiceFactoryBean factory = new ConversionServiceFactoryBean();
Set<Object> converters = new HashSet<>();
// The following String -> Foo Converter cannot be implemented as a lambda
// due to type erasure of the source and target types.
converters.add(new Converter<String, Foo>() {
@Override
public Foo convert(String source) {

View File

@ -49,6 +49,7 @@ public class DynamicFileAssert<A extends DynamicFileAssert<A, F>, F extends Dyna
return this.myself;
}
@Override
public A isEqualTo(@Nullable Object expected) {
if (expected instanceof DynamicFile) {
return super.isEqualTo(expected);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2022 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.
@ -153,11 +153,15 @@ public class ScenariosForSpringSecurityExpressionTests extends AbstractExpressio
public String[] getRoles() { return new String[]{"NONE"}; }
public boolean hasAnyRole(String... roles) {
if (roles == null) return true;
if (roles == null) {
return true;
}
String[] myRoles = getRoles();
for (int i = 0; i < myRoles.length; i++) {
for (int j = 0; j < roles.length; j++) {
if (myRoles[i].equals(roles[j])) return true;
for (String myRole : myRoles) {
for (String role : roles) {
if (myRole.equals(role)) {
return true;
}
}
}
return false;

View File

@ -1796,7 +1796,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
((SpelExpression) expression).compileExpression();
assertThat(expression.getValue(context, Boolean.class)).isFalse();
List<String> ls = new ArrayList<String>();
List<String> ls = new ArrayList<>();
ls.add(new String("foo"));
context = new StandardEvaluationContext(ls);
expression = parse("get(0) != 'foo'");
@ -1844,7 +1844,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
assertThat(aa.gotComparedTo).isEqualTo(bb);
List<String> ls = new ArrayList<String>();
List<String> ls = new ArrayList<>();
ls.add(new String("foo"));
StandardEvaluationContext context = new StandardEvaluationContext(ls);
expression = parse("get(0) == 'foo'");
@ -5109,29 +5109,26 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
private String stringify(Object object) {
StringBuilder s = new StringBuilder();
if (object instanceof List) {
List<?> ls = (List<?>) object;
for (Object l: ls) {
if (object instanceof List<?> list) {
for (Object l: list) {
s.append(l);
s.append(' ');
}
}
else if (object instanceof Object[]) {
Object[] os = (Object[]) object;
for (Object o: os) {
else if (object instanceof Object[] objects) {
for (Object o: objects) {
s.append(o);
s.append(' ');
}
}
else if (object instanceof int[]) {
int[] is = (int[]) object;
for (int i: is) {
else if (object instanceof int[] ints) {
for (int i: ints) {
s.append(i);
s.append(' ');
}
}
else {
s.append(object.toString());
s.append(object);
}
return s.toString().trim();
}

View File

@ -1321,20 +1321,14 @@ class SpelReproTests extends AbstractExpressionTests {
assertThat(Array.get(result, 1)).isEqualTo(ABC.B);
assertThat(Array.get(result, 2)).isEqualTo(ABC.C);
context.addMethodResolver(new MethodResolver() {
@Override
public MethodExecutor resolve(EvaluationContext context, Object targetObject, String name,
List<TypeDescriptor> argumentTypes) throws AccessException {
return (context1, target, arguments) -> {
try {
Method method = XYZ.class.getMethod("values");
Object value = method.invoke(target, arguments);
return new TypedValue(value, new TypeDescriptor(new MethodParameter(method, -1)).narrow(value));
}
catch (Exception ex) {
throw new AccessException(ex.getMessage(), ex);
}
};
context.addMethodResolver((context2, targetObject, name, argumentTypes) -> (context1, target, arguments) -> {
try {
Method method = XYZ.class.getMethod("values");
Object value = method.invoke(target, arguments);
return new TypedValue(value, new TypeDescriptor(new MethodParameter(method, -1)).narrow(value));
}
catch (Exception ex) {
throw new AccessException(ex.getMessage(), ex);
}
});

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2022 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.
@ -18,6 +18,7 @@ package org.springframework.expression.spel.testresources;
///CLOVER:OFF
public class PlaceOfBirth {
private String city;
public String Country;
@ -29,11 +30,14 @@ public class PlaceOfBirth {
* country - but as it is just a test object, it is ok.
*/
@Override
public String toString() {return city;}
public String toString() {
return city;
}
public String getCity() {
return city;
}
public void setCity(String s) {
this.city = s;
}
@ -48,11 +52,10 @@ public class PlaceOfBirth {
@Override
public boolean equals(Object o) {
if (!(o instanceof PlaceOfBirth)) {
if (!(o instanceof PlaceOfBirth otherPOB)) {
return false;
}
PlaceOfBirth oPOB = (PlaceOfBirth)o;
return (city.equals(oPOB.city));
return (city.equals(otherPOB.city));
}
@Override

View File

@ -209,32 +209,30 @@ public class R2dbcTransactionManager extends AbstractReactiveTransactionManager
connectionMono = Mono.just(txObject.getConnectionHolder().getConnection());
}
return connectionMono.flatMap(con -> {
return prepareTransactionalConnection(con, definition, transaction)
.then(Mono.from(doBegin(definition, con)))
.doOnSuccess(v -> {
txObject.getConnectionHolder().setTransactionActive(true);
Duration timeout = determineTimeout(definition);
if (!timeout.isNegative() && !timeout.isZero()) {
txObject.getConnectionHolder().setTimeoutInMillis(timeout.toMillis());
}
// Bind the connection holder to the thread.
if (txObject.isNewConnectionHolder()) {
synchronizationManager.bindResource(obtainConnectionFactory(), txObject.getConnectionHolder());
}
}).thenReturn(con).onErrorResume(e -> {
if (txObject.isNewConnectionHolder()) {
return ConnectionFactoryUtils.releaseConnection(con, obtainConnectionFactory())
.doOnTerminate(() -> txObject.setConnectionHolder(null, false))
.then(Mono.error(e));
}
return Mono.error(e);
});
}).onErrorResume(e -> {
CannotCreateTransactionException ex = new CannotCreateTransactionException(
"Could not open R2DBC Connection for transaction", e);
return Mono.error(ex);
});
return connectionMono.flatMap(con -> prepareTransactionalConnection(con, definition, transaction)
.then(Mono.from(doBegin(definition, con)))
.doOnSuccess(v -> {
txObject.getConnectionHolder().setTransactionActive(true);
Duration timeout = determineTimeout(definition);
if (!timeout.isNegative() && !timeout.isZero()) {
txObject.getConnectionHolder().setTimeoutInMillis(timeout.toMillis());
}
// Bind the connection holder to the thread.
if (txObject.isNewConnectionHolder()) {
synchronizationManager.bindResource(obtainConnectionFactory(), txObject.getConnectionHolder());
}
}).thenReturn(con).onErrorResume(e -> {
if (txObject.isNewConnectionHolder()) {
return ConnectionFactoryUtils.releaseConnection(con, obtainConnectionFactory())
.doOnTerminate(() -> txObject.setConnectionHolder(null, false))
.then(Mono.error(e));
}
return Mono.error(e);
})).onErrorResume(e -> {
CannotCreateTransactionException ex = new CannotCreateTransactionException(
"Could not open R2DBC Connection for transaction", e);
return Mono.error(ex);
});
}).then();
}