Polishing

This commit is contained in:
Juergen Hoeller
2017-05-23 22:05:22 +02:00
parent db69a082d9
commit 0183576215
7 changed files with 74 additions and 71 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2017 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.
@@ -27,8 +27,7 @@ import static org.junit.Assert.*;
/**
* Unit tests for the {@link AspectJAdviceParameterNameDiscoverer} class.
*
* <p>See also {@link TigerAspectJAdviceParameterNameDiscovererTests} in
* the 'tiger' tree for tests relating to annotations.
* <p>See also {@link TigerAspectJAdviceParameterNameDiscovererTests} for tests relating to annotations.
*
* @author Adrian Colyer
* @author Chris Beams
@@ -83,27 +82,28 @@ public class AspectJAdviceParameterNameDiscovererTests {
@Test
public void testJoinPointOnly() {
assertParameterNames(getMethod("tjp"), "execution(* *(..))", new String[]{"thisJoinPoint"});
assertParameterNames(getMethod("tjp"), "execution(* *(..))", new String[] {"thisJoinPoint"});
}
@Test
public void testJoinPointStaticPartOnly() {
assertParameterNames(getMethod("tjpsp"), "execution(* *(..))", new String[]{"thisJoinPointStaticPart"});
assertParameterNames(getMethod("tjpsp"), "execution(* *(..))", new String[] {"thisJoinPointStaticPart"});
}
@Test
public void testTwoJoinPoints() {
assertException(getMethod("twoJoinPoints"), "foo()", IllegalStateException.class, "Failed to bind all argument names: 1 argument(s) could not be bound");
assertException(getMethod("twoJoinPoints"), "foo()", IllegalStateException.class,
"Failed to bind all argument names: 1 argument(s) could not be bound");
}
@Test
public void testOneThrowable() {
assertParameterNames(getMethod("oneThrowable"), "foo()", null, "ex", new String[]{"ex"});
assertParameterNames(getMethod("oneThrowable"), "foo()", null, "ex", new String[] {"ex"});
}
@Test
public void testOneJPAndOneThrowable() {
assertParameterNames(getMethod("jpAndOneThrowable"), "foo()", null, "ex", new String[]{"thisJoinPoint", "ex"});
assertParameterNames(getMethod("jpAndOneThrowable"), "foo()", null, "ex", new String[] {"thisJoinPoint", "ex"});
}
@Test
@@ -120,7 +120,7 @@ public class AspectJAdviceParameterNameDiscovererTests {
@Test
public void testReturning() {
assertParameterNames(getMethod("oneObject"), "foo()", "obj", null, new String[]{"obj"});
assertParameterNames(getMethod("oneObject"), "foo()", "obj", null, new String[] {"obj"});
}
@Test
@@ -137,16 +137,16 @@ public class AspectJAdviceParameterNameDiscovererTests {
@Test
public void testThisBindingOneCandidate() {
assertParameterNames(getMethod("oneObject"), "this(x)", new String[]{"x"});
assertParameterNames(getMethod("oneObject"), "this(x)", new String[] {"x"});
}
@Test
public void testThisBindingWithAlternateTokenizations() {
assertParameterNames(getMethod("oneObject"), "this( x )", new String[]{"x"});
assertParameterNames(getMethod("oneObject"), "this( x)", new String[]{"x"});
assertParameterNames(getMethod("oneObject"), "this (x )", new String[]{"x"});
assertParameterNames(getMethod("oneObject"), "this(x )", new String[]{"x"});
assertParameterNames(getMethod("oneObject"), "foo() && this(x)", new String[]{"x"});
assertParameterNames(getMethod("oneObject"), "this( x )", new String[] {"x"});
assertParameterNames(getMethod("oneObject"), "this( x)", new String[] {"x"});
assertParameterNames(getMethod("oneObject"), "this (x )", new String[] {"x"});
assertParameterNames(getMethod("oneObject"), "this(x )", new String[] {"x"});
assertParameterNames(getMethod("oneObject"), "foo() && this(x)", new String[] {"x"});
}
@Test
@@ -165,16 +165,16 @@ public class AspectJAdviceParameterNameDiscovererTests {
@Test
public void testTargetBindingOneCandidate() {
assertParameterNames(getMethod("oneObject"), "target(x)", new String[]{"x"});
assertParameterNames(getMethod("oneObject"), "target(x)", new String[] {"x"});
}
@Test
public void testTargetBindingWithAlternateTokenizations() {
assertParameterNames(getMethod("oneObject"), "target( x )", new String[]{"x"});
assertParameterNames(getMethod("oneObject"), "target( x)", new String[]{"x"});
assertParameterNames(getMethod("oneObject"), "target (x )", new String[]{"x"});
assertParameterNames(getMethod("oneObject"), "target(x )", new String[]{"x"});
assertParameterNames(getMethod("oneObject"), "foo() && target(x)", new String[]{"x"});
assertParameterNames(getMethod("oneObject"), "target( x )", new String[] {"x"});
assertParameterNames(getMethod("oneObject"), "target( x)", new String[] {"x"});
assertParameterNames(getMethod("oneObject"), "target (x )", new String[] {"x"});
assertParameterNames(getMethod("oneObject"), "target(x )", new String[] {"x"});
assertParameterNames(getMethod("oneObject"), "foo() && target(x)", new String[] {"x"});
}
@Test
@@ -193,7 +193,7 @@ public class AspectJAdviceParameterNameDiscovererTests {
@Test
public void testArgsBindingOneObject() {
assertParameterNames(getMethod("oneObject"), "args(x)", new String[]{"x"});
assertParameterNames(getMethod("oneObject"), "args(x)", new String[] {"x"});
}
@Test
@@ -210,7 +210,7 @@ public class AspectJAdviceParameterNameDiscovererTests {
@Test
public void testArgsOnePrimitive() {
assertParameterNames(getMethod("onePrimitive"), "args(count)", new String[]{"count"});
assertParameterNames(getMethod("onePrimitive"), "args(count)", new String[] {"count"});
}
@Test
@@ -221,62 +221,64 @@ public class AspectJAdviceParameterNameDiscovererTests {
@Test
public void testThisAndPrimitive() {
assertParameterNames(getMethod("oneObjectOnePrimitive"), "args(count) && this(obj)", new String[]{"obj", "count"});
assertParameterNames(getMethod("oneObjectOnePrimitive"), "args(count) && this(obj)", new String[] {"obj", "count"});
}
@Test
public void testTargetAndPrimitive() {
assertParameterNames(getMethod("oneObjectOnePrimitive"), "args(count) && target(obj)", new String[]{"obj", "count"});
assertParameterNames(getMethod("oneObjectOnePrimitive"), "args(count) && target(obj)", new String[] {"obj", "count"});
}
@Test
public void testThrowingAndPrimitive() {
assertParameterNames(getMethod("oneThrowableOnePrimitive"), "args(count)", null, "ex", new String[]{"ex", "count"});
assertParameterNames(getMethod("oneThrowableOnePrimitive"), "args(count)", null, "ex", new String[] {"ex", "count"});
}
@Test
public void testAllTogetherNow() {
assertParameterNames(getMethod("theBigOne"), "this(foo) && args(x)", null, "ex", new String[]{"thisJoinPoint", "ex", "x", "foo"});
assertParameterNames(getMethod("theBigOne"), "this(foo) && args(x)", null, "ex", new String[] {"thisJoinPoint", "ex", "x", "foo"});
}
@Test
public void testReferenceBinding() {
assertParameterNames(getMethod("onePrimitive"),"somepc(foo)",new String[] {"foo"});
assertParameterNames(getMethod("onePrimitive"),"somepc(foo)", new String[] {"foo"});
}
@Test
public void testReferenceBindingWithAlternateTokenizations() {
assertParameterNames(getMethod("onePrimitive"),"call(bar *) && somepc(foo)",new String[] {"foo"});
assertParameterNames(getMethod("onePrimitive"),"somepc ( foo )",new String[] {"foo"});
assertParameterNames(getMethod("onePrimitive"),"somepc( foo)",new String[] {"foo"});
assertParameterNames(getMethod("onePrimitive"),"call(bar *) && somepc(foo)", new String[] {"foo"});
assertParameterNames(getMethod("onePrimitive"),"somepc ( foo )", new String[] {"foo"});
assertParameterNames(getMethod("onePrimitive"),"somepc( foo)", new String[] {"foo"});
}
protected Method getMethod(String name) {
// assumes no overloading of test methods...
Method[] candidates = this.getClass().getMethods();
for (int i = 0; i < candidates.length; i++) {
if (candidates[i].getName().equals(name)) {
return candidates[i];
for (Method candidate : candidates) {
if (candidate.getName().equals(name)) {
return candidate;
}
}
fail("Bad test specification, no method '" + name + "' found in test class");
return null;
}
protected void assertParameterNames(Method m, String pointcut, String[] parameterNames) {
assertParameterNames(m, pointcut, null, null, parameterNames);
protected void assertParameterNames(Method method, String pointcut, String[] parameterNames) {
assertParameterNames(method, pointcut, null, null, parameterNames);
}
protected void assertParameterNames(Method m, String pointcut, String returning, String throwing, String[] parameterNames) {
protected void assertParameterNames(Method method, String pointcut, String returning, String throwing,
String[] parameterNames) {
assertEquals("bad test specification, must have same number of parameter names as method arguments",
m.getParameterCount(), parameterNames.length);
method.getParameterCount(), parameterNames.length);
AspectJAdviceParameterNameDiscoverer discoverer = new AspectJAdviceParameterNameDiscoverer(pointcut);
discoverer.setRaiseExceptions(true);
discoverer.setReturningName(returning);
discoverer.setThrowingName(throwing);
String[] discoveredNames = discoverer.getParameterNames(m);
String[] discoveredNames = discoverer.getParameterNames(method);
String formattedExpectedNames = format(parameterNames);
String formattedActualNames = format(discoveredNames);
@@ -294,18 +296,20 @@ public class AspectJAdviceParameterNameDiscovererTests {
}
}
protected void assertException(Method m, String pointcut, Class<?> exceptionType, String message) {
assertException(m, pointcut, null, null, exceptionType, message);
protected void assertException(Method method, String pointcut, Class<?> exceptionType, String message) {
assertException(method, pointcut, null, null, exceptionType, message);
}
protected void assertException(Method m, String pointcut, String returning, String throwing, Class<?> exceptionType, String message) {
protected void assertException(Method method, String pointcut, String returning, String throwing,
Class<?> exceptionType, String message) {
AspectJAdviceParameterNameDiscoverer discoverer = new AspectJAdviceParameterNameDiscoverer(pointcut);
discoverer.setRaiseExceptions(true);
discoverer.setReturningName(returning);
discoverer.setThrowingName(throwing);
try {
discoverer.getParameterNames(m);
discoverer.getParameterNames(method);
fail("Expecting " + exceptionType.getName() + " with message '" + message + "'");
}
catch (RuntimeException expected) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2017 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.
@@ -27,55 +27,54 @@ import org.springframework.aop.aspectj.AspectJAdviceParameterNameDiscoverer.Ambi
* @author Adrian Colyer
* @author Chris Beams
*/
public class TigerAspectJAdviceParameterNameDiscovererTests
extends AspectJAdviceParameterNameDiscovererTests {
public class TigerAspectJAdviceParameterNameDiscovererTests extends AspectJAdviceParameterNameDiscovererTests {
@Test
public void testAtThis() {
assertParameterNames(getMethod("oneAnnotation"),"@this(a)",new String[]{"a"});
assertParameterNames(getMethod("oneAnnotation"),"@this(a)", new String[] {"a"});
}
@Test
public void testAtTarget() {
assertParameterNames(getMethod("oneAnnotation"),"@target(a)",new String[]{"a"});
assertParameterNames(getMethod("oneAnnotation"),"@target(a)", new String[] {"a"});
}
@Test
public void testAtArgs() {
assertParameterNames(getMethod("oneAnnotation"),"@args(a)",new String[]{"a"});
assertParameterNames(getMethod("oneAnnotation"),"@args(a)", new String[] {"a"});
}
@Test
public void testAtWithin() {
assertParameterNames(getMethod("oneAnnotation"),"@within(a)",new String[]{"a"});
assertParameterNames(getMethod("oneAnnotation"),"@within(a)", new String[] {"a"});
}
@Test
public void testAtWithincode() {
assertParameterNames(getMethod("oneAnnotation"),"@withincode(a)",new String[]{"a"});
assertParameterNames(getMethod("oneAnnotation"),"@withincode(a)", new String[] {"a"});
}
@Test
public void testAtAnnotation() {
assertParameterNames(getMethod("oneAnnotation"),"@annotation(a)",new String[]{"a"});
assertParameterNames(getMethod("oneAnnotation"),"@annotation(a)", new String[] {"a"});
}
@Test
public void testAmbiguousAnnotationTwoVars() {
assertException(getMethod("twoAnnotations"),"@annotation(a) && @this(x)",AmbiguousBindingException.class,
assertException(getMethod("twoAnnotations"),"@annotation(a) && @this(x)", AmbiguousBindingException.class,
"Found 2 potential annotation variable(s), and 2 potential argument slots");
}
@Test
public void testAmbiguousAnnotationOneVar() {
assertException(getMethod("oneAnnotation"),"@annotation(a) && @this(x)",IllegalArgumentException.class,
"Found 2 candidate annotation binding variables but only one potential argument binding slot");
"Found 2 candidate annotation binding variables but only one potential argument binding slot");
}
@Test
public void testAnnotationMedley() {
assertParameterNames(getMethod("annotationMedley"),"@annotation(a) && args(count) && this(foo)",null,"ex",
new String[] {"ex","foo","count","a"});
assertParameterNames(getMethod("annotationMedley"),"@annotation(a) && args(count) && this(foo)",
null, "ex", new String[] {"ex", "foo", "count", "a"});
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2017 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.
@@ -22,12 +22,12 @@ import com.google.protobuf.ExtensionRegistry;
* Google Protocol Messages can contain message extensions that can be parsed if
* the appropriate configuration has been registered in the {@code ExtensionRegistry}.
*
* This interface provides a facility to populate the {@code ExtensionRegistry}.
* <p>This interface provides a facility to populate the {@code ExtensionRegistry}.
*
* @author Alex Antonov
* @since 4.1
* @see <a href="https://developers.google.com/protocol-buffers/docs/reference/java/com/google/protobuf/ExtensionRegistry">
* com.google.protobuf.ExtensionRegistry</a>
* com.google.protobuf.ExtensionRegistry</a>
*/
public interface ExtensionRegistryInitializer {

View File

@@ -75,7 +75,7 @@ public abstract class AbstractServerHttpResponse implements ServerHttpResponse {
public AbstractServerHttpResponse(DataBufferFactory dataBufferFactory) {
Assert.notNull(dataBufferFactory, "'dataBufferFactory' must not be null");
Assert.notNull(dataBufferFactory, "DataBufferFactory must not be null");
this.dataBufferFactory = dataBufferFactory;
this.headers = new HttpHeaders();
this.cookies = new LinkedMultiValueMap<>();

View File

@@ -22,7 +22,8 @@ import org.springframework.util.Assert;
/**
* Represents a function that evaluates on a given {@link ServerRequest}.
* Instances of this function that evaluate on common request properties can be found in {@link RequestPredicates}.
* Instances of this function that evaluate on common request properties
* can be found in {@link RequestPredicates}.
*
* @author Arjen Poutsma
* @since 5.0
@@ -74,17 +75,17 @@ public interface RequestPredicate {
/**
* Transform the given request into a request used for a nested route. For instance,
* a path-based predicate can return a {@code ServerRequest} with a the path remaining after a
* match.
* a path-based predicate can return a {@code ServerRequest} with a the path remaining
* after a match.
* <p>The default implementation returns an {@code Optional} wrapping the given path if
* {@link #test(ServerRequest)} evaluates to {@code true}; or {@link Optional#empty()} if it
* evaluates to {@code false}.
* {@link #test(ServerRequest)} evaluates to {@code true}; or {@link Optional#empty()}
* if it evaluates to {@code false}.
* @param request the request to be nested
* @return the nested request
* @see RouterFunctions#nest(RequestPredicate, RouterFunction)
*/
default Optional<ServerRequest> nest(ServerRequest request) {
return test(request) ? Optional.of(request) : Optional.empty();
return (test(request) ? Optional.of(request) : Optional.empty());
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 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.
@@ -44,10 +44,11 @@ public class HandlerFunctionAdapter implements HandlerAdapter {
HANDLER_FUNCTION_RETURN_TYPE = new MethodParameter(method, -1);
}
catch (NoSuchMethodException ex) {
throw new Error(ex);
throw new IllegalStateException(ex);
}
}
@Override
public boolean supports(Object handler) {
return handler instanceof HandlerFunction;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2017 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.
@@ -24,7 +24,6 @@ import javax.script.ScriptEngine;
* a {@code ScriptEngine} for use in a web application.
*
* <pre class="code">
*
* // Add the following to an &#64;Configuration class
* &#64;Bean
* public ScriptTemplateConfigurer mustacheConfigurer() {
@@ -157,7 +156,6 @@ public class ScriptTemplateConfigurer implements ScriptTemplateConfig {
/**
* Set the render function name (mandatory).
*
* <p>This function will be called with the following parameters:
* <ol>
* <li>{@code String template}: the template content</li>