Simplify some redundant code

Closes gh-24586

Co-authored-by: Sam Brannen <sbrannen@pivotal.io>
This commit is contained in:
ZhangT 2020-02-26 19:29:09 +08:00 committed by GitHub
parent 0ad942f337
commit c5fb7b9fb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 9 additions and 19 deletions

View File

@ -162,8 +162,7 @@ public class ConstructorInvocationTests extends AbstractExpressionTests {
ctx.addConstructorResolver(dummy); ctx.addConstructorResolver(dummy);
assertThat(ctx.getConstructorResolvers().size()).isEqualTo(2); assertThat(ctx.getConstructorResolvers().size()).isEqualTo(2);
List<ConstructorResolver> copy = new ArrayList<>(); List<ConstructorResolver> copy = new ArrayList<>(ctx.getConstructorResolvers());
copy.addAll(ctx.getConstructorResolvers());
assertThat(ctx.removeConstructorResolver(dummy)).isTrue(); assertThat(ctx.removeConstructorResolver(dummy)).isTrue();
assertThat(ctx.removeConstructorResolver(dummy)).isFalse(); assertThat(ctx.removeConstructorResolver(dummy)).isFalse();
assertThat(ctx.getConstructorResolvers().size()).isEqualTo(1); assertThat(ctx.getConstructorResolvers().size()).isEqualTo(1);

View File

@ -96,8 +96,7 @@ public class ExpressionLanguageScenarioTests extends AbstractExpressionTests {
// Use the standard evaluation context // Use the standard evaluation context
StandardEvaluationContext ctx = new StandardEvaluationContext(); StandardEvaluationContext ctx = new StandardEvaluationContext();
ctx.setVariable("favouriteColour","blue"); ctx.setVariable("favouriteColour","blue");
List<Integer> primes = new ArrayList<>(); List<Integer> primes = Arrays.asList(2, 3, 5, 7, 11, 13, 17);
primes.addAll(Arrays.asList(2,3,5,7,11,13,17));
ctx.setVariable("primes",primes); ctx.setVariable("primes",primes);
Expression expr = parser.parseRaw("#favouriteColour"); Expression expr = parser.parseRaw("#favouriteColour");

View File

@ -221,8 +221,7 @@ public class MethodInvocationTests extends AbstractExpressionTests {
ctx.addMethodResolver(dummy); ctx.addMethodResolver(dummy);
assertThat(ctx.getMethodResolvers().size()).isEqualTo(2); assertThat(ctx.getMethodResolvers().size()).isEqualTo(2);
List<MethodResolver> copy = new ArrayList<>(); List<MethodResolver> copy = new ArrayList<>(ctx.getMethodResolvers());
copy.addAll(ctx.getMethodResolvers());
assertThat(ctx.removeMethodResolver(dummy)).isTrue(); assertThat(ctx.removeMethodResolver(dummy)).isTrue();
assertThat(ctx.removeMethodResolver(dummy)).isFalse(); assertThat(ctx.removeMethodResolver(dummy)).isFalse();
assertThat(ctx.getMethodResolvers().size()).isEqualTo(1); assertThat(ctx.getMethodResolvers().size()).isEqualTo(1);

View File

@ -135,8 +135,7 @@ public class PropertyAccessTests extends AbstractExpressionTests {
ctx.addPropertyAccessor(spa); ctx.addPropertyAccessor(spa);
assertThat(ctx.getPropertyAccessors().size()).isEqualTo(2); assertThat(ctx.getPropertyAccessors().size()).isEqualTo(2);
List<PropertyAccessor> copy = new ArrayList<>(); List<PropertyAccessor> copy = new ArrayList<>(ctx.getPropertyAccessors());
copy.addAll(ctx.getPropertyAccessors());
assertThat(ctx.removePropertyAccessor(spa)).isTrue(); assertThat(ctx.removePropertyAccessor(spa)).isTrue();
assertThat(ctx.removePropertyAccessor(spa)).isFalse(); assertThat(ctx.removePropertyAccessor(spa)).isFalse();
assertThat(ctx.getPropertyAccessors().size()).isEqualTo(1); assertThat(ctx.getPropertyAccessors().size()).isEqualTo(1);

View File

@ -420,8 +420,7 @@ public class SpelDocumentationTests extends AbstractExpressionTests {
@Test @Test
public void testSpecialVariables() throws Exception { public void testSpecialVariables() throws Exception {
// create an array of integers // create an array of integers
List<Integer> primes = new ArrayList<>(); List<Integer> primes = Arrays.asList(2, 3, 5, 7, 11, 13, 17);
primes.addAll(Arrays.asList(2,3,5,7,11,13,17));
// create parser and set variable 'primes' as the array of integers // create parser and set variable 'primes' as the array of integers
ExpressionParser parser = new SpelExpressionParser(); ExpressionParser parser = new SpelExpressionParser();
@ -518,4 +517,3 @@ public class SpelDocumentationTests extends AbstractExpressionTests {
} }
} }

View File

@ -205,8 +205,7 @@ public class MethodMessageHandlerTests {
@Override @Override
protected List<? extends HandlerMethodReturnValueHandler> initReturnValueHandlers() { protected List<? extends HandlerMethodReturnValueHandler> initReturnValueHandlers() {
List<HandlerMethodReturnValueHandler> handlers = new ArrayList<>(); List<HandlerMethodReturnValueHandler> handlers = new ArrayList<>(getCustomReturnValueHandlers());
handlers.addAll(getCustomReturnValueHandlers());
return handlers; return handlers;
} }

View File

@ -240,8 +240,7 @@ public abstract class ExtendedEntityManagerCreator {
} }
else { else {
interfaces = cachedEntityManagerInterfaces.computeIfAbsent(rawEm.getClass(), key -> { interfaces = cachedEntityManagerInterfaces.computeIfAbsent(rawEm.getClass(), key -> {
Set<Class<?>> ifcs = new LinkedHashSet<>(); Set<Class<?>> ifcs = new LinkedHashSet<>(ClassUtils
ifcs.addAll(ClassUtils
.getAllInterfacesForClassAsSet(key, cl)); .getAllInterfacesForClassAsSet(key, cl));
ifcs.add(EntityManagerProxy.class); ifcs.add(EntityManagerProxy.class);
return ClassUtils.toClassArray(ifcs); return ClassUtils.toClassArray(ifcs);

View File

@ -227,8 +227,7 @@ public class ProtobufDecoder extends ProtobufCodecSupport implements Decoder<Mes
this.output = input.factory().allocateBuffer(this.messageBytesToRead); this.output = input.factory().allocateBuffer(this.messageBytesToRead);
} }
chunkBytesToRead = this.messageBytesToRead >= input.readableByteCount() ? chunkBytesToRead = Math.min(this.messageBytesToRead, input.readableByteCount());
input.readableByteCount() : this.messageBytesToRead;
remainingBytesToRead = input.readableByteCount() - chunkBytesToRead; remainingBytesToRead = input.readableByteCount() - chunkBytesToRead;
byte[] bytesToWrite = new byte[chunkBytesToRead]; byte[] bytesToWrite = new byte[chunkBytesToRead];

View File

@ -320,8 +320,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
assertThat(response.getStatus()).as("Invalid response status").isEqualTo(HttpServletResponse.SC_METHOD_NOT_ALLOWED); assertThat(response.getStatus()).as("Invalid response status").isEqualTo(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
String allowHeader = response.getHeader("Allow"); String allowHeader = response.getHeader("Allow");
assertThat(allowHeader).as("No Allow header").isNotNull(); assertThat(allowHeader).as("No Allow header").isNotNull();
Set<String> allowedMethods = new HashSet<>(); Set<String> allowedMethods = new HashSet<>(Arrays.asList(StringUtils.delimitedListToStringArray(allowHeader, ", ")));
allowedMethods.addAll(Arrays.asList(StringUtils.delimitedListToStringArray(allowHeader, ", ")));
assertThat(allowedMethods.size()).as("Invalid amount of supported methods").isEqualTo(6); assertThat(allowedMethods.size()).as("Invalid amount of supported methods").isEqualTo(6);
assertThat(allowedMethods.contains("PUT")).as("PUT not allowed").isTrue(); assertThat(allowedMethods.contains("PUT")).as("PUT not allowed").isTrue();
assertThat(allowedMethods.contains("DELETE")).as("DELETE not allowed").isTrue(); assertThat(allowedMethods.contains("DELETE")).as("DELETE not allowed").isTrue();