Skip to content

Commit

Permalink
Mirrored rspec test for StringSetting into JUnit
Browse files Browse the repository at this point in the history
  • Loading branch information
andsel committed Nov 12, 2024
1 parent 28605e4 commit 91e2048
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
1 change: 1 addition & 0 deletions logstash-core/spec/logstash/settings/string_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
19 changes: 19 additions & 0 deletions logstash-core/src/test/java/org/logstash/settings/BooleanTest.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> 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());
}
}

0 comments on commit 91e2048

Please sign in to comment.