Unit Testing Servlet filter with Mockito

This assumes that you have gone through the basic JUnit & Mockito tutorials. Here is test class to “Unit Testing Servlet Filter”. The “HttpServletRequest“, “HttpServletResponse“, “FilterChain“, etc are mocked with Mockito. The Spring also provides classes like “MockHttpServletRequest“, etc.

Here is the “LoggingFilter” that is being tested


Java & Big Data Interview FAQs

Java Key Areas Interview Q&As

800+ Java Interview Q&As

Java & Big Data Tutorials

Top