Skip to content

Commit d58fbdd

Browse files
committed
Tidy up some collections code
1 parent 7f2ece7 commit d58fbdd

File tree

3 files changed

+18
-22
lines changed

3 files changed

+18
-22
lines changed

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authz/accesscontrol/DocumentSubsetBitsetCacheTests.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import java.util.Collections;
5555
import java.util.IdentityHashMap;
5656
import java.util.List;
57+
import java.util.Map;
5758
import java.util.Set;
5859
import java.util.concurrent.CountDownLatch;
5960
import java.util.concurrent.ExecutorService;
@@ -62,8 +63,6 @@
6263
import java.util.concurrent.atomic.AtomicInteger;
6364
import java.util.concurrent.atomic.AtomicReference;
6465

65-
import static java.util.Collections.emptyList;
66-
import static java.util.Collections.emptyMap;
6766
import static org.hamcrest.Matchers.equalTo;
6867
import static org.hamcrest.Matchers.is;
6968
import static org.hamcrest.Matchers.not;
@@ -600,7 +599,7 @@ private TestIndexContext testIndex(MappingLookup mappingLookup, Client client) t
600599
null,
601600
() -> true,
602601
null,
603-
emptyMap(),
602+
Map.of(),
604603
MapperMetrics.NOOP
605604
);
606605

@@ -630,7 +629,7 @@ private void runTestOnIndices(int numberIndices, CheckedConsumer<List<TestIndexC
630629
types.add(new MockFieldMapper(new KeywordFieldMapper.KeywordFieldType("dne-" + i)));
631630
}
632631

633-
MappingLookup mappingLookup = MappingLookup.fromMappers(Mapping.EMPTY, types, emptyList());
632+
MappingLookup mappingLookup = MappingLookup.fromMappers(Mapping.EMPTY, types, List.of());
634633

635634
final Client client = mock(Client.class);
636635
when(client.settings()).thenReturn(Settings.EMPTY);

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authz/accesscontrol/SecurityIndexReaderWrapperIntegrationTests.java

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,11 @@
6464
import java.util.Arrays;
6565
import java.util.HashSet;
6666
import java.util.List;
67+
import java.util.Map;
6768
import java.util.Set;
6869
import java.util.concurrent.Executors;
6970
import java.util.stream.Collectors;
7071

