Consistent HttpMethod identity comparisons
This commit is contained in:
@@ -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.
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.web.servlet.mvc.condition;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import javax.servlet.DispatcherType;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
@@ -27,17 +26,8 @@ import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.mock.web.test.MockHttpServletRequest;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.springframework.web.bind.annotation.RequestMethod.DELETE;
|
||||
import static org.springframework.web.bind.annotation.RequestMethod.GET;
|
||||
import static org.springframework.web.bind.annotation.RequestMethod.HEAD;
|
||||
import static org.springframework.web.bind.annotation.RequestMethod.OPTIONS;
|
||||
import static org.springframework.web.bind.annotation.RequestMethod.POST;
|
||||
import static org.springframework.web.bind.annotation.RequestMethod.PUT;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.web.bind.annotation.RequestMethod.*;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
@@ -63,7 +53,7 @@ public class RequestMethodsRequestConditionTests {
|
||||
public void getMatchingConditionWithEmptyConditions() {
|
||||
RequestMethodsRequestCondition condition = new RequestMethodsRequestCondition();
|
||||
for (RequestMethod method : RequestMethod.values()) {
|
||||
if (!OPTIONS.equals(method)) {
|
||||
if (method != OPTIONS) {
|
||||
HttpServletRequest request = new MockHttpServletRequest(method.name(), "");
|
||||
assertNotNull(condition.getMatchingCondition(request));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 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,9 +16,6 @@
|
||||
|
||||
package org.springframework.web.servlet.mvc.method;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@@ -26,7 +23,6 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -63,6 +59,8 @@ import org.springframework.web.servlet.mvc.condition.ProducesRequestCondition;
|
||||
import org.springframework.web.servlet.mvc.condition.RequestMethodsRequestCondition;
|
||||
import org.springframework.web.util.UrlPathHelper;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Test fixture with {@link RequestMappingInfoHandlerMapping}.
|
||||
@@ -157,9 +155,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||
}
|
||||
}
|
||||
|
||||
// SPR-9603
|
||||
|
||||
@Test(expected = HttpMediaTypeNotAcceptableException.class)
|
||||
@Test(expected = HttpMediaTypeNotAcceptableException.class) // SPR-9603
|
||||
public void getHandlerRequestMethodMatchFalsePositive() throws Exception {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/users");
|
||||
request.addHeader("Accept", "application/xml");
|
||||
@@ -167,9 +163,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||
this.handlerMapping.getHandler(request);
|
||||
}
|
||||
|
||||
// SPR-8462
|
||||
|
||||
@Test
|
||||
@Test // SPR-8462
|
||||
public void getHandlerMediaTypeNotSupported() throws Exception {
|
||||
testHttpMediaTypeNotSupportedException("/person/1");
|
||||
testHttpMediaTypeNotSupportedException("/person/1/");
|
||||
@@ -197,18 +191,14 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||
}
|
||||
}
|
||||
|
||||
// SPR-8462
|
||||
|
||||
@Test
|
||||
@Test // SPR-8462
|
||||
public void getHandlerMediaTypeNotAccepted() throws Exception {
|
||||
testHttpMediaTypeNotAcceptableException("/persons");
|
||||
testHttpMediaTypeNotAcceptableException("/persons/");
|
||||
testHttpMediaTypeNotAcceptableException("/persons.json");
|
||||
}
|
||||
|
||||
// SPR-12854
|
||||
|
||||
@Test
|
||||
@Test // SPR-12854
|
||||
public void getHandlerUnsatisfiedServletRequestParameterException() throws Exception {
|
||||
try {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/params");
|
||||
@@ -275,10 +265,8 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||
assertEquals("2", uriVariables.get("path2"));
|
||||
}
|
||||
|
||||
// SPR-9098
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
@Test // SPR-9098
|
||||
public void handleMatchUriTemplateVariablesDecode() {
|
||||
RequestMappingInfo key = RequestMappingInfo.paths("/{group}/{identifier}").build();
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/group/a%2Fb");
|
||||
@@ -502,6 +490,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Controller
|
||||
private static class UserController {
|
||||
@@ -515,6 +504,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class TestRequestMappingInfoHandlerMapping extends RequestMappingInfoHandlerMapping {
|
||||
|
||||
public void registerHandler(Object handler) {
|
||||
|
||||
Reference in New Issue
Block a user