@Override
    public void commence(final HttpServletRequest httpServletRequest, final HttpServletResponse httpServletResponse,
                         final AuthenticationException authenticationException) throws IOException {

        httpServletResponse.setContentType(MediaType.APPLICATION_JSON_VALUE);
        httpServletResponse.setStatus(HttpStatus.UNAUTHORIZED.value());

        final CustomError customError = CustomError.builder()
                .header(CustomError.Header.AUTH_ERROR.getName())
                .httpStatus(HttpStatus.UNAUTHORIZED)
                .isSuccess(false)
                .build();

        final String responseBody = OBJECT_MAPPER
                .writer(DateFormat.getDateInstance())
                .writeValueAsString(customError);

        httpServletResponse.getOutputStream()
                .write(responseBody.getBytes());

    }
@Test
    public void testCommence() throws IOException {
        // Mock objects
        HttpServletRequest httpServletRequest = mock(HttpServletRequest.class);
        HttpServletResponse httpServletResponse = mock(HttpServletResponse.class);
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        ServletOutputStream servletOutputStream = new ServletOutputStream() {
            @Override
            public void write(int b) throws IOException {
                byteArrayOutputStream.write(b);
            }

            @Override
            public boolean isReady() {
                return true;
            }

            @Override
            public void setWriteListener(WriteListener writeListener) {
                // No-op
            }
        };

        // Set up the mocks
        when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream);

        // Call the method to test
        customAuthenticationEntryPoint.commence(httpServletRequest, httpServletResponse, new AuthenticationException("Test") {});

        // Verify that the response status was set
        verify(httpServletResponse).setStatus(HttpStatus.UNAUTHORIZED.value());
        verify(httpServletResponse).setContentType(MediaType.APPLICATION_JSON_VALUE);

        // Convert the response to a string and verify the content
        String responseBody = byteArrayOutputStream.toString(); // Use ByteArrayOutputStream
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.registerModule(new JavaTimeModule());
        CustomError expectedCustomError = CustomError.builder()
                .header(CustomError.Header.AUTH_ERROR.getName())
                .httpStatus(HttpStatus.UNAUTHORIZED)
                .isSuccess(false)
                .build();
        String expectedResponseBody = objectMapper.writeValueAsString(expectedCustomError);

        // Parse the JSON response and expected response
        JsonNode responseNode = objectMapper.readTree(responseBody);
        JsonNode expectedNode = objectMapper.readTree(expectedResponseBody);

        // Extract and format the 'time' fields
        String responseTime = responseNode.get("time").asText();
        JsonNode expectedTimeNode = expectedNode.get("time");

        // Define a DateTimeFormatter to compare up to minutes
        DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME;

        // Parse the time strings into LocalDateTime objects
        LocalDateTime responseDateTime = LocalDateTime.parse(responseTime, formatter);
        LocalDateTime expectedDateTime = convertArrayToLocalDateTime(expectedTimeNode);

        // Truncate to minutes for comparison
        responseDateTime = responseDateTime.truncatedTo(ChronoUnit.MINUTES);
        expectedDateTime = expectedDateTime.truncatedTo(ChronoUnit.MINUTES);

        // Compare only the date and time up to minutes
        assertEquals(expectedDateTime, responseDateTime);
    }