ElasticSearchUtil { public static boolean isResponseEmpty(SearchResponse searchResponse) { if (searchResponse == null || searchResponse.getHits() == null || searchResponse.getHits().getHits() == null || searchResponse.getHits().getHits().length == 0) { return true; } return false; } private  ElasticSearchUtil(); static boolean isResponseEmpty(SearchResponse searchResponse);  }
@Test public void doTest() { SearchResponse response = Mockito.mock(SearchResponse.class); SearchHits hits = Mockito.mock(SearchHits.class); Assert.assertTrue(ElasticSearchUtil.isResponseEmpty(null)); Mockito.when(response.getHits()).thenReturn(null); Assert.assertTrue(ElasticSearchUtil.isResponseEmpty(response)); Mockito.reset(response); Mockito.when(hits.getHits()).thenReturn(null); Mockito.when(response.getHits()).thenReturn(hits); Assert.assertTrue(ElasticSearchUtil.isResponseEmpty(response)); Mockito.reset(response, hits); Mockito.when(hits.getHits()).thenReturn(new SearchHit[0]); Mockito.when(response.getHits()).thenReturn(hits); Assert.assertTrue(ElasticSearchUtil.isResponseEmpty(response)); Mockito.reset(response, hits); Mockito.when(hits.getHits()).thenReturn(new SearchHit[10]); Mockito.when(response.getHits()).thenReturn(hits); Assert.assertFalse(ElasticSearchUtil.isResponseEmpty(response)); }