Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void testFromRubbish() throws Exception {
}

public void testVersionedMediaType() {
String version = String.valueOf(Math.abs(randomByte()));
String version = String.valueOf(randomNonNegativeByte());
assertThat(XContentType.fromMediaType("application/vnd.elasticsearch+json;compatible-with=" + version),
equalTo(XContentType.JSON));
assertThat(XContentType.fromMediaType("application/vnd.elasticsearch+cbor;compatible-with=" + version),
Expand All @@ -119,7 +119,7 @@ public void testVersionedMediaType() {
}

public void testVersionParsing() {
byte version = (byte) Math.abs(randomByte());
byte version = randomNonNegativeByte();
assertThat(XContentType.parseVersion("application/vnd.elasticsearch+json;compatible-with=" + version),
equalTo(version));
assertThat(XContentType.parseVersion("application/vnd.elasticsearch+cbor;compatible-with=" + version),
Expand All @@ -146,12 +146,12 @@ public void testUnrecognizedParameter() {
is(nullValue())); }

public void testMediaTypeWithoutESSubtype() {
String version = String.valueOf(Math.abs(randomByte()));
String version = String.valueOf(randomNonNegativeByte());
assertThat(XContentType.fromMediaType("application/json;compatible-with=" + version), nullValue());
}

public void testAnchoring() {
String version = String.valueOf(Math.abs(randomByte()));
String version = String.valueOf(randomNonNegativeByte());
assertThat(XContentType.fromMediaType("sth_application/json;compatible-with=" + version + ".0"), nullValue());
assertThat(XContentType.fromMediaType("sth_application/json;compatible-with=" + version + "_sth"), nullValue());
assertThat(XContentType.fromMediaType("application/json;compatible-with=" + version + "_sth"), nullValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,11 @@ public static byte randomByte() {
return (byte) random().nextInt();
}

public static byte randomNonNegativeByte() {
byte randomByte = randomByte();
return (byte) (randomByte == Byte.MIN_VALUE ? 0 : Math.abs(randomByte));
}

/**
* Helper method to create a byte array of a given length populated with random byte values
*
Expand Down