Polishing
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user