Polishing
This commit is contained in:
parent
d9d45cc0b1
commit
bc3b3d01ee
|
@ -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,
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -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) -> {
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1321,11 +1321,7 @@ 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
|
|
||||||
public MethodExecutor resolve(EvaluationContext context, Object targetObject, String name,
|
|
||||||
List<TypeDescriptor> argumentTypes) throws AccessException {
|
|
||||||
return (context1, target, arguments) -> {
|
|
||||||
try {
|
try {
|
||||||
Method method = XYZ.class.getMethod("values");
|
Method method = XYZ.class.getMethod("values");
|
||||||
Object value = method.invoke(target, arguments);
|
Object value = method.invoke(target, arguments);
|
||||||
|
@ -1334,8 +1330,6 @@ class SpelReproTests extends AbstractExpressionTests {
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
throw new AccessException(ex.getMessage(), ex);
|
throw new AccessException(ex.getMessage(), ex);
|
||||||
}
|
}
|
||||||
};
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
result = spel.getValue(context);
|
result = spel.getValue(context);
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -209,8 +209,7 @@ 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);
|
||||||
|
@ -229,8 +228,7 @@ public class R2dbcTransactionManager extends AbstractReactiveTransactionManager
|
||||||
.then(Mono.error(e));
|
.then(Mono.error(e));
|
||||||
}
|
}
|
||||||
return Mono.error(e);
|
return Mono.error(e);
|
||||||
});
|
})).onErrorResume(e -> {
|
||||||
}).onErrorResume(e -> {
|
|
||||||
CannotCreateTransactionException ex = new CannotCreateTransactionException(
|
CannotCreateTransactionException ex = new CannotCreateTransactionException(
|
||||||
"Could not open R2DBC Connection for transaction", e);
|
"Could not open R2DBC Connection for transaction", e);
|
||||||
return Mono.error(ex);
|
return Mono.error(ex);
|
||||||
|
|
Loading…
Reference in New Issue