Polishing
This commit is contained in:
@@ -261,7 +261,7 @@ public class WebExchangeBindException extends ServerWebInputException implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordFieldValue(String field, Class<?> type, Object value) {
|
||||
public void recordFieldValue(String field, Class<?> type, @Nullable Object value) {
|
||||
this.bindingResult.recordFieldValue(field, type, value);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,6 @@ import org.springframework.core.ParameterNameDiscoverer;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.validation.AbstractBindingResult;
|
||||
import org.springframework.validation.BindException;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.validation.Errors;
|
||||
@@ -289,13 +288,11 @@ public class ModelAttributeMethodProcessor implements HandlerMethodArgumentResol
|
||||
}
|
||||
|
||||
if (bindingFailure) {
|
||||
if (binder.getBindingResult() instanceof AbstractBindingResult) {
|
||||
AbstractBindingResult result = (AbstractBindingResult) binder.getBindingResult();
|
||||
for (int i = 0; i < paramNames.length; i++) {
|
||||
result.recordFieldValue(paramNames[i], paramTypes[i], args[i]);
|
||||
}
|
||||
BindingResult result = binder.getBindingResult();
|
||||
for (int i = 0; i < paramNames.length; i++) {
|
||||
result.recordFieldValue(paramNames[i], paramTypes[i], args[i]);
|
||||
}
|
||||
throw new BindException(binder.getBindingResult());
|
||||
throw new BindException(result);
|
||||
}
|
||||
|
||||
return BeanUtils.instantiateClass(ctor, args);
|
||||
@@ -319,13 +316,17 @@ public class ModelAttributeMethodProcessor implements HandlerMethodArgumentResol
|
||||
* @param parameter the method parameter declaration
|
||||
*/
|
||||
protected void validateIfApplicable(WebDataBinder binder, MethodParameter parameter) {
|
||||
Annotation[] annotations = parameter.getParameterAnnotations();
|
||||
for (Annotation ann : annotations) {
|
||||
for (Annotation ann : parameter.getParameterAnnotations()) {
|
||||
Validated validatedAnn = AnnotationUtils.getAnnotation(ann, Validated.class);
|
||||
if (validatedAnn != null || ann.annotationType().getSimpleName().startsWith("Valid")) {
|
||||
Object hints = (validatedAnn != null ? validatedAnn.value() : AnnotationUtils.getValue(ann));
|
||||
Object[] validationHints = (hints instanceof Object[] ? (Object[]) hints : new Object[] {hints});
|
||||
binder.validate(validationHints);
|
||||
if (hints != null) {
|
||||
Object[] validationHints = (hints instanceof Object[] ? (Object[]) hints : new Object[] {hints});
|
||||
binder.validate(validationHints);
|
||||
}
|
||||
else {
|
||||
binder.validate();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ public class InMemoryWebSessionStore implements WebSessionStore {
|
||||
* {@link IllegalStateException}.
|
||||
* <p>By default set to 10000.
|
||||
* @param maxSessions the maximum number of sessions
|
||||
* @since 5.1
|
||||
* @since 5.0.8
|
||||
*/
|
||||
public void setMaxSessions(int maxSessions) {
|
||||
this.maxSessions = maxSessions;
|
||||
@@ -70,7 +70,7 @@ public class InMemoryWebSessionStore implements WebSessionStore {
|
||||
|
||||
/**
|
||||
* Return the maximum number of sessions that can be stored.
|
||||
* @since 5.1
|
||||
* @since 5.0.8
|
||||
*/
|
||||
public int getMaxSessions() {
|
||||
return this.maxSessions;
|
||||
@@ -102,9 +102,9 @@ public class InMemoryWebSessionStore implements WebSessionStore {
|
||||
* Return the map of sessions with an {@link Collections#unmodifiableMap
|
||||
* unmodifiable} wrapper. This could be used for management purposes, to
|
||||
* list active sessions, invalidate expired ones, etc.
|
||||
* @since 5.1
|
||||
* @since 5.0.8
|
||||
*/
|
||||
public Map<String, InMemoryWebSession> getSessions() {
|
||||
public Map<String, WebSession> getSessions() {
|
||||
return Collections.unmodifiableMap(this.sessions);
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ public class InMemoryWebSessionStore implements WebSessionStore {
|
||||
* kicked off lazily during calls to {@link #createWebSession() create} or
|
||||
* {@link #retrieveSession retrieve}, no less than 60 seconds apart.
|
||||
* This method can be called to force a check at a specific time.
|
||||
* @since 5.1
|
||||
* @since 5.0.8
|
||||
*/
|
||||
public void removeExpiredSessions() {
|
||||
this.expiredSessionChecker.removeExpiredSessions(this.clock.instant());
|
||||
|
||||
@@ -255,7 +255,6 @@ final class HierarchicalUriComponents extends UriComponents {
|
||||
// Encoding
|
||||
|
||||
HierarchicalUriComponents encodeTemplate(Charset charset) {
|
||||
|
||||
if (this.encodeState.isEncoded()) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -325,7 +325,7 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable {
|
||||
}
|
||||
|
||||
|
||||
// encode methods
|
||||
// Encode methods
|
||||
|
||||
/**
|
||||
* Request to have the URI template pre-encoded at build time, and
|
||||
@@ -361,7 +361,7 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable {
|
||||
}
|
||||
|
||||
|
||||
// build methods
|
||||
// Build methods
|
||||
|
||||
/**
|
||||
* Build a {@code UriComponents} instance from the various components contained in this builder.
|
||||
@@ -386,8 +386,7 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable {
|
||||
HierarchicalUriComponents uriComponents =
|
||||
new HierarchicalUriComponents(this.scheme, this.fragment, this.userInfo,
|
||||
this.host, this.port, this.pathBuilder.build(), this.queryParams, encoded);
|
||||
|
||||
return this.encodeTemplate ? uriComponents.encodeTemplate(this.charset) : uriComponents;
|
||||
return (this.encodeTemplate ? uriComponents.encodeTemplate(this.charset) : uriComponents);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -406,7 +405,7 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable {
|
||||
* Build a {@code UriComponents} instance and replaces URI template variables
|
||||
* with the values from an array. This is a shortcut method which combines
|
||||
* calls to {@link #build()} and then {@link UriComponents#expand(Object...)}.
|
||||
* @param uriVariableValues URI variable values
|
||||
* @param uriVariableValues the URI variable values
|
||||
* @return the URI components with expanded values
|
||||
*/
|
||||
public UriComponents buildAndExpand(Object... uriVariableValues) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -62,7 +62,7 @@ public class Jaxb2CollectionHttpMessageConverterTests {
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
public void setup() {
|
||||
converter = new Jaxb2CollectionHttpMessageConverter<Collection<Object>>();
|
||||
rootElementListType = new ParameterizedTypeReference<List<RootElement>>() {}.getType();
|
||||
rootElementSetType = new ParameterizedTypeReference<Set<RootElement>>() {}.getType();
|
||||
@@ -72,7 +72,7 @@ public class Jaxb2CollectionHttpMessageConverterTests {
|
||||
|
||||
|
||||
@Test
|
||||
public void canRead() throws Exception {
|
||||
public void canRead() {
|
||||
assertTrue(converter.canRead(rootElementListType, null, null));
|
||||
assertTrue(converter.canRead(rootElementSetType, null, null));
|
||||
assertTrue(converter.canRead(typeSetType, null, null));
|
||||
@@ -271,4 +271,4 @@ public class Jaxb2CollectionHttpMessageConverterTests {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2018 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,13 +16,7 @@
|
||||
|
||||
package org.springframework.http.converter.xml;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.xmlunit.diff.ComparisonType.*;
|
||||
import static org.xmlunit.diff.DifferenceEvaluators.*;
|
||||
import static org.xmlunit.matchers.CompareMatcher.*;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import javax.xml.bind.Marshaller;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
@@ -48,6 +42,11 @@ import org.springframework.http.MockHttpInputMessage;
|
||||
import org.springframework.http.MockHttpOutputMessage;
|
||||
import org.springframework.http.converter.HttpMessageNotReadableException;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.xmlunit.diff.ComparisonType.*;
|
||||
import static org.xmlunit.diff.DifferenceEvaluators.*;
|
||||
import static org.xmlunit.matchers.CompareMatcher.*;
|
||||
|
||||
/**
|
||||
* Tests for {@link Jaxb2RootElementHttpMessageConverter}.
|
||||
*
|
||||
@@ -68,7 +67,7 @@ public class Jaxb2RootElementHttpMessageConverterTests {
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
public void setup() {
|
||||
converter = new Jaxb2RootElementHttpMessageConverter();
|
||||
rootElement = new RootElement();
|
||||
DefaultAopProxyFactory proxyFactory = new DefaultAopProxyFactory();
|
||||
@@ -81,7 +80,7 @@ public class Jaxb2RootElementHttpMessageConverterTests {
|
||||
|
||||
|
||||
@Test
|
||||
public void canRead() throws Exception {
|
||||
public void canRead() {
|
||||
assertTrue("Converter does not support reading @XmlRootElement",
|
||||
converter.canRead(RootElement.class, null));
|
||||
assertTrue("Converter does not support reading @XmlType",
|
||||
@@ -89,7 +88,7 @@ public class Jaxb2RootElementHttpMessageConverterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canWrite() throws Exception {
|
||||
public void canWrite() {
|
||||
assertTrue("Converter does not support writing @XmlRootElement",
|
||||
converter.canWrite(RootElement.class, null));
|
||||
assertTrue("Converter does not support writing @XmlRootElement subclass",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -43,7 +43,7 @@ import static org.mockito.BDDMockito.*;
|
||||
public class MarshallingHttpMessageConverterTests {
|
||||
|
||||
@Test
|
||||
public void canRead() throws Exception {
|
||||
public void canRead() {
|
||||
Unmarshaller unmarshaller = mock(Unmarshaller.class);
|
||||
|
||||
given(unmarshaller.supports(Integer.class)).willReturn(false);
|
||||
@@ -58,7 +58,7 @@ public class MarshallingHttpMessageConverterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canWrite() throws Exception {
|
||||
public void canWrite() {
|
||||
Marshaller marshaller = mock(Marshaller.class);
|
||||
|
||||
given(marshaller.supports(Integer.class)).willReturn(false);
|
||||
@@ -130,8 +130,8 @@ public class MarshallingHttpMessageConverterTests {
|
||||
MarshallingHttpMessageConverter converter = new MarshallingHttpMessageConverter(marshaller);
|
||||
converter.write(body, null, outputMessage);
|
||||
|
||||
assertEquals("Invalid content-type", new MediaType("application", "xml"), outputMessage.getHeaders()
|
||||
.getContentType());
|
||||
assertEquals("Invalid content-type", new MediaType("application", "xml"),
|
||||
outputMessage.getHeaders().getContentType());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -48,13 +48,8 @@ import org.springframework.http.MockHttpOutputMessage;
|
||||
import org.springframework.http.converter.HttpMessageNotReadableException;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.xmlunit.matchers.CompareMatcher.isSimilarTo;
|
||||
|
||||
// Do NOT statically import org.junit.Assert.*, since XMLAssert extends junit.framework.Assert
|
||||
import static org.junit.Assert.*;
|
||||
import static org.xmlunit.matchers.CompareMatcher.*;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
@@ -73,7 +68,7 @@ public class SourceHttpMessageConverterTests {
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws IOException {
|
||||
public void setup() throws IOException {
|
||||
converter = new SourceHttpMessageConverter<>();
|
||||
Resource external = new ClassPathResource("external.txt", getClass());
|
||||
|
||||
@@ -163,7 +158,7 @@ public class SourceHttpMessageConverterTests {
|
||||
XMLReader reader = result.getXMLReader();
|
||||
reader.setContentHandler(new DefaultHandler() {
|
||||
@Override
|
||||
public void characters(char[] ch, int start, int length) throws SAXException {
|
||||
public void characters(char[] ch, int start, int length) {
|
||||
String s = new String(ch, start, length);
|
||||
assertNotEquals("Invalid result", "Foo Bar", s);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user