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 @@ -114,7 +114,7 @@ private static Stream<Arguments> artifactsAndJars() throws IOException {
.map(
line -> {
String[] parts = line.split(":", 2);
return Arguments.of(parts[0], parts[1]);
return Arguments.argumentSet(parts[0], parts[0], parts[1]);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -612,12 +612,16 @@ void extract_limit_maxEntries(List<String> headers, Baggage expectedBaggage) {

static Stream<Arguments> extract_limit_maxEntries() {
return Stream.of(
// Exactly at the limit — all 64 entries extracted
Arguments.of(ImmutableList.of(baggageHeader(0, 64)), baggageWithEntries(0, 64)),
// One over the limit — only the first 64 extracted
Arguments.of(ImmutableList.of(baggageHeader(0, 65)), baggageWithEntries(0, 64)),
// Split across two headers — only the first 64 total extracted
Arguments.of(
Arguments.argumentSet(
"exactly at limit, all 64 extracted",
ImmutableList.of(baggageHeader(0, 64)),
baggageWithEntries(0, 64)),
Arguments.argumentSet(
"one over limit, only first 64 extracted",
ImmutableList.of(baggageHeader(0, 65)),
baggageWithEntries(0, 64)),
Arguments.argumentSet(
"split across two headers, first 64 total extracted",
ImmutableList.of(baggageHeader(0, 32), baggageHeader(32, 33)),
baggageWithEntries(0, 64)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ void valueString(String input, String expectedJson) {

private static Stream<Arguments> stringValueProvider() {
return Stream.of(
Arguments.of("hello", "hello"),
Arguments.of("", ""),
Arguments.of("line1\nline2\ttab", "line1\nline2\ttab"),
Arguments.of("say \"hello\"", "say \"hello\""),
Arguments.of("path\\to\\file", "path\\to\\file"),
Arguments.of("\u0000\u0001\u001F", "\u0000\u0001\u001F"),
Arguments.of("Hello 世界 🌍", "Hello 世界 🌍"));
Arguments.argumentSet("hello", "hello", "hello"),
Arguments.argumentSet("empty string", "", ""),
Arguments.argumentSet("newline and tab", "line1\nline2\ttab", "line1\nline2\ttab"),
Arguments.argumentSet("double quotes", "say \"hello\"", "say \"hello\""),
Arguments.argumentSet("backslash path", "path\\to\\file", "path\\to\\file"),
Arguments.argumentSet("control chars", "\u0000\u0001\u001F", "\u0000\u0001\u001F"),
Arguments.argumentSet("unicode", "Hello 世界 🌍", "Hello 世界 🌍"));
}

@ParameterizedTest
Expand All @@ -42,7 +42,9 @@ void valueBoolean(boolean input, String expectedJson) {
}

private static Stream<Arguments> booleanValueProvider() {
return Stream.of(Arguments.of(true, "true"), Arguments.of(false, "false"));
return Stream.of(
Arguments.argumentSet("true", true, "true"),
Arguments.argumentSet("false", false, "false"));
}

@ParameterizedTest
Expand All @@ -53,11 +55,11 @@ void valueLong(long input, String expectedJson) {

private static Stream<Arguments> longValueProvider() {
return Stream.of(
Arguments.of(42L, "42"),
Arguments.of(-123L, "-123"),
Arguments.of(0L, "0"),
Arguments.of(Long.MAX_VALUE, "9223372036854775807"),
Arguments.of(Long.MIN_VALUE, "-9223372036854775808"));
Arguments.argumentSet("Positive value", 42L, "42"),
Arguments.argumentSet("Negative value", -123L, "-123"),
Arguments.argumentSet("Zero case", 0L, "0"),
Arguments.argumentSet("Maximum possible", Long.MAX_VALUE, "9223372036854775807"),
Arguments.argumentSet("Minimum possible", Long.MIN_VALUE, "-9223372036854775808"));
}

@ParameterizedTest
Expand All @@ -68,15 +70,15 @@ void valueDouble(double input, String expectedJson) {

private static Stream<Arguments> doubleValueProvider() {
return Stream.of(
Comment thread
jack-berg marked this conversation as resolved.
Arguments.of(3.14, "3.14"),
Arguments.of(-2.5, "-2.5"),
Arguments.of(0.0, "0.0"),
Arguments.of(-0.0, "-0.0"),
Arguments.of(Double.NaN, "NaN"),
Arguments.of(Double.POSITIVE_INFINITY, "Infinity"),
Arguments.of(Double.NEGATIVE_INFINITY, "-Infinity"),
Arguments.of(1.23e10, "1.23E10"),
Arguments.of(1.23e-10, "1.23E-10"));
Arguments.argumentSet("Positive value", 3.14, "3.14"),
Arguments.argumentSet("Negative value", -2.5, "-2.5"),
Arguments.argumentSet("Zero", 0.0, "0.0"),
Arguments.argumentSet("Negative zero", -0.0, "-0.0"),
Arguments.argumentSet("NaN", Double.NaN, "NaN"),
Arguments.argumentSet("Positive infinity", Double.POSITIVE_INFINITY, "Infinity"),
Arguments.argumentSet("Negative infinity", Double.NEGATIVE_INFINITY, "-Infinity"),
Arguments.argumentSet("Scientific notation positive exponent", 1.23e10, "1.23E10"),
Arguments.argumentSet("Scientific notation negative exponent", 1.23e-10, "1.23E-10"));
}

@ParameterizedTest
Expand All @@ -88,8 +90,9 @@ void valueBytes(byte[] input, String expectedJson) {
private static Stream<Arguments> bytesValueProvider() {
byte[] regularBytes = new byte[] {0, 1, 2, Byte.MAX_VALUE, Byte.MIN_VALUE};
return Stream.of(
Arguments.of(new byte[] {}, ""),
Arguments.of(regularBytes, Base64.getEncoder().encodeToString(regularBytes)));
Arguments.argumentSet("empty bytes", new byte[] {}, ""),
Arguments.argumentSet(
"regular bytes", regularBytes, Base64.getEncoder().encodeToString(regularBytes)));
}

@Test
Expand All @@ -107,11 +110,16 @@ void valueArray(Value<?> input, String expectedJson) {
@SuppressWarnings("ExplicitArrayForVarargs")
private static Stream<Arguments> arrayValueProvider() {
return Stream.of(
Arguments.of(Value.of(new Value<?>[] {}), "[]"),
Arguments.of(Value.of(Value.of("test")), "[\"test\"]"),
Arguments.of(Value.of(Value.of("a"), Value.of("b"), Value.of("c")), "[\"a\",\"b\",\"c\"]"),
Arguments.of(Value.of(Value.of(1L), Value.of(2L), Value.of(3L)), "[1,2,3]"),
Arguments.of(
Arguments.argumentSet("empty array", Value.of(new Value<?>[] {}), "[]"),
Arguments.argumentSet("single string", Value.of(Value.of("test")), "[\"test\"]"),
Arguments.argumentSet(
"string array",
Value.of(Value.of("a"), Value.of("b"), Value.of("c")),
"[\"a\",\"b\",\"c\"]"),
Arguments.argumentSet(
"long array", Value.of(Value.of(1L), Value.of(2L), Value.of(3L)), "[1,2,3]"),
Arguments.argumentSet(
"mixed types",
Value.of(
Value.of("string"),
Value.of(42L),
Expand All @@ -120,11 +128,13 @@ private static Stream<Arguments> arrayValueProvider() {
Value.of(false),
Value.empty()),
"[\"string\",42,3.14,true,false,null]"),
Arguments.of(
Arguments.argumentSet(
"nested array",
Value.of(
Value.of("outer"), Value.of(Value.of("inner1"), Value.of("inner2")), Value.of(42L)),
"[\"outer\",[\"inner1\",\"inner2\"],42]"),
Arguments.of(
Arguments.argumentSet(
"deeply nested",
Value.of(Value.of(Value.of(Value.of(Value.of(Value.of("deep"))))), Value.of("shallow")),
"[[[[[\"deep\"]]]],\"shallow\"]"));
}
Expand All @@ -143,15 +153,18 @@ private static Stream<Arguments> keyValueListValueProvider() {
map.put("key2", Value.of(42L));

return Stream.of(
Arguments.of(Value.of(new KeyValue[] {}), "{}"),
Arguments.of(Value.of(KeyValue.of("key", Value.of("value"))), "{\"key\":\"value\"}"),
Arguments.of(
Arguments.argumentSet("empty kvlist", Value.of(new KeyValue[] {}), "{}"),
Arguments.argumentSet(
"single kv", Value.of(KeyValue.of("key", Value.of("value"))), "{\"key\":\"value\"}"),
Arguments.argumentSet(
"kv with mixed types",
Value.of(
KeyValue.of("name", Value.of("Alice")),
KeyValue.of("age", Value.of(30L)),
KeyValue.of("active", Value.of(true))),
"{\"name\":\"Alice\",\"age\":30,\"active\":true}"),
Arguments.of(
Arguments.argumentSet(
"nested kvlist",
Value.of(
KeyValue.of("outer", Value.of("value")),
KeyValue.of(
Expand All @@ -160,12 +173,14 @@ private static Stream<Arguments> keyValueListValueProvider() {
KeyValue.of("nested1", Value.of("a")),
KeyValue.of("nested2", Value.of("b"))))),
"{\"outer\":\"value\",\"inner\":{\"nested1\":\"a\",\"nested2\":\"b\"}}"),
Arguments.of(
Arguments.argumentSet(
"kv with array value",
Value.of(
KeyValue.of("name", Value.of("test")),
KeyValue.of("items", Value.of(Value.of(1L), Value.of(2L), Value.of(3L)))),
"{\"name\":\"test\",\"items\":[1,2,3]}"),
Arguments.of(
Arguments.argumentSet(
"all value types",
Value.of(
KeyValue.of("string", Value.of("text")),
KeyValue.of("long", Value.of(42L)),
Expand All @@ -176,8 +191,9 @@ private static Stream<Arguments> keyValueListValueProvider() {
KeyValue.of("array", Value.of(Value.of("a"), Value.of("b")))),
"{\"string\":\"text\",\"long\":42,\"double\":3.14,\"bool\":true,"
+ "\"empty\":null,\"bytes\":\"AQI=\",\"array\":[\"a\",\"b\"]}"),
Arguments.of(Value.of(map), "{\"key1\":\"value1\",\"key2\":42}"),
Arguments.of(
Arguments.argumentSet("map value", Value.of(map), "{\"key1\":\"value1\",\"key2\":42}"),
Arguments.argumentSet(
"keys with special chars",
Value.of(
KeyValue.of("key with spaces", Value.of("value1")),
KeyValue.of("key\"with\"quotes", Value.of("value2")),
Expand Down Expand Up @@ -229,20 +245,27 @@ void edgeCases(Value<?> input, String expectedJson) {
@SuppressWarnings("ExplicitArrayForVarargs")
private static Stream<Arguments> edgeCaseProvider() {
return Stream.of(
Arguments.of(Value.of(KeyValue.of("", Value.of("value"))), "{\"\":\"value\"}"),
Arguments.of(Value.of(Value.empty(), Value.empty(), Value.empty()), "[null,null,null]"),
Arguments.of(
Arguments.argumentSet(
"empty key", Value.of(KeyValue.of("", Value.of("value"))), "{\"\":\"value\"}"),
Arguments.argumentSet(
"null values",
Value.of(Value.empty(), Value.empty(), Value.empty()),
"[null,null,null]"),
Arguments.argumentSet(
"array of kvlists",
Value.of(
Value.of(KeyValue.of("id", Value.of(1L)), KeyValue.of("name", Value.of("A"))),
Value.of(KeyValue.of("id", Value.of(2L)), KeyValue.of("name", Value.of("B"))),
Value.of(KeyValue.of("id", Value.of(3L)), KeyValue.of("name", Value.of("C")))),
"[{\"id\":1,\"name\":\"A\"},{\"id\":2,\"name\":\"B\"},{\"id\":3,\"name\":\"C\"}]"),
Arguments.of(
Arguments.argumentSet(
"kv with empty array",
Value.of(
KeyValue.of("data", Value.of("test")),
KeyValue.of("items", Value.of(new Value<?>[] {}))),
"{\"data\":\"test\",\"items\":[]}"),
Arguments.of(
Arguments.argumentSet(
"kv with empty kvlist",
Value.of(
KeyValue.of("data", Value.of("test")),
KeyValue.of("metadata", Value.of(new KeyValue[] {}))),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,11 @@ void keyManager_CertWithExplanatoryText(SelfSignedCertificate selfSignedCertific
private static Stream<Arguments> keyManagerArgs() throws CertificateException {
Instant now = Instant.now();
return Stream.of(
Arguments.of(
new SelfSignedCertificate(Date.from(now), Date.from(now), "RSA", 2048),
Arguments.argumentSet(
"RSA certificate",
new SelfSignedCertificate(Date.from(now), Date.from(now), "RSA", 2048)),
Arguments.argumentSet(
"EC certificate",
new SelfSignedCertificate(Date.from(now), Date.from(now), "EC", 256)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ private static Stream<Arguments> writeToArgs() {
new ThrowingMarshaler2<>(new IOException("error"));

return Stream.of(
Arguments.of(
Arguments.argumentSet(
"repeated message collection",
asWriter(
output ->
output.serializeRepeatedMessageWithContext(
Expand All @@ -108,7 +109,8 @@ private static Stream<Arguments> writeToArgs() {
throwingMarshaler,
context,
MarshalerContext.key()))),
Arguments.of(
Arguments.argumentSet(
"repeated message map",
asWriter(
output ->
output.serializeRepeatedMessageWithContext(
Expand All @@ -117,7 +119,8 @@ private static Stream<Arguments> writeToArgs() {
throwingMarshaler2,
context,
MarshalerContext.key()))),
Arguments.of(
Arguments.argumentSet(
"repeated message attributes",
asWriter(
output ->
output.serializeRepeatedMessageWithContext(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,30 +133,6 @@ enum OutputType {
FILE_AND_BUFFERED_WRITER
}

public static class TestCase {
private final MemoryMode memoryMode;
private final boolean wrapperJsonObject;
private final OutputType outputType;

public TestCase(OutputType outputType, MemoryMode memoryMode, boolean wrapperJsonObject) {
this.outputType = outputType;
this.memoryMode = memoryMode;
this.wrapperJsonObject = wrapperJsonObject;
}

public OutputType getOutputType() {
return outputType;
}

public boolean isWrapperJsonObject() {
return wrapperJsonObject;
}

public MemoryMode getMemoryMode() {
return memoryMode;
}
}

static Stream<Arguments> exportTestCases() {
return ImmutableList.of(
testCase(OutputType.SYSTEM_OUT, MemoryMode.IMMUTABLE_DATA, /* wrapperJsonObject= */ true),
Expand Down Expand Up @@ -192,23 +168,24 @@ static Stream<Arguments> exportTestCases() {

private static Arguments testCase(
OutputType type, MemoryMode memoryMode, boolean wrapperJsonObject) {
return Arguments.of(
String name =
"output="
+ type
+ ", wrapperJsonObject="
+ wrapperJsonObject
+ ", memoryMode="
+ memoryMode,
new TestCase(type, memoryMode, wrapperJsonObject));
+ memoryMode;
return Arguments.argumentSet(name, type, memoryMode, wrapperJsonObject);
}

@SuppressWarnings("SystemOut")
@ParameterizedTest(name = "{0}")
@ParameterizedTest
@MethodSource("exportTestCases")
void exportWithProgrammaticConfig(String name, TestCase testCase) throws Exception {
void exportWithProgrammaticConfig(
OutputType outputType, MemoryMode memoryMode, boolean wrapperJsonObject) throws Exception {
OutputStream outputStream;
Path file = null;
switch (testCase.getOutputType()) {
switch (outputType) {
case LOGGER:
outputStream = null;
break;
Expand All @@ -224,14 +201,12 @@ void exportWithProgrammaticConfig(String name, TestCase testCase) throws Excepti
outputStream = new BufferedOutputStream(Files.newOutputStream(file));
break;
default:
throw new IllegalStateException("Unexpected value: " + testCase.getOutputType());
throw new IllegalStateException("Unexpected value: " + outputType);
}

Supplier<T> exporter =
() ->
createExporter(outputStream, testCase.getMemoryMode(), testCase.isWrapperJsonObject());
Supplier<T> exporter = () -> createExporter(outputStream, memoryMode, wrapperJsonObject);

if (testCase.getMemoryMode() == MemoryMode.REUSABLE_DATA && !testCase.isWrapperJsonObject()) {
if (memoryMode == MemoryMode.REUSABLE_DATA && !wrapperJsonObject) {
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(exporter::get)
.withMessage("Reusable data mode is not supported without wrapperJsonObject");
Expand All @@ -241,10 +216,10 @@ void exportWithProgrammaticConfig(String name, TestCase testCase) throws Excepti
testDataExporter.export(exporter.get());

String output = output(outputStream, file);
String expectedJson = testDataExporter.getExpectedJson(testCase.isWrapperJsonObject());
String expectedJson = testDataExporter.getExpectedJson(wrapperJsonObject);
JSONAssert.assertEquals("Got \n" + output, expectedJson, output, false);

if (testCase.isWrapperJsonObject()) {
if (wrapperJsonObject) {
assertThat(output).doesNotContain("\n");
}

Expand Down
Loading
Loading