1+ /*
2+ * Licensed to Elasticsearch B.V. under one or more contributor
3+ * license agreements. See the NOTICE file distributed with
4+ * this work for additional information regarding copyright
5+ * ownership. Elasticsearch B.V. licenses this file to you under
6+ * the Apache License, Version 2.0 (the "License"); you may
7+ * not use this file except in compliance with the License.
8+ * You may obtain a copy of the License at
9+ *
10+ * http://www.apache.org/licenses/LICENSE-2.0
11+ *
12+ * Unless required by applicable law or agreed to in writing,
13+ * software distributed under the License is distributed on an
14+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+ * KIND, either express or implied. See the License for the
16+ * specific language governing permissions and limitations
17+ * under the License.
18+ */
19+ package org .logstash .settings ;
20+
21+ import org .junit .Before ;
22+ import org .junit .Test ;
23+
24+ import java .util .List ;
25+
26+ import static org .junit .Assert .assertEquals ;
27+
28+ // Mirrored from logstash-core/spec/logstash/settings/string_spec.rb
29+ public class StringSettingTest {
30+
31+ private static final List <String > POSSIBLE_VALUES = List .of ("a" , "b" , "c" );
32+ private StringSetting sut ;
33+
34+ @ Before
35+ public void setUp () throws Exception {
36+ sut = new StringSetting ("mytext" , POSSIBLE_VALUES .iterator ().next (), true , POSSIBLE_VALUES );
37+ }
38+
39+ @ Test (expected = IllegalArgumentException .class )
40+ public void whenSetValueNotPresentInPossibleValuesThenThrowAnError () {
41+ sut .set ("d" );
42+ }
43+
44+ @ Test
45+ public void whenSetValuePresentInPossibleValuesThenSetValue () {
46+ sut .set ("a" );
47+
48+ assertEquals ("a" , sut .value ());
49+ }
50+ }
0 commit comments