Skip to content

Commit 9451177

Browse files
committed
Polishing
(cherry picked from commit 382a931)
1 parent 9ed087d commit 9451177

File tree

2 files changed

+14
-27
lines changed

2 files changed

+14
-27
lines changed

spring-web/src/test/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBeanTests.java

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@
3030
import org.springframework.web.context.request.NativeWebRequest;
3131
import org.springframework.web.context.request.ServletWebRequest;
3232

33-
import static org.junit.Assert.assertEquals;
33+
import static org.junit.Assert.*;
3434

3535
/**
3636
* Test fixture for {@link ContentNegotiationManagerFactoryBean} tests.
37+
*
3738
* @author Rossen Stoyanchev
3839
*/
3940
public class ContentNegotiationManagerFactoryBeanTests {
@@ -119,9 +120,7 @@ public void favorPathWithJafTurnedOff() throws Exception {
119120
assertEquals(Collections.emptyList(), manager.resolveMediaTypes(this.webRequest));
120121
}
121122

122-
// SPR-10170
123-
124-
@Test(expected = HttpMediaTypeNotAcceptableException.class)
123+
@Test(expected = HttpMediaTypeNotAcceptableException.class) // SPR-10170
125124
public void favorPathWithIgnoreUnknownPathExtensionTurnedOff() throws Exception {
126125
this.factoryBean.setFavorPathExtension(true);
127126
this.factoryBean.setIgnoreUnknownPathExtensions(false);
@@ -152,9 +151,7 @@ public void favorParameter() throws Exception {
152151
manager.resolveMediaTypes(this.webRequest));
153152
}
154153

155-
// SPR-10170
156-
157-
@Test(expected = HttpMediaTypeNotAcceptableException.class)
154+
@Test(expected = HttpMediaTypeNotAcceptableException.class) // SPR-10170
158155
public void favorParameterWithUnknownMediaType() throws HttpMediaTypeNotAcceptableException {
159156
this.factoryBean.setFavorParameter(true);
160157
this.factoryBean.afterPropertiesSet();
@@ -188,16 +185,12 @@ public void setDefaultContentType() throws Exception {
188185
manager.resolveMediaTypes(this.webRequest));
189186

190187
// SPR-10513
191-
192188
this.servletRequest.addHeader("Accept", MediaType.ALL_VALUE);
193-
194189
assertEquals(Collections.singletonList(MediaType.APPLICATION_JSON),
195190
manager.resolveMediaTypes(this.webRequest));
196191
}
197192

198-
// SPR-12286
199-
200-
@Test
193+
@Test // SPR-12286
201194
public void setDefaultContentTypeWithStrategy() throws Exception {
202195
this.factoryBean.setDefaultContentTypeStrategy(new FixedContentNegotiationStrategy(MediaType.APPLICATION_JSON));
203196
this.factoryBean.afterPropertiesSet();
@@ -216,7 +209,6 @@ private static class TestServletContext extends MockServletContext {
216209

217210
private final Map<String, String> mimeTypes = new HashMap<>();
218211

219-
220212
public Map<String, String> getMimeTypes() {
221213
return this.mimeTypes;
222214
}

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMapping.java

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe
6565
}
6666
catch (NoSuchMethodException ex) {
6767
// Should never happen
68-
throw new IllegalStateException("No handler for HTTP OPTIONS", ex);
68+
throw new IllegalStateException("Failed to retrieve internal handler method for HTTP OPTIONS", ex);
6969
}
7070
}
7171

@@ -183,7 +183,6 @@ private Map<String, MultiValueMap<String, String>> extractMatrixVariables(
183183
/**
184184
* Iterate all RequestMappingInfo's once again, look if any match by URL at
185185
* least and raise exceptions according to what doesn't match.
186-
*
187186
* @throws HttpRequestMethodNotSupportedException if there are matches by URL
188187
* but not by HTTP method
189188
* @throws HttpMediaTypeNotAcceptableException if there are matches by URL
@@ -243,7 +242,6 @@ private static class PartialMatchHelper {
243242

244243
private final List<PartialMatch> partialMatches = new ArrayList<PartialMatch>();
245244

246-
247245
public PartialMatchHelper(Set<RequestMappingInfo> infos, HttpServletRequest request) {
248246
for (RequestMappingInfo info : infos) {
249247
if (info.getPatternsCondition().getMatchingCondition(request) != null) {
@@ -252,7 +250,6 @@ public PartialMatchHelper(Set<RequestMappingInfo> infos, HttpServletRequest requ
252250
}
253251
}
254252

255-
256253
/**
257254
* Whether there any partial matches.
258255
*/
@@ -387,20 +384,18 @@ private static class PartialMatch {
387384

388385
private final boolean paramsMatch;
389386

390-
391387
/**
392388
* @param info RequestMappingInfo that matches the URL path.
393389
* @param request the current request
394390
*/
395391
public PartialMatch(RequestMappingInfo info, HttpServletRequest request) {
396392
this.info = info;
397-
this.methodsMatch = info.getMethodsCondition().getMatchingCondition(request) != null;
398-
this.consumesMatch = info.getConsumesCondition().getMatchingCondition(request) != null;
399-
this.producesMatch = info.getProducesCondition().getMatchingCondition(request) != null;
400-
this.paramsMatch = info.getParamsCondition().getMatchingCondition(request) != null;
393+
this.methodsMatch = (info.getMethodsCondition().getMatchingCondition(request) != null);
394+
this.consumesMatch = (info.getConsumesCondition().getMatchingCondition(request) != null);
395+
this.producesMatch = (info.getProducesCondition().getMatchingCondition(request) != null);
396+
this.paramsMatch = (info.getParamsCondition().getMatchingCondition(request) != null);
401397
}
402398

403-
404399
public RequestMappingInfo getInfo() {
405400
return this.info;
406401
}
@@ -410,15 +405,15 @@ public boolean hasMethodsMatch() {
410405
}
411406

412407
public boolean hasConsumesMatch() {
413-
return hasMethodsMatch() && this.consumesMatch;
408+
return (hasMethodsMatch() && this.consumesMatch);
414409
}
415410

416411
public boolean hasProducesMatch() {
417-
return hasConsumesMatch() && this.producesMatch;
412+
return (hasConsumesMatch() && this.producesMatch);
418413
}
419414

420415
public boolean hasParamsMatch() {
421-
return hasProducesMatch() && this.paramsMatch;
416+
return (hasProducesMatch() && this.paramsMatch);
422417
}
423418

424419
@Override
@@ -428,14 +423,14 @@ public String toString() {
428423
}
429424
}
430425

426+
431427
/**
432428
* Default handler for HTTP OPTIONS.
433429
*/
434430
private static class HttpOptionsHandler {
435431

436432
private final HttpHeaders headers = new HttpHeaders();
437433

438-
439434
public HttpOptionsHandler(Set<String> declaredMethods) {
440435
this.headers.setAllow(initAllowedHttpMethods(declaredMethods));
441436
}

0 commit comments

Comments
 (0)