Skip to content

Commit 421922e

Browse files
committed
Remove most usages of junit ArgumentsProvider
1 parent 7ddd49d commit 421922e

File tree

23 files changed

+2088
-2440
lines changed

23 files changed

+2088
-2440
lines changed

instrumentation-api-incubator/src/test/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/RedisCommandSanitizerTest.java

Lines changed: 245 additions & 259 deletions
Large diffs are not rendered by default.

instrumentation-api-incubator/src/test/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/SqlStatementSanitizerTest.java

Lines changed: 227 additions & 267 deletions
Large diffs are not rendered by default.

instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/SpanSuppressionStrategyTest.java

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,41 +22,35 @@
2222
import java.util.Set;
2323
import java.util.stream.Stream;
2424
import org.junit.jupiter.api.Test;
25-
import org.junit.jupiter.api.extension.ExtensionContext;
2625
import org.junit.jupiter.params.ParameterizedTest;
2726
import org.junit.jupiter.params.provider.Arguments;
28-
import org.junit.jupiter.params.provider.ArgumentsProvider;
29-
import org.junit.jupiter.params.provider.ArgumentsSource;
3027
import org.junit.jupiter.params.provider.EnumSource;
28+
import org.junit.jupiter.params.provider.MethodSource;
3129

3230
class SpanSuppressionStrategyTest {
3331

3432
static final Span span = Span.getInvalid();
3533

3634
@ParameterizedTest
37-
@ArgumentsSource(ConfigArgs.class)
35+
@MethodSource("configArgs")
3836
void shouldParseConfig(String value, SpanSuppressionStrategy expectedStrategy) {
3937
assertEquals(expectedStrategy, SpanSuppressionStrategy.fromConfig(value));
4038
}
4139

42-
static final class ConfigArgs implements ArgumentsProvider {
43-
44-
@Override
45-
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
46-
return Stream.of(
47-
Arguments.of("none", SpanSuppressionStrategy.NONE),
48-
Arguments.of("NONE", SpanSuppressionStrategy.NONE),
49-
Arguments.of("span-kind", SpanSuppressionStrategy.SPAN_KIND),
50-
Arguments.of("Span-Kind", SpanSuppressionStrategy.SPAN_KIND),
51-
Arguments.of("semconv", SpanSuppressionStrategy.SEMCONV),
52-
Arguments.of("SemConv", SpanSuppressionStrategy.SEMCONV),
53-
Arguments.of("asdfasdfasdf", SpanSuppressionStrategy.SEMCONV),
54-
Arguments.of(null, SpanSuppressionStrategy.SEMCONV));
55-
}
40+
private static Stream<Arguments> configArgs() {
41+
return Stream.of(
42+
Arguments.of("none", SpanSuppressionStrategy.NONE),
43+
Arguments.of("NONE", SpanSuppressionStrategy.NONE),
44+
Arguments.of("span-kind", SpanSuppressionStrategy.SPAN_KIND),
45+
Arguments.of("Span-Kind", SpanSuppressionStrategy.SPAN_KIND),
46+
Arguments.of("semconv", SpanSuppressionStrategy.SEMCONV),
47+
Arguments.of("SemConv", SpanSuppressionStrategy.SEMCONV),
48+
Arguments.of("asdfasdfasdf", SpanSuppressionStrategy.SEMCONV),
49+
Arguments.of(null, SpanSuppressionStrategy.SEMCONV));
5650
}
5751

5852
@ParameterizedTest
59-
@ArgumentsSource(SpanKindsAndKeys.class)
53+
@MethodSource("spanKindsAndKeys")
6054
void none_shouldNotSuppressAnything(SpanKind spanKind, SpanKey spanKey) {
6155
SpanSuppressor suppressor = SpanSuppressionStrategy.NONE.create(emptySet());
6256

@@ -77,7 +71,7 @@ void none_shouldNotStoreSpansInContext(SpanKind spanKind) {
7771
}
7872

7973
@ParameterizedTest
80-
@ArgumentsSource(SpanKindsAndKeys.class)
74+
@MethodSource("spanKindsAndKeys")
8175
void spanKind_shouldStoreInContext(SpanKind spanKind, SpanKey spanKey) {
8276
SpanSuppressor suppressor = SpanSuppressionStrategy.SPAN_KIND.create(emptySet());
8377
Context context = Context.root();
@@ -89,7 +83,7 @@ void spanKind_shouldStoreInContext(SpanKind spanKind, SpanKey spanKey) {
8983
}
9084

9185
@ParameterizedTest
92-
@ArgumentsSource(SpanKindsAndKeys.class)
86+
@MethodSource("spanKindsAndKeys")
9387
void spanKind_shouldSuppressSameKind(SpanKind spanKind, SpanKey spanKey) {
9488
SpanSuppressor suppressor = SpanSuppressionStrategy.SPAN_KIND.create(emptySet());
9589
Context context = Context.root();
@@ -100,16 +94,12 @@ void spanKind_shouldSuppressSameKind(SpanKind spanKind, SpanKey spanKey) {
10094
assertSame(span, spanKey.fromContextOrNull(newContext));
10195
}
10296

103-
static final class SpanKindsAndKeys implements ArgumentsProvider {
104-
105-
@Override
106-
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
107-
return Stream.of(
108-
Arguments.of(SpanKind.SERVER, SpanKey.KIND_SERVER),
109-
Arguments.of(SpanKind.CLIENT, SpanKey.KIND_CLIENT),
110-
Arguments.of(SpanKind.CONSUMER, SpanKey.KIND_CONSUMER),
111-
Arguments.of(SpanKind.PRODUCER, SpanKey.KIND_PRODUCER));
112-
}
97+
private static Stream<Arguments> spanKindsAndKeys() {
98+
return Stream.of(
99+
Arguments.of(SpanKind.SERVER, SpanKey.KIND_SERVER),
100+
Arguments.of(SpanKind.CLIENT, SpanKey.KIND_CLIENT),
101+
Arguments.of(SpanKind.CONSUMER, SpanKey.KIND_CONSUMER),
102+
Arguments.of(SpanKind.PRODUCER, SpanKey.KIND_PRODUCER));
113103
}
114104

115105
@Test

instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/semconv/http/ForwardedHostAddressAndPortExtractorTest.java

Lines changed: 46 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@
1818
import java.util.stream.Stream;
1919
import javax.annotation.Nullable;
2020
import org.junit.jupiter.api.extension.ExtendWith;
21-
import org.junit.jupiter.api.extension.ExtensionContext;
2221
import org.junit.jupiter.params.ParameterizedTest;
2322
import org.junit.jupiter.params.provider.Arguments;
24-
import org.junit.jupiter.params.provider.ArgumentsProvider;
25-
import org.junit.jupiter.params.provider.ArgumentsSource;
23+
import org.junit.jupiter.params.provider.MethodSource;
2624
import org.mockito.InjectMocks;
2725
import org.mockito.Mock;
2826
import org.mockito.junit.jupiter.MockitoExtension;
@@ -37,7 +35,7 @@ class ForwardedHostAddressAndPortExtractorTest {
3735
@InjectMocks ForwardedHostAddressAndPortExtractor<String> underTest;
3836

3937
@ParameterizedTest
40-
@ArgumentsSource(ForwardedArgs.class)
38+
@MethodSource("forwardedArgs")
4139
void shouldParseForwarded(
4240
List<String> headers, @Nullable String expectedAddress, @Nullable Integer expectedPort) {
4341
when(getter.getHttpRequestHeader(REQUEST, "forwarded")).thenReturn(headers);
@@ -49,40 +47,36 @@ void shouldParseForwarded(
4947
assertThat(sink.getPort()).isEqualTo(expectedPort);
5048
}
5149

52-
static final class ForwardedArgs implements ArgumentsProvider {
53-
54-
@Override
55-
public Stream<? extends Arguments> provideArguments(ExtensionContext extensionContext) {
56-
return Stream.of(
57-
// empty/invalid headers
58-
arguments(singletonList(""), null, null),
59-
arguments(singletonList("host="), null, null),
60-
arguments(singletonList("host=;"), null, null),
61-
arguments(singletonList("host=\""), null, null),
62-
arguments(singletonList("host=\"\""), null, null),
63-
arguments(singletonList("host=\"example.com"), null, null),
64-
arguments(singletonList("by=1.2.3.4, test=abc"), null, null),
65-
arguments(singletonList("host=example.com"), "example.com", null),
66-
arguments(singletonList("host=\"example.com\""), "example.com", null),
67-
arguments(singletonList("host=example.com; test=abc:1234"), "example.com", null),
68-
arguments(singletonList("host=\"example.com\"; test=abc:1234"), "example.com", null),
69-
arguments(singletonList("host=example.com:port"), "example.com", null),
70-
arguments(singletonList("host=\"example.com:port\""), "example.com", null),
71-
arguments(singletonList("host=example.com:42"), "example.com", 42),
72-
arguments(singletonList("host=\"example.com:42\""), "example.com", 42),
73-
arguments(singletonList("host=example.com:42; test=abc:1234"), "example.com", 42),
74-
arguments(singletonList("host=\"example.com:42\"; test=abc:1234"), "example.com", 42),
75-
76-
// multiple headers
77-
arguments(
78-
asList("proto=https", "host=example.com", "host=github.com:1234"),
79-
"example.com",
80-
null));
81-
}
50+
private static Stream<Arguments> forwardedArgs() {
51+
return Stream.of(
52+
// empty/invalid headers
53+
arguments(singletonList(""), null, null),
54+
arguments(singletonList("host="), null, null),
55+
arguments(singletonList("host=;"), null, null),
56+
arguments(singletonList("host=\""), null, null),
57+
arguments(singletonList("host=\"\""), null, null),
58+
arguments(singletonList("host=\"example.com"), null, null),
59+
arguments(singletonList("by=1.2.3.4, test=abc"), null, null),
60+
arguments(singletonList("host=example.com"), "example.com", null),
61+
arguments(singletonList("host=\"example.com\""), "example.com", null),
62+
arguments(singletonList("host=example.com; test=abc:1234"), "example.com", null),
63+
arguments(singletonList("host=\"example.com\"; test=abc:1234"), "example.com", null),
64+
arguments(singletonList("host=example.com:port"), "example.com", null),
65+
arguments(singletonList("host=\"example.com:port\""), "example.com", null),
66+
arguments(singletonList("host=example.com:42"), "example.com", 42),
67+
arguments(singletonList("host=\"example.com:42\""), "example.com", 42),
68+
arguments(singletonList("host=example.com:42; test=abc:1234"), "example.com", 42),
69+
arguments(singletonList("host=\"example.com:42\"; test=abc:1234"), "example.com", 42),
70+
71+
// multiple headers
72+
arguments(
73+
asList("proto=https", "host=example.com", "host=github.com:1234"),
74+
"example.com",
75+
null));
8276
}
8377

8478
@ParameterizedTest
85-
@ArgumentsSource(HostArgs.class)
79+
@MethodSource("hostArgs")
8680
@SuppressWarnings("MockitoDoSetup")
8781
void shouldParseForwardedHost(
8882
List<String> headers, @Nullable String expectedAddress, @Nullable Integer expectedPort) {
@@ -97,7 +91,7 @@ void shouldParseForwardedHost(
9791
}
9892

9993
@ParameterizedTest
100-
@ArgumentsSource(HostArgs.class)
94+
@MethodSource("hostArgs")
10195
@SuppressWarnings("MockitoDoSetup")
10296
void shouldParsePseudoAuthority(
10397
List<String> headers, @Nullable String expectedAddress, @Nullable Integer expectedPort) {
@@ -113,7 +107,7 @@ void shouldParsePseudoAuthority(
113107
}
114108

115109
@ParameterizedTest
116-
@ArgumentsSource(HostArgs.class)
110+
@MethodSource("hostArgs")
117111
@SuppressWarnings("MockitoDoSetup")
118112
void shouldParseHost(
119113
List<String> headers, @Nullable String expectedAddress, @Nullable Integer expectedPort) {
@@ -129,24 +123,20 @@ void shouldParseHost(
129123
assertThat(sink.getPort()).isEqualTo(expectedPort);
130124
}
131125

132-
static final class HostArgs implements ArgumentsProvider {
133-
134-
@Override
135-
public Stream<? extends Arguments> provideArguments(ExtensionContext extensionContext) {
136-
return Stream.of(
137-
// empty/invalid headers
138-
arguments(singletonList(""), null, null),
139-
arguments(singletonList("\""), null, null),
140-
arguments(singletonList("\"\""), null, null),
141-
arguments(singletonList("example.com"), "example.com", null),
142-
arguments(singletonList("example.com:port"), "example.com", null),
143-
arguments(singletonList("example.com:42"), "example.com", 42),
144-
arguments(singletonList("\"example.com\""), "example.com", null),
145-
arguments(singletonList("\"example.com:port\""), "example.com", null),
146-
arguments(singletonList("\"example.com:42\""), "example.com", 42),
147-
148-
// multiple headers
149-
arguments(asList("example.com", "github.com:1234"), "example.com", null));
150-
}
126+
private static Stream<Arguments> hostArgs() {
127+
return Stream.of(
128+
// empty/invalid headers
129+
arguments(singletonList(""), null, null),
130+
arguments(singletonList("\""), null, null),
131+
arguments(singletonList("\"\""), null, null),
132+
arguments(singletonList("example.com"), "example.com", null),
133+
arguments(singletonList("example.com:port"), "example.com", null),
134+
arguments(singletonList("example.com:42"), "example.com", 42),
135+
arguments(singletonList("\"example.com\""), "example.com", null),
136+
arguments(singletonList("\"example.com:port\""), "example.com", null),
137+
arguments(singletonList("\"example.com:42\""), "example.com", 42),
138+
139+
// multiple headers
140+
arguments(asList("example.com", "github.com:1234"), "example.com", null));
151141
}
152142
}

instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/semconv/http/ForwardedUrlSchemeProviderTest.java

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@
1919
import java.util.stream.Stream;
2020
import org.junit.jupiter.api.Test;
2121
import org.junit.jupiter.api.extension.ExtendWith;
22-
import org.junit.jupiter.api.extension.ExtensionContext;
2322
import org.junit.jupiter.params.ParameterizedTest;
2423
import org.junit.jupiter.params.provider.Arguments;
25-
import org.junit.jupiter.params.provider.ArgumentsProvider;
26-
import org.junit.jupiter.params.provider.ArgumentsSource;
24+
import org.junit.jupiter.params.provider.MethodSource;
2725
import org.mockito.InjectMocks;
2826
import org.mockito.Mock;
2927
import org.mockito.junit.jupiter.MockitoExtension;
@@ -44,52 +42,44 @@ void noHeaders() {
4442
}
4543

4644
@ParameterizedTest
47-
@ArgumentsSource(ForwardedHeaderValues.class)
45+
@MethodSource("forwardedHeaderValues")
4846
void parseForwardedHeader(List<String> values, String expectedScheme) {
4947
when(getter.getHttpRequestHeader(REQUEST, "forwarded")).thenReturn(values);
5048
assertThat(underTest.apply(REQUEST)).isEqualTo(expectedScheme);
5149
}
5250

53-
static final class ForwardedHeaderValues implements ArgumentsProvider {
54-
55-
@Override
56-
public Stream<? extends Arguments> provideArguments(ExtensionContext extensionContext) {
57-
return Stream.of(
58-
arguments(singletonList("for=1.1.1.1;proto=xyz"), "xyz"),
59-
arguments(singletonList("for=1.1.1.1;proto=xyz;"), "xyz"),
60-
arguments(singletonList("for=1.1.1.1;proto=xyz,"), "xyz"),
61-
arguments(singletonList("for=1.1.1.1;proto="), null),
62-
arguments(singletonList("for=1.1.1.1;proto=;"), null),
63-
arguments(singletonList("for=1.1.1.1;proto=,"), null),
64-
arguments(singletonList("for=1.1.1.1;proto=\"xyz\""), "xyz"),
65-
arguments(singletonList("for=1.1.1.1;proto=\"xyz\";"), "xyz"),
66-
arguments(singletonList("for=1.1.1.1;proto=\"xyz\","), "xyz"),
67-
arguments(singletonList("for=1.1.1.1;proto=\""), null),
68-
arguments(singletonList("for=1.1.1.1;proto=\"\""), null),
69-
arguments(singletonList("for=1.1.1.1;proto=\"\";"), null),
70-
arguments(singletonList("for=1.1.1.1;proto=\"\","), null),
71-
arguments(asList("for=1.1.1.1", "proto=xyz", "proto=abc"), "xyz"));
72-
}
51+
private static Stream<Arguments> forwardedHeaderValues() {
52+
return Stream.of(
53+
arguments(singletonList("for=1.1.1.1;proto=xyz"), "xyz"),
54+
arguments(singletonList("for=1.1.1.1;proto=xyz;"), "xyz"),
55+
arguments(singletonList("for=1.1.1.1;proto=xyz,"), "xyz"),
56+
arguments(singletonList("for=1.1.1.1;proto="), null),
57+
arguments(singletonList("for=1.1.1.1;proto=;"), null),
58+
arguments(singletonList("for=1.1.1.1;proto=,"), null),
59+
arguments(singletonList("for=1.1.1.1;proto=\"xyz\""), "xyz"),
60+
arguments(singletonList("for=1.1.1.1;proto=\"xyz\";"), "xyz"),
61+
arguments(singletonList("for=1.1.1.1;proto=\"xyz\","), "xyz"),
62+
arguments(singletonList("for=1.1.1.1;proto=\""), null),
63+
arguments(singletonList("for=1.1.1.1;proto=\"\""), null),
64+
arguments(singletonList("for=1.1.1.1;proto=\"\";"), null),
65+
arguments(singletonList("for=1.1.1.1;proto=\"\","), null),
66+
arguments(asList("for=1.1.1.1", "proto=xyz", "proto=abc"), "xyz"));
7367
}
7468

7569
@ParameterizedTest
76-
@ArgumentsSource(ForwardedProtoHeaderValues.class)
70+
@MethodSource("forwardedProtoHeaderValues")
7771
@SuppressWarnings("MockitoDoSetup")
7872
void parseForwardedProtoHeader(List<String> values, String expectedScheme) {
7973
doReturn(emptyList()).when(getter).getHttpRequestHeader(REQUEST, "forwarded");
8074
doReturn(values).when(getter).getHttpRequestHeader(REQUEST, "x-forwarded-proto");
8175
assertThat(underTest.apply(REQUEST)).isEqualTo(expectedScheme);
8276
}
8377

84-
static final class ForwardedProtoHeaderValues implements ArgumentsProvider {
85-
86-
@Override
87-
public Stream<? extends Arguments> provideArguments(ExtensionContext extensionContext) {
88-
return Stream.of(
89-
arguments(singletonList("xyz"), "xyz"),
90-
arguments(singletonList("\"xyz\""), "xyz"),
91-
arguments(singletonList("\""), null),
92-
arguments(asList("xyz", "abc"), "xyz"));
93-
}
78+
private static Stream<Arguments> forwardedProtoHeaderValues() {
79+
return Stream.of(
80+
arguments(singletonList("xyz"), "xyz"),
81+
arguments(singletonList("\"xyz\""), "xyz"),
82+
arguments(singletonList("\""), null),
83+
arguments(asList("xyz", "abc"), "xyz"));
9484
}
9585
}

0 commit comments

Comments
 (0)