IndexSettings should not be Null in Mapper.BuildContext

Rename method name
Change validation

Closes #20174
This commit is contained in:
Jun Ohtani 2016-10-14 17:00:06 +09:00
parent 75c9e4f418
commit ddced5df1a
2 changed files with 7 additions and 8 deletions

View File

@ -39,7 +39,7 @@ public abstract class Mapper implements ToXContent, Iterable<Mapper> {
private final ContentPath contentPath;
public BuilderContext(Settings indexSettings, ContentPath contentPath) {
assert indexSettings != null;
Objects.requireNonNull(indexSettings, "indexSettings is required");
this.contentPath = contentPath;
this.indexSettings = indexSettings;
}

View File

@ -24,20 +24,19 @@ import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.test.ESTestCase;
import static org.hamcrest.Matchers.equalTo;
public class MapperTests extends ESTestCase {
public void testBuilderContextWithIndexSettings() {
public void testSuccessfulBuilderContext() {
Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build();
Mapper.BuilderContext context = new Mapper.BuilderContext(settings, new ContentPath(1));
ContentPath contentPath = new ContentPath(1);
Mapper.BuilderContext context = new Mapper.BuilderContext(settings, contentPath);
assertNotNull(context.indexSettings());
assertThat(context.indexSettings(), equalTo(settings));
assertEquals(settings, context.indexSettings());
assertEquals(contentPath, context.path());
}
public void testBuilderContextWithIndexSettingsAsNull() {
AssertionError e = expectThrows(AssertionError.class, () -> new Mapper.BuilderContext(null, new ContentPath(1)));
NullPointerException e = expectThrows(NullPointerException.class, () -> new Mapper.BuilderContext(null, new ContentPath(1)));
}