diff --git a/dsms-engine-application/src/test/java/com/dsms/common/handler/AuthenticationEntryPointImplTest.java b/dsms-engine-application/src/test/java/com/dsms/common/handler/AuthenticationEntryPointImplTest.java new file mode 100644 index 0000000000000000000000000000000000000000..ab6e54169a9bcb4cc3f49aa1b21c1f81610ef18b --- /dev/null +++ b/dsms-engine-application/src/test/java/com/dsms/common/handler/AuthenticationEntryPointImplTest.java @@ -0,0 +1,30 @@ +package com.dsms.common.handler; + +import com.dsms.common.constant.ResultCode; +import java.io.PrintWriter; +import java.nio.charset.StandardCharsets; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import lombok.SneakyThrows; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; +import org.springframework.security.authentication.BadCredentialsException; + +class AuthenticationEntryPointImplTest { + + @Test + @SneakyThrows + void commence() { + HttpServletRequest request = Mockito.mock(HttpServletRequest.class); + HttpServletResponse response = Mockito.mock(HttpServletResponse.class); + PrintWriter printWriter = Mockito.mock(PrintWriter.class); + Mockito.when(response.getWriter()).thenReturn(printWriter); + + AuthenticationEntryPointImpl authenticationEntryPoint = new AuthenticationEntryPointImpl(); + + authenticationEntryPoint.commence(request, response, new BadCredentialsException("bad credentials")); + + Mockito.verify(response).setStatus(ResultCode.UNAUTHORIZED.getCode()); + Mockito.verify(response).setCharacterEncoding(StandardCharsets.UTF_8.displayName()); + } +} \ No newline at end of file