BAEL-4404 | Added test class to verify the beahvior
This commit is contained in:
parent
51c2e22324
commit
3626b5c858
|
@ -0,0 +1,34 @@
|
|||
package com.baeldung.charencoding.controller;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.web.filter.CharacterEncodingFilter;
|
||||
|
||||
class CharEncodingCheckControllerTest {
|
||||
|
||||
@Test
|
||||
void whenCharEncodingFilter_thenVerifyEncoding() throws ServletException, IOException {
|
||||
HttpServletRequest request = mock(HttpServletRequest.class);
|
||||
HttpServletResponse response = mock(HttpServletResponse.class);
|
||||
FilterChain chain = mock(FilterChain.class);
|
||||
|
||||
CharacterEncodingFilter filter = new CharacterEncodingFilter();
|
||||
filter.setEncoding("UTF-8");
|
||||
filter.setForceEncoding(true);
|
||||
|
||||
filter.doFilter(request, response, chain);
|
||||
|
||||
verify(request).setCharacterEncoding("UTF-8");
|
||||
verify(response).setCharacterEncoding("UTF-8");
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue