@Override
  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    final String userAgentString = ((HttpServletRequest) request).getHeader(HttpHeaders.USER_AGENT);

    UserAgent userAgent;
    try {
      userAgent = UserAgentUtil.parseUserAgentString(userAgentString);
    } catch (final UnrecognizedUserAgentException e) {
      userAgent = null;
    }

    if (shouldBlock(userAgent)) {
      ((HttpServletResponse) response).sendError(499);
    } else {
      chain.doFilter(request, response);
    }
  }
@Test
  void testEmptyMap() throws IOException, ServletException {
    // We're happy as long as there's no exception
    final DynamicConfigurationManager dynamicConfigurationManager = mock(DynamicConfigurationManager.class);
    final DynamicConfiguration dynamicConfiguration = mock(DynamicConfiguration.class);
    final DynamicRemoteDeprecationConfiguration emptyConfiguration = new DynamicRemoteDeprecationConfiguration();

    when(dynamicConfigurationManager.getConfiguration()).thenReturn(dynamicConfiguration);
    when(dynamicConfiguration.getRemoteDeprecationConfiguration()).thenReturn(emptyConfiguration);

    final RemoteDeprecationFilter filter = new RemoteDeprecationFilter(dynamicConfigurationManager);

    final HttpServletRequest servletRequest = mock(HttpServletRequest.class);
    final HttpServletResponse servletResponse = mock(HttpServletResponse.class);
    final FilterChain filterChain = mock(FilterChain.class);

    when(servletRequest.getHeader("UserAgent")).thenReturn("Signal-Android/4.68.3");

    filter.doFilter(servletRequest, servletResponse, filterChain);

    verify(filterChain).doFilter(servletRequest, servletResponse);
    verify(servletResponse, never()).sendError(anyInt());
  }