use expectThrows instead of manually testing exception

This commit is contained in:
David Pilato 2017-01-26 17:33:26 +01:00
parent d97750b52c
commit 6e7aee0c5a
1 changed files with 4 additions and 5 deletions

View File

@ -197,12 +197,11 @@ public class Ec2DiscoveryTests extends ESTestCase {
Settings nodeSettings = Settings.builder() Settings nodeSettings = Settings.builder()
.put(DISCOVERY_EC2.HOST_TYPE_SETTING.getKey(), "does_not_exist") .put(DISCOVERY_EC2.HOST_TYPE_SETTING.getKey(), "does_not_exist")
.build(); .build();
try {
IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, () -> {
buildDynamicNodes(nodeSettings, 1); buildDynamicNodes(nodeSettings, 1);
fail("Expected IllegalArgumentException"); });
} catch (IllegalArgumentException e) { assertThat(exception.getMessage(), containsString("does_not_exist is unknown for discovery.ec2.host_type"));
assertThat(e.getMessage(), containsString("does_not_exist is unknown for discovery.ec2.host_type"));
}
} }
public void testFilterByTags() throws InterruptedException { public void testFilterByTags() throws InterruptedException {