Polishing

This commit is contained in:
Juergen Hoeller
2015-11-26 01:10:31 +01:00
parent e410129aaf
commit 97148ce889
4 changed files with 41 additions and 23 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2015 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.
@@ -54,7 +54,7 @@ import org.springframework.format.annotation.DateTimeFormat.ISO;
*/
public class JodaTimeFormatterRegistrar implements FormatterRegistrar {
private static enum Type {DATE, TIME, DATE_TIME}
private enum Type {DATE, TIME, DATE_TIME}
/**
@@ -119,9 +119,9 @@ public class JodaTimeFormatterRegistrar implements FormatterRegistrar {
* the {@link #setDateStyle(String) dateStyle} and
* {@link #setUseIsoFormat(boolean) useIsoFormat} properties will be ignored.
* @param formatter the formatter to use
* @since 3.2
* @see #setTimeFormatter
* @see #setDateTimeFormatter
* @since 3.2
*/
public void setDateFormatter(DateTimeFormatter formatter) {
this.formatters.put(Type.DATE, formatter);
@@ -133,9 +133,9 @@ public class JodaTimeFormatterRegistrar implements FormatterRegistrar {
* the {@link #setTimeStyle(String) timeStyle} and
* {@link #setUseIsoFormat(boolean) useIsoFormat} properties will be ignored.
* @param formatter the formatter to use
* @since 3.2
* @see #setDateFormatter
* @see #setDateTimeFormatter
* @since 3.2
*/
public void setTimeFormatter(DateTimeFormatter formatter) {
this.formatters.put(Type.TIME, formatter);
@@ -148,9 +148,9 @@ public class JodaTimeFormatterRegistrar implements FormatterRegistrar {
* the {@link #setDateTimeStyle(String) dateTimeStyle} and
* {@link #setUseIsoFormat(boolean) useIsoFormat} properties will be ignored.
* @param formatter the formatter to use
* @since 3.2
* @see #setDateFormatter
* @see #setTimeFormatter
* @since 3.2
*/
public void setDateTimeFormatter(DateTimeFormatter formatter) {
this.formatters.put(Type.DATE_TIME, formatter);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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.
@@ -50,7 +50,7 @@ import org.springframework.lang.UsesJava8;
@UsesJava8
public class DateTimeFormatterRegistrar implements FormatterRegistrar {
private static enum Type {DATE, TIME, DATE_TIME}
private enum Type {DATE, TIME, DATE_TIME}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2015 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.
@@ -16,6 +16,7 @@
package org.springframework.test.web.servlet.result;
import com.jayway.jsonpath.JsonPath;
import org.hamcrest.Matcher;
import org.springframework.test.util.JsonPathExpectationsHelper;
@@ -23,30 +24,36 @@ import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.ResultMatcher;
/**
* Factory for assertions on the response content using <a
* href="http://goessner.net/articles/JsonPath/">JSONPath</a> expressions.
* An instance of this class is typically accessed via
* {@link MockMvcResultMatchers#jsonPath}.
* Factory for assertions on the response content using
* <a href="https://github.com/jayway/JsonPath">JsonPath</a> expressions.
* <p>An instance of this class is typically accessed via
* {@link MockMvcResultMatchers#jsonPath(String, Matcher)} or
* {@link MockMvcResultMatchers#jsonPath(String, Object...)}.
*
* @author Rossen Stoyanchev
* @since 3.2
*/
public class JsonPathResultMatchers {
private JsonPathExpectationsHelper jsonPathHelper;
private final JsonPathExpectationsHelper jsonPathHelper;
/**
* Protected constructor. Use
* {@link MockMvcResultMatchers#jsonPath(String, Object...)} or
* Protected constructor.
* <p>Use {@link MockMvcResultMatchers#jsonPath(String, Object...)} or
* {@link MockMvcResultMatchers#jsonPath(String, Matcher)}.
* @param expression the {@link JsonPath} expression; never {@code null} or empty
* @param args arguments to parameterize the {@code JsonPath} expression with,
* using formatting specifiers defined in {@link String#format(String, Object...)}
*/
protected JsonPathResultMatchers(String expression, Object ... args) {
this.jsonPathHelper = new JsonPathExpectationsHelper(expression, args);
}
/**
* Evaluate the JSONPath and assert the value of the content found with the
* given Hamcrest {@code Matcher}.
* Evaluate the JSON path expression against the response content and
* assert the resulting value with the given Hamcrest {@link Matcher}.
*/
public <T> ResultMatcher value(final Matcher<T> matcher) {
return new ResultMatcher() {
@@ -59,7 +66,8 @@ public class JsonPathResultMatchers {
}
/**
* Evaluate the JSONPath and assert the value of the content found.
* Evaluate the JSON path expression against the response content and
* assert that the result is equal to the supplied value.
*/
public ResultMatcher value(final Object expectedValue) {
return new ResultMatcher() {
@@ -71,7 +79,11 @@ public class JsonPathResultMatchers {
}
/**
* Evaluate the JSONPath and assert that content exists.
* Evaluate the JSON path expression against the response content and
* assert that a non-null value exists at the given path.
* <p>If the JSON path expression is not {@linkplain JsonPath#isDefinite
* definite}, this method asserts that the value at the given path is not
* <em>empty</em>.
*/
public ResultMatcher exists() {
return new ResultMatcher() {
@@ -84,7 +96,11 @@ public class JsonPathResultMatchers {
}
/**
* Evaluate the JSON path and assert not content was found.
* Evaluate the JSON path expression against the response content and
* assert that a value does not exist at the given path.
* <p>If the JSON path expression is not {@linkplain JsonPath#isDefinite
* definite}, this method asserts that the value at the given path is
* <em>empty</em>.
*/
public ResultMatcher doesNotExist() {
return new ResultMatcher() {
@@ -97,7 +113,8 @@ public class JsonPathResultMatchers {
}
/**
* Evluate the JSON path and assert the content found is an array.
* Evaluate the JSON path expression against the response content and
* assert that the result is an array.
*/
public ResultMatcher isArray() {
return new ResultMatcher() {

View File

@@ -196,7 +196,8 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
protected abstract T getMappingForMethod(Method method, Class<?> handlerType);
/**
* Register a handler method and its unique mapping.
* Register a handler method and its unique mapping. Invoked at startup for
* each detected handler method.
* @param handler the bean name of the handler or the handler instance
* @param method the method to register
* @param mapping the mapping conditions associated with the handler method
@@ -346,7 +347,7 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
return bestMatch.handlerMethod;
}
else {
return handleNoMatch(handlerMethods.keySet(), lookupPath, request);
return handleNoMatch(this.handlerMethods.keySet(), lookupPath, request);
}
}