### Question:
BulkProcessorObjectFactory implements ClientObjectFactory<TransportClient, BulkRequest> { @Override public TransportClient createClient() { if (client == null) { TransportClient client = getClientProvider().createClient(); for (String serverUri : serverUris) { try { String host = uriParser.getHost(serverUri); int port = uriParser.getPort(serverUri); client.addTransportAddress(new TransportAddress(InetAddress.getByName(host), port)); } catch (UnknownHostException e) { throw new ConfigurationException(e.getMessage()); } } this.client = client; } return client; } protected  BulkProcessorObjectFactory(Collection<String> serverUris, Auth auth); protected  BulkProcessorObjectFactory(Collection<String> serverUris, Auth auth, ClientSettings clientSettings); @Override Collection<String> getServerList(); @Override TransportClient createClient(); @Override Function<BulkRequest, Boolean> createBatchListener(FailoverPolicy failoverPolicy); @Override Function<BulkRequest, Boolean> createFailureHandler(FailoverPolicy failover); @Override BatchOperations<BulkRequest> createBatchOperations(); @Override void execute(IndexTemplate indexTemplate); @Override void addOperation(Operation operation); @PluginBuilderFactory static Builder newBuilder();  }### Answer:
@Test public void throwsIfUnknownHostWasProvided() { Builder builder = createTestObjectFactoryBuilder(); builder.withServerUris("http: BulkProcessorObjectFactory factory = builder.build(); expectedException.expect(ConfigurationException.class); expectedException.expectMessage("unknowntesthost"); factory.createClient(); }
@Test public void clientIsCalledWhenBatchItemIsAdded() { Builder builder = createTestObjectFactoryBuilder(); ClientObjectFactory<TransportClient, BulkRequest> config = spy(builder.build()); Settings settings = Settings.builder().build(); TransportClient client = spy(new PreBuiltTransportClient(settings)); client.addTransportAddress(new TransportAddress(new InetSocketAddress(9999))); when(config.createClient()).thenReturn(client); FailoverPolicy failoverPolicy = spy(new NoopFailoverPolicy()); BulkProcessorFactory bulkProcessorFactory = new BulkProcessorFactory(); BatchEmitter batchEmitter = bulkProcessorFactory.createInstance( 1, 100, config, failoverPolicy); String payload1 = "test1"; ActionRequest testRequest = createTestRequest(payload1); batchEmitter.add(testRequest); ArgumentCaptor<BulkRequest> captor = ArgumentCaptor.forClass(BulkRequest.class); verify(client, times(1)).bulk(captor.capture(), Mockito.any()); assertEquals(payload1, new BulkRequestIntrospector().items(captor.getValue()).iterator().next()); }