I found what my problem was, and I just leave a note here in case someone had the same problem.
Here is why I got the NoSuchMethodError
:
- I use Apache Maven to handle dependencies
to use
MockHttpServletRequest
andMockHttpServletResponse
I included a dependency to spring-mock 2.0.8:<dependency> <groupId>org.springframework</groupId> <artifactId>spring-mock</artifactId> <version>2.0.8</version> <scope>test</scope> </dependency>
unfortunately spring-mock 2.0.8 has a dependency to commons-logging 1.1, which, in turn, has a dependency to servlet-api 2.3, in which
javax/servlet/http/HttpServletResponse.getContentType()Ljava/lang/String
does not exists! That method exists since servlet-api 2.4
So, to solve my problem I simply added an explicit dependency to servlet-api 2.4 with scope test! Now my unit test works without a problem!