Use expectThrows in JsonSettingsLoaderTests

This commit refactors the unit tests in JsonSettingsLoaderTests to use
exceptThrows for simplification.
This commit is contained in:
Jason Tedor 2016-03-23 21:40:11 -04:00
parent 7841b439ec
commit f9500b1d6a
1 changed files with 10 additions and 16 deletions

View File

@ -49,22 +49,16 @@ public class JsonSettingsLoaderTests extends ESTestCase {
}
public void testDuplicateKeysThrowsException() {
String json = "{\"foo\":\"bar\",\"foo\":\"baz\"}";
try {
settingsBuilder()
.loadFromSource(json)
.build();
fail("expected exception");
} catch (SettingsException e) {
assertEquals(e.getCause().getClass(), ElasticsearchParseException.class);
assertThat(
e.toString(),
containsString("duplicate settings key [foo] " +
"found at line number [1], " +
"column number [20], " +
"previous value [bar], " +
"current value [baz]"));
}
final String json = "{\"foo\":\"bar\",\"foo\":\"baz\"}";
final SettingsException e = expectThrows(SettingsException.class, () -> settingsBuilder().loadFromSource(json).build());
assertEquals(e.getCause().getClass(), ElasticsearchParseException.class);
assertThat(
e.toString(),
containsString("duplicate settings key [foo] " +
"found at line number [1], " +
"column number [20], " +
"previous value [bar], " +
"current value [baz]"));
}
public void testNullValuedSettingThrowsException() {