diff --git a/logstash-core/spec/logstash/settings/string_spec.rb b/logstash-core/spec/logstash/settings/string_spec.rb index 4ce66795dad..b82fd723056 100644 --- a/logstash-core/spec/logstash/settings/string_spec.rb +++ b/logstash-core/spec/logstash/settings/string_spec.rb @@ -18,6 +18,7 @@ require "spec_helper" require "logstash/settings" +# Mirrored in java class org.logstash.settings.StringSettingTest describe LogStash::Setting::StringSetting do let(:possible_values) { ["a", "b", "c"] } subject { described_class.new("mytext", possible_values.first, true, possible_values) } diff --git a/logstash-core/src/test/java/org/logstash/settings/BooleanTest.java b/logstash-core/src/test/java/org/logstash/settings/BooleanTest.java index 0886f6710b8..c99f6552b70 100644 --- a/logstash-core/src/test/java/org/logstash/settings/BooleanTest.java +++ b/logstash-core/src/test/java/org/logstash/settings/BooleanTest.java @@ -1,3 +1,22 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package org.logstash.settings; import org.junit.Assert; diff --git a/logstash-core/src/test/java/org/logstash/settings/StringSettingTest.java b/logstash-core/src/test/java/org/logstash/settings/StringSettingTest.java new file mode 100644 index 00000000000..9613e89e784 --- /dev/null +++ b/logstash-core/src/test/java/org/logstash/settings/StringSettingTest.java @@ -0,0 +1,50 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.logstash.settings; + +import org.junit.Before; +import org.junit.Test; + +import java.util.List; + +import static org.junit.Assert.assertEquals; + +// Mirrored from logstash-core/spec/logstash/settings/string_spec.rb +public class StringSettingTest { + + private static final List POSSIBLE_VALUES = List.of("a", "b", "c"); + private StringSetting sut; + + @Before + public void setUp() throws Exception { + sut = new StringSetting("mytext", POSSIBLE_VALUES.iterator().next(), true, POSSIBLE_VALUES); + } + + @Test(expected = IllegalArgumentException.class) + public void whenSetValueNotPresentInPossibleValuesThenThrowAnError() { + sut.set("d"); + } + + @Test + public void whenSetValuePresentInPossibleValuesThenSetValue() { + sut.set("a"); + + assertEquals("a", sut.value()); + } +} \ No newline at end of file