From 47e52044e452073c3205475515bee87168360812 Mon Sep 17 00:00:00 2001 From: javanna Date: Thu, 2 Jun 2016 11:30:09 +0200 Subject: [PATCH] [TEST] add setHosts test and rename RestClientBuilderTests to RestClientTests --- ...BuilderTests.java => RestClientTests.java} | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) rename client/src/test/java/org/elasticsearch/client/{RestClientBuilderTests.java => RestClientTests.java} (75%) diff --git a/client/src/test/java/org/elasticsearch/client/RestClientBuilderTests.java b/client/src/test/java/org/elasticsearch/client/RestClientTests.java similarity index 75% rename from client/src/test/java/org/elasticsearch/client/RestClientBuilderTests.java rename to client/src/test/java/org/elasticsearch/client/RestClientTests.java index 1d73db6ec37..f6a297eb145 100644 --- a/client/src/test/java/org/elasticsearch/client/RestClientBuilderTests.java +++ b/client/src/test/java/org/elasticsearch/client/RestClientTests.java @@ -31,7 +31,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -public class RestClientBuilderTests extends LuceneTestCase { +public class RestClientTests extends LuceneTestCase { public void testBuild() throws IOException { try { @@ -105,4 +105,33 @@ public class RestClientBuilderTests extends LuceneTestCase { assertNotNull(restClient); } } + + public void testSetNodes() throws IOException { + try (RestClient restClient = RestClient.builder().setHosts(new HttpHost("localhost", 9200)).build()) { + try { + restClient.setHosts((HttpHost[]) null); + fail("setHosts should have failed"); + } catch (IllegalArgumentException e) { + assertEquals("hosts must not be null nor empty", e.getMessage()); + } + try { + restClient.setHosts(); + fail("setHosts should have failed"); + } catch (IllegalArgumentException e) { + assertEquals("hosts must not be null nor empty", e.getMessage()); + } + try { + restClient.setHosts((HttpHost) null); + fail("setHosts should have failed"); + } catch (NullPointerException e) { + assertEquals("host cannot be null", e.getMessage()); + } + try { + restClient.setHosts(new HttpHost("localhost", 9200), null, new HttpHost("localhost", 9201)); + fail("setHosts should have failed"); + } catch (NullPointerException e) { + assertEquals("host cannot be null", e.getMessage()); + } + } + } }