MetronSolrClient extends CloudSolrClient { public void createCollection(String name, int numShards, int replicationFactor) throws IOException, SolrServerException { if (!listCollections().contains(name)) { request(getCreateCollectionsRequest(name, numShards, replicationFactor)); } } MetronSolrClient(String zkHost);  MetronSolrClient(String zkHost, Map<String, Object> solrHttpConfig); static SolrParams toSolrProps(Map<String, Object> config); void createCollection(String name, int numShards, int replicationFactor); QueryRequest getCreateCollectionsRequest(String name, int numShards, int replicationFactor); @SuppressWarnings("unchecked") List<String> listCollections(); QueryRequest getListCollectionsRequest();  }
@Test public void testClient() throws Exception { final String collection = "metron"; String zookeeperUrl = "zookeeperUrl"; MetronSolrClient metronSolrClient = Mockito.spy(new MetronSolrClient(zookeeperUrl)); Mockito.doReturn(new NamedList<Object>() {{ add("collections", new ArrayList<String>() {{ add(collection); }}); }}).when(metronSolrClient).request(argThat(new CollectionRequestMatcher(CollectionParams.CollectionAction.LIST.name())), isNull()); metronSolrClient.createCollection(collection, 1, 1); verify(metronSolrClient, times(1)).request(argThat(new CollectionRequestMatcher(CollectionParams.CollectionAction.LIST.name())), isNull()); verify(metronSolrClient, times(0)).request(argThat(new CollectionRequestMatcher(CollectionParams.CollectionAction.CREATE.name())), isNull()); metronSolrClient = Mockito.spy(new MetronSolrClient(zookeeperUrl)); Mockito.doReturn(new NamedList<Object>() {{ add("collections", new ArrayList<String>()); }}).when(metronSolrClient).request(argThat(new CollectionRequestMatcher(CollectionParams.CollectionAction.LIST.name())), isNull()); Mockito.doReturn(new NamedList<>()).when(metronSolrClient).request(argThat(new CollectionRequestMatcher(CollectionParams.CollectionAction.CREATE.name())), isNull()); metronSolrClient.createCollection(collection, 1, 1); verify(metronSolrClient, times(1)).request(argThat(new CollectionRequestMatcher(CollectionParams.CollectionAction.LIST.name())), isNull()); verify(metronSolrClient, times(1)).request(argThat(new CollectionRequestMatcher(CollectionParams.CollectionAction.CREATE.name())), isNull()); }