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; return null;
} }
@Override
public CodeBlock generateSetBeanInstanceSupplierCode( public CodeBlock generateSetBeanInstanceSupplierCode(
GenerationContext generationContext, GenerationContext generationContext,
BeanRegistrationCode beanRegistrationCode, CodeBlock instanceSupplierCode, BeanRegistrationCode beanRegistrationCode, CodeBlock instanceSupplierCode,

View File

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

View File

@ -371,7 +371,7 @@ class BeanDefinitionPropertiesCodeGeneratorTests {
void attributesWhenSomeFiltered() { void attributesWhenSomeFiltered() {
this.beanDefinition.setAttribute("a", "A"); this.beanDefinition.setAttribute("a", "A");
this.beanDefinition.setAttribute("b", "B"); this.beanDefinition.setAttribute("b", "B");
Predicate<String> attributeFilter = attribute -> "a".equals(attribute); Predicate<String> attributeFilter = "a"::equals;
this.generator = new BeanDefinitionPropertiesCodeGenerator(this.hints, this.generator = new BeanDefinitionPropertiesCodeGenerator(this.hints,
attributeFilter, this.generatedMethods, (name, value) -> null); attributeFilter, this.generatedMethods, (name, value) -> null);
testCompiledResult(this.beanDefinition, (actual, compiled) -> { 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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); beanRegistry.registerSingleton("tb", tb);
assertThat(beanRegistry.getSingleton("tb")).isSameAs(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("tb2")).isSameAs(tb2);
assertThat(beanRegistry.getSingleton("tb")).isSameAs(tb); 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.registerBeanDefinition("testBean4", tbd);
bf.registerResolvableDependency(BeanFactory.class, bf); bf.registerResolvableDependency(BeanFactory.class, bf);
bf.registerResolvableDependency(INestedTestBean.class, (ObjectFactory<Object>) () -> new NestedTestBean()); bf.registerResolvableDependency(INestedTestBean.class, (ObjectFactory<Object>) NestedTestBean::new);
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
org.springframework.beans.factory.config.PropertyPlaceholderConfigurer ppc = new org.springframework.beans.factory.config.PropertyPlaceholderConfigurer(); org.springframework.beans.factory.config.PropertyPlaceholderConfigurer ppc = new org.springframework.beans.factory.config.PropertyPlaceholderConfigurer();

View File

@ -55,6 +55,8 @@ class ConversionServiceFactoryBeanTests {
void createDefaultConversionServiceWithSupplements() { void createDefaultConversionServiceWithSupplements() {
ConversionServiceFactoryBean factory = new ConversionServiceFactoryBean(); ConversionServiceFactoryBean factory = new ConversionServiceFactoryBean();
Set<Object> converters = new HashSet<>(); 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>() { converters.add(new Converter<String, Foo>() {
@Override @Override
public Foo convert(String source) { 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; return this.myself;
} }
@Override
public A isEqualTo(@Nullable Object expected) { public A isEqualTo(@Nullable Object expected) {
if (expected instanceof DynamicFile) { if (expected instanceof DynamicFile) {
return super.isEqualTo(expected); 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 String[] getRoles() { return new String[]{"NONE"}; }
public boolean hasAnyRole(String... roles) { public boolean hasAnyRole(String... roles) {
if (roles == null) return true; if (roles == null) {
return true;
}
String[] myRoles = getRoles(); String[] myRoles = getRoles();
for (int i = 0; i < myRoles.length; i++) { for (String myRole : myRoles) {
for (int j = 0; j < roles.length; j++) { for (String role : roles) {
if (myRoles[i].equals(roles[j])) return true; if (myRole.equals(role)) {
return true;
}
} }
} }
return false; return false;

View File

@ -1796,7 +1796,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
((SpelExpression) expression).compileExpression(); ((SpelExpression) expression).compileExpression();
assertThat(expression.getValue(context, Boolean.class)).isFalse(); assertThat(expression.getValue(context, Boolean.class)).isFalse();
List<String> ls = new ArrayList<String>(); List<String> ls = new ArrayList<>();
ls.add(new String("foo")); ls.add(new String("foo"));
context = new StandardEvaluationContext(ls); context = new StandardEvaluationContext(ls);
expression = parse("get(0) != 'foo'"); expression = parse("get(0) != 'foo'");
@ -1844,7 +1844,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
assertThat(aa.gotComparedTo).isEqualTo(bb); assertThat(aa.gotComparedTo).isEqualTo(bb);
List<String> ls = new ArrayList<String>(); List<String> ls = new ArrayList<>();
ls.add(new String("foo")); ls.add(new String("foo"));
StandardEvaluationContext context = new StandardEvaluationContext(ls); StandardEvaluationContext context = new StandardEvaluationContext(ls);
expression = parse("get(0) == 'foo'"); expression = parse("get(0) == 'foo'");
@ -5109,29 +5109,26 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
private String stringify(Object object) { private String stringify(Object object) {
StringBuilder s = new StringBuilder(); StringBuilder s = new StringBuilder();
if (object instanceof List) { if (object instanceof List<?> list) {
List<?> ls = (List<?>) object; for (Object l: list) {
for (Object l: ls) {
s.append(l); s.append(l);
s.append(' '); s.append(' ');
} }
} }
else if (object instanceof Object[]) { else if (object instanceof Object[] objects) {
Object[] os = (Object[]) object; for (Object o: objects) {
for (Object o: os) {
s.append(o); s.append(o);
s.append(' '); s.append(' ');
} }
} }
else if (object instanceof int[]) { else if (object instanceof int[] ints) {
int[] is = (int[]) object; for (int i: ints) {
for (int i: is) {
s.append(i); s.append(i);
s.append(' '); s.append(' ');
} }
} }
else { else {
s.append(object.toString()); s.append(object);
} }
return s.toString().trim(); 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, 1)).isEqualTo(ABC.B);
assertThat(Array.get(result, 2)).isEqualTo(ABC.C); assertThat(Array.get(result, 2)).isEqualTo(ABC.C);
context.addMethodResolver(new MethodResolver() { context.addMethodResolver((context2, targetObject, name, argumentTypes) -> (context1, target, arguments) -> {
@Override try {
public MethodExecutor resolve(EvaluationContext context, Object targetObject, String name, Method method = XYZ.class.getMethod("values");
List<TypeDescriptor> argumentTypes) throws AccessException { Object value = method.invoke(target, arguments);
return (context1, target, arguments) -> { return new TypedValue(value, new TypeDescriptor(new MethodParameter(method, -1)).narrow(value));
try { }
Method method = XYZ.class.getMethod("values"); catch (Exception ex) {
Object value = method.invoke(target, arguments); throw new AccessException(ex.getMessage(), ex);
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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 ///CLOVER:OFF
public class PlaceOfBirth { public class PlaceOfBirth {
private String city; private String city;
public String Country; public String Country;
@ -29,11 +30,14 @@ public class PlaceOfBirth {
* country - but as it is just a test object, it is ok. * country - but as it is just a test object, it is ok.
*/ */
@Override @Override
public String toString() {return city;} public String toString() {
return city;
}
public String getCity() { public String getCity() {
return city; return city;
} }
public void setCity(String s) { public void setCity(String s) {
this.city = s; this.city = s;
} }
@ -48,11 +52,10 @@ public class PlaceOfBirth {
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (!(o instanceof PlaceOfBirth)) { if (!(o instanceof PlaceOfBirth otherPOB)) {
return false; return false;
} }
PlaceOfBirth oPOB = (PlaceOfBirth)o; return (city.equals(otherPOB.city));
return (city.equals(oPOB.city));
} }
@Override @Override

View File

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