### Question:
ESProxyFilter implements Filter { protected URI getEsNodeURI() throws ServletException { Client client = getElasticsearchClientService().getClient(); if (client == null) throw new ServletException("Elasticsearch client for " + (useStatsClient ? "stats" : "search") + " cluster is not available"); NodesInfoResponse nir = client.admin().cluster().nodesInfo(new NodesInfoRequest().http(true)).actionGet(); NodeInfo[] nis = nir.getNodes(); if (nis == null || nis.length == 0) { throw new ServletException("Elasticsearch node is not available"); } NodeInfo ni = nir.getAt(0); HttpInfo hi = ni.getHttp(); if (hi == null) { throw new ServletException("HTTP Connector is not available for Elasticsearch node " + ni.getNode().getName()); } TransportAddress ta = hi.getAddress().publishAddress(); if (ta == null || !(ta instanceof InetSocketTransportAddress)) { throw new ServletException("HTTP Connector is not available for Elasticsearch node " + ni.getNode().getName()); } InetSocketTransportAddress a = (InetSocketTransportAddress) ta; String url = "http: try { return new URI(url); } catch (URISyntaxException e) { throw new ServletException("Generated ES URL is invalid: " + url); } }  @Override void init(FilterConfig filterConfig); @Override void destroy(); @Override void doFilter(ServletRequest request, ServletResponse response, FilterChain chain);  }### Answer:
@Test(expected = ServletException.class) public void getEsNodeURI() throws ServletException { ESProxyFilter tested = getTested(); tested.searchClientService = Mockito.mock(SearchClientService.class); Mockito.when(tested.searchClientService.getClient()).thenReturn(null); tested.getEsNodeURI(); }