71-
import static java.util.Collections.emptyList;
72-
import static java.util.Collections.emptyMap;
73-
import static java.util.Collections.singleton;
74-
import static java.util.Collections.singletonMap;
7572
import static org.elasticsearch.xpack.core.security.SecurityField.DOCUMENT_LEVEL_SECURITY_FEATURE;
7673
import static org.hamcrest.Matchers.containsInAnyOrder;
7774
import static org.hamcrest.Matchers.equalTo;
@@ -115,7 +112,7 @@ public void testDLS() throws Exception {
115112
null,
116113
() -> true,
117114
null,
118-
emptyMap(),
115+
Map.of(),
119116
MapperMetrics.NOOP
120117
);
121118
SearchExecutionContext searchExecutionContext = spy(realSearchExecutionContext);
@@ -172,7 +169,7 @@ public void testDLS() throws Exception {
172169
String termQuery = "{\"term\": {\"field\": \"" + values[i] + "\"} }";
173170
IndicesAccessControl.IndexAccessControl indexAccessControl = new IndicesAccessControl.IndexAccessControl(
174171
FieldPermissions.DEFAULT,
175-
DocumentPermissions.filteredBy(singleton(new BytesArray(termQuery)))
172+
DocumentPermissions.filteredBy(Set.of(new BytesArray(termQuery)))
176173
);
177174
SecurityIndexReaderWrapper wrapper = new SecurityIndexReaderWrapper(
178175
s -> searchExecutionContext,
@@ -184,7 +181,7 @@ public void testDLS() throws Exception {
184181

185182
@Override
186183
protected IndicesAccessControl getIndicesAccessControl() {
187-
return new IndicesAccessControl(true, singletonMap("_index", indexAccessControl));
184+
return new IndicesAccessControl(true, Map.of("_index", indexAccessControl));
188185
}
189186
};
190187

@@ -237,9 +234,9 @@ public void testDLSWithLimitedPermissions() throws Exception {
237234
FieldPermissions.DEFAULT,
238235
DocumentPermissions.filteredBy(queries)
239236
);
240-
queries = singleton(new BytesArray("{\"terms\" : { \"f1\" : [\"fv11\", \"fv21\", \"fv31\"] } }"));
237+
queries = Set.of(new BytesArray("{\"terms\" : { \"f1\" : [\"fv11\", \"fv21\", \"fv31\"] } }"));
241238
if (restrictiveLimitedIndexPermissions) {
242-
queries = singleton(new BytesArray("{\"terms\" : { \"f1\" : [\"fv11\", \"fv31\"] } }"));
239+
queries = Set.of(new BytesArray("{\"terms\" : { \"f1\" : [\"fv11\", \"fv31\"] } }"));
243240
}
244241
IndicesAccessControl.IndexAccessControl limitedIndexAccessControl = new IndicesAccessControl.IndexAccessControl(
245242
FieldPermissions.DEFAULT,
@@ -271,7 +268,7 @@ public void testDLSWithLimitedPermissions() throws Exception {
271268
null,
272269
() -> true,
273270
null,
274-
emptyMap(),
271+
Map.of(),
275272
MapperMetrics.NOOP
276273
);
277274
SearchExecutionContext searchExecutionContext = spy(realSearchExecutionContext);
@@ -289,13 +286,13 @@ public void testDLSWithLimitedPermissions() throws Exception {
289286

290287
@Override
291288
protected IndicesAccessControl getIndicesAccessControl() {
292-
IndicesAccessControl indicesAccessControl = new IndicesAccessControl(true, singletonMap("_index", indexAccessControl));
289+
IndicesAccessControl indicesAccessControl = new IndicesAccessControl(true, Map.of("_index", indexAccessControl));
293290
if (noFilteredIndexPermissions) {
294291
return indicesAccessControl;
295292
}
296293
IndicesAccessControl limitedByIndicesAccessControl = new IndicesAccessControl(
297294
true,
298-
singletonMap("_index", limitedIndexAccessControl)
295+
Map.of("_index", limitedIndexAccessControl)
299296
);
300297
return indicesAccessControl.limitIndicesAccessControl(limitedByIndicesAccessControl);
301298
}
@@ -494,7 +491,7 @@ public void testDLSWithNestedDocs() throws Exception {
494491
protected IndicesAccessControl getIndicesAccessControl() {
495492
IndicesAccessControl indicesAccessControl = new IndicesAccessControl(
496493
true,
497-
singletonMap(indexSettings().getIndex().getName(), indexAccessControl)
494+
Map.of(indexSettings().getIndex().getName(), indexAccessControl)
498495
);
499496
return indicesAccessControl;
500497
}
@@ -522,6 +519,6 @@ protected IndicesAccessControl getIndicesAccessControl() {
522519

523520
private static MappingLookup createMappingLookup(List<MappedFieldType> concreteFields) {
524521
List<FieldMapper> mappers = concreteFields.stream().map(MockFieldMapper::new).collect(Collectors.toList());
525-
return MappingLookup.fromMappers(Mapping.EMPTY, mappers, emptyList());
522+
return MappingLookup.fromMappers(Mapping.EMPTY, mappers, List.of());
526523
}
527524
}

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authz/accesscontrol/SecurityIndexReaderWrapperUnitTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030
import org.junit.After;
3131
import org.junit.Before;
3232

33-
import java.util.Arrays;
3433
import java.util.Collections;
3534
import java.util.HashSet;
35+
import java.util.List;
36+
import java.util.Map;
3637
import java.util.Set;
3738

38-
import static java.util.Collections.singletonMap;
3939
import static org.elasticsearch.xpack.core.security.SecurityField.DOCUMENT_LEVEL_SECURITY_FEATURE;
4040
import static org.hamcrest.Matchers.is;
4141
import static org.hamcrest.Matchers.sameInstance;
@@ -93,7 +93,7 @@ protected IndicesAccessControl getIndicesAccessControl() {
9393
new FieldPermissions(fieldPermissionDef(new String[] {}, null)),
9494
DocumentPermissions.allowAll()
9595
);
96-
return new IndicesAccessControl(true, singletonMap("_index", indexAccessControl));
96+
return new IndicesAccessControl(true, Map.of("_index", indexAccessControl));
9797
}
9898
};
9999

@@ -166,7 +166,7 @@ public void testFieldPermissionsWithFieldExceptions() throws Exception {
166166
deniedFields = META_FIELDS.toArray(new String[0]);
167167
assertResolved(
168168
new FieldPermissions(fieldPermissionDef(null, deniedFields)),
169-
new HashSet<>(Arrays.asList("foo", "bar", "_some_plugin_meta_field"))
169+
new HashSet<>(List.of("foo", "bar", "_some_plugin_meta_field"))
170170
);
171171

172172
// check we can add all fields with *

0 commit comments

Comments
 (0)