I am on the java tomcat stack and creating a new filter. https://javaee.github.io/javaee-spec/javadocs/javax/servlet/http/HttpFilter.html I am interested in unit testing it because I want to have 100% branch coverage.
This filter wraps the response object. We override the default behavior of the response such that whenever we call response.addCookie(cookie), we append the string "happy" to the cookie name:
HappyCookieFilter implements Filter {
HappyCookieResponseWrapper happyCookieResponseWrapper;
...
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) {
chain.doFilter(req, happyCookieResponseWrapper.wrap(res));
}
...
}
- Assuming the HappyCookieResponseWrapper is already unit tested, what would be the benefit of testing doFilter method?
- How would I test the HappyCookieFilter.doFilter and what should I assert?