mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-01 16:39:11 +00:00
Tests: Remove class only used by tests
The `Integers` class was only used in tests (but lurked around in the src) and is not needed. Also replaced some lambda calls with their shorter equivalents. Original commit: elastic/x-pack-elasticsearch@a81a5c33d3
This commit is contained in:
parent
984b1b0dd1
commit
9d002430b5
@ -1,40 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
||||||
* or more contributor license agreements. Licensed under the Elastic License;
|
|
||||||
* you may not use this file except in compliance with the Elastic License.
|
|
||||||
*/
|
|
||||||
package org.elasticsearch.xpack.watcher.support;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.NoSuchElementException;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class Integers {
|
|
||||||
private Integers() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Iterable<Integer> asIterable(int[] values) {
|
|
||||||
Objects.requireNonNull(values);
|
|
||||||
return () -> new Iterator<Integer>() {
|
|
||||||
private int position = 0;
|
|
||||||
@Override
|
|
||||||
public boolean hasNext() {
|
|
||||||
return position < values.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Integer next() {
|
|
||||||
if (position < values.length) {
|
|
||||||
return values[position++];
|
|
||||||
} else {
|
|
||||||
throw new NoSuchElementException("position: " + position + ", length: " + values.length);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean contains(int[] values, final int value) {
|
|
||||||
return Arrays.stream(values).anyMatch(v -> v == value);
|
|
||||||
}
|
|
||||||
}
|
|
@ -13,14 +13,14 @@ import org.elasticsearch.common.xcontent.json.JsonXContent;
|
|||||||
import org.elasticsearch.xpack.watcher.support.Strings;
|
import org.elasticsearch.xpack.watcher.support.Strings;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||||
import static org.elasticsearch.xpack.watcher.support.Integers.asIterable;
|
|
||||||
import static org.elasticsearch.xpack.watcher.support.Integers.contains;
|
|
||||||
import static org.hamcrest.Matchers.arrayContaining;
|
import static org.hamcrest.Matchers.arrayContaining;
|
||||||
import static org.hamcrest.Matchers.arrayWithSize;
|
import static org.hamcrest.Matchers.arrayWithSize;
|
||||||
import static org.hamcrest.Matchers.containsString;
|
import static org.hamcrest.Matchers.containsString;
|
||||||
|
import static org.hamcrest.Matchers.hasItem;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
import static org.hamcrest.Matchers.notNullValue;
|
import static org.hamcrest.Matchers.notNullValue;
|
||||||
|
|
||||||
@ -147,7 +147,7 @@ public class HourlyScheduleTests extends ScheduleTestCase {
|
|||||||
int[] minutes = validMinutes();
|
int[] minutes = validMinutes();
|
||||||
XContentBuilder builder = jsonBuilder()
|
XContentBuilder builder = jsonBuilder()
|
||||||
.startObject()
|
.startObject()
|
||||||
.field("minute", asIterable(minutes))
|
.field("minute", minutes)
|
||||||
.endObject();
|
.endObject();
|
||||||
BytesReference bytes = builder.bytes();
|
BytesReference bytes = builder.bytes();
|
||||||
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
|
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
|
||||||
@ -155,8 +155,9 @@ public class HourlyScheduleTests extends ScheduleTestCase {
|
|||||||
HourlySchedule schedule = new HourlySchedule.Parser().parse(parser);
|
HourlySchedule schedule = new HourlySchedule.Parser().parse(parser);
|
||||||
assertThat(schedule, notNullValue());
|
assertThat(schedule, notNullValue());
|
||||||
assertThat(schedule.minutes().length, is(minutes.length));
|
assertThat(schedule.minutes().length, is(minutes.length));
|
||||||
|
List<Integer> ints = Arrays.stream(schedule.minutes()).mapToObj(Integer::valueOf).collect(Collectors.toList());
|
||||||
for (int i = 0; i < minutes.length; i++) {
|
for (int i = 0; i < minutes.length; i++) {
|
||||||
assertThat(contains(schedule.minutes(), minutes[i]), is(true));
|
assertThat(ints, hasItem(minutes[i]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,7 +165,7 @@ public class HourlyScheduleTests extends ScheduleTestCase {
|
|||||||
int[] minutes = invalidMinutes();
|
int[] minutes = invalidMinutes();
|
||||||
XContentBuilder builder = jsonBuilder()
|
XContentBuilder builder = jsonBuilder()
|
||||||
.startObject()
|
.startObject()
|
||||||
.field("minute", asIterable(minutes))
|
.field("minute", minutes)
|
||||||
.endObject();
|
.endObject();
|
||||||
BytesReference bytes = builder.bytes();
|
BytesReference bytes = builder.bytes();
|
||||||
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
|
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
|
||||||
@ -181,7 +182,7 @@ public class HourlyScheduleTests extends ScheduleTestCase {
|
|||||||
int[] minutes = validMinutes();
|
int[] minutes = validMinutes();
|
||||||
XContentBuilder builder = jsonBuilder()
|
XContentBuilder builder = jsonBuilder()
|
||||||
.startObject()
|
.startObject()
|
||||||
.field("minute", Arrays.stream(minutes).mapToObj(p -> Integer.toString(p)).collect(Collectors.toList()))
|
.field("minute", Arrays.stream(minutes).mapToObj(Integer::toString).collect(Collectors.toList()))
|
||||||
.endObject();
|
.endObject();
|
||||||
BytesReference bytes = builder.bytes();
|
BytesReference bytes = builder.bytes();
|
||||||
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
|
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
|
||||||
@ -189,8 +190,10 @@ public class HourlyScheduleTests extends ScheduleTestCase {
|
|||||||
HourlySchedule schedule = new HourlySchedule.Parser().parse(parser);
|
HourlySchedule schedule = new HourlySchedule.Parser().parse(parser);
|
||||||
assertThat(schedule, notNullValue());
|
assertThat(schedule, notNullValue());
|
||||||
assertThat(schedule.minutes().length, is(minutes.length));
|
assertThat(schedule.minutes().length, is(minutes.length));
|
||||||
|
|
||||||
|
List<Integer> ints = Arrays.stream(schedule.minutes()).mapToObj(Integer::valueOf).collect(Collectors.toList());
|
||||||
for (int i = 0; i < minutes.length; i++) {
|
for (int i = 0; i < minutes.length; i++) {
|
||||||
assertThat(contains(schedule.minutes(), minutes[i]), is(true));
|
assertThat(ints, hasItem(minutes[i]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,7 +201,7 @@ public class HourlyScheduleTests extends ScheduleTestCase {
|
|||||||
int[] minutes = invalidMinutes();
|
int[] minutes = invalidMinutes();
|
||||||
XContentBuilder builder = jsonBuilder()
|
XContentBuilder builder = jsonBuilder()
|
||||||
.startObject()
|
.startObject()
|
||||||
.field("minute", Arrays.stream(minutes).mapToObj(p -> Integer.toString(p)).collect(Collectors.toList()))
|
.field("minute", Arrays.stream(minutes).mapToObj(Integer::toString).collect(Collectors.toList()))
|
||||||
.endObject();
|
.endObject();
|
||||||
BytesReference bytes = builder.bytes();
|
BytesReference bytes = builder.bytes();
|
||||||
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
|
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user