Skip to content

Commit 7b2142e

Browse files
committed
chore: commonify settingsarr
Signed-off-by: Mohammad Hasnain <[email protected]>
1 parent a1ff3c5 commit 7b2142e

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

modules/analysis-common/src/test/java/org/opensearch/analysis/common/CompoundAnalysisTests.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.apache.lucene.analysis.Analyzer;
3636
import org.apache.lucene.analysis.TokenStream;
3737
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
38+
import org.junit.Before;
3839
import org.opensearch.Version;
3940
import org.opensearch.cluster.metadata.IndexMetadata;
4041
import org.opensearch.common.settings.Settings;
@@ -66,9 +67,16 @@
6667
import static org.hamcrest.Matchers.instanceOf;
6768

6869
public class CompoundAnalysisTests extends OpenSearchTestCase {
70+
71+
Settings[] settingsArr;
72+
73+
@Before
74+
public void initialize() throws IOException {
75+
this.settingsArr = getSettingsArr();
76+
}
77+
6978
public void testDefaultsCompoundAnalysis() throws Exception {
70-
Settings[] settingsArr = getSettingsArr();
71-
for (Settings settings : settingsArr) {
79+
for (Settings settings : this.settingsArr) {
7280
IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("test", settings);
7381
AnalysisModule analysisModule = createAnalysisModule(settings);
7482
TokenFilterFactory filterFactory = analysisModule.getAnalysisRegistry().buildTokenFilterFactories(idxSettings).get("dict_dec");
@@ -77,8 +85,7 @@ public void testDefaultsCompoundAnalysis() throws Exception {
7785
}
7886

7987
public void testDictionaryDecompounder() throws Exception {
80-
Settings[] settingsArr = getSettingsArr();
81-
for (Settings settings : settingsArr) {
88+
for (Settings settings : this.settingsArr) {
8289
List<String> terms = analyze(settings, "decompoundingAnalyzer", "donaudampfschiff spargelcremesuppe");
8390
MatcherAssert.assertThat(terms.size(), equalTo(8));
8491
MatcherAssert.assertThat(
@@ -91,8 +98,7 @@ public void testDictionaryDecompounder() throws Exception {
9198
// Hyphenation Decompounder tests mimic the behavior of lucene tests
9299
// lucene/analysis/common/src/test/org/apache/lucene/analysis/compound/TestHyphenationCompoundWordTokenFilterFactory.java
93100
public void testHyphenationDecompounder() throws Exception {
94-
Settings[] settingsArr = getSettingsArr();
95-
for (Settings settings : settingsArr) {
101+
for (Settings settings : this.settingsArr) {
96102
List<String> terms = analyze(settings, "hyphenationAnalyzer", "min veninde som er lidt af en læsehest");
97103
MatcherAssert.assertThat(terms.size(), equalTo(10));
98104
MatcherAssert.assertThat(terms, hasItems("min", "veninde", "som", "er", "lidt", "af", "en", "læsehest", "læse", "hest"));
@@ -102,8 +108,7 @@ public void testHyphenationDecompounder() throws Exception {
102108
// Hyphenation Decompounder tests mimic the behavior of lucene tests
103109
// lucene/analysis/common/src/test/org/apache/lucene/analysis/compound/TestHyphenationCompoundWordTokenFilterFactory.java
104110
public void testHyphenationDecompounderNoSubMatches() throws Exception {
105-
Settings[] settingsArr = getSettingsArr();
106-
for (Settings settings : settingsArr) {
111+
for (Settings settings : this.settingsArr) {
107112
List<String> terms = analyze(settings, "hyphenationAnalyzerNoSubMatches", "basketballkurv");
108113
MatcherAssert.assertThat(terms.size(), equalTo(3));
109114
MatcherAssert.assertThat(terms, hasItems("basketballkurv", "basketball", "kurv"));

0 commit comments

Comments
 (0)