Skip to content

Commit

Permalink
enforce static imports
Browse files Browse the repository at this point in the history
  • Loading branch information
zeitlinger committed Aug 19, 2024
1 parent 873e1e1 commit 4ce6c49
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
4 changes: 3 additions & 1 deletion buildscripts/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@
<module name="TreeWalker">
<module name="RegexpSinglelineJava">
<!-- Please statically import methods -->
<property name="format" value="(?&lt;!import static java\.util\.)Collections\.singletonMap"/>
<property name="format" value="(?&lt;!io\.opentelemetry\.sdk\.testing\.assertj\.)OpenTelemetryAssertions.assertThat"/>
<!-- just use OpenTelemetryAssertions you need both OpenTelemetryAssertions and Assertions -->
<property name="format" value="(?&lt;!org\.assertj\.core\.api\.)Assertions.assertThat"/>
</module>
<module name="OuterTypeFilename"/>
<module name="IllegalTokenText">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import io.opentelemetry.semconv.ServerAttributes;
import io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes;
import java.util.concurrent.TimeUnit;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;

class MessagingProducerMetricsTest {
Expand Down Expand Up @@ -65,15 +64,15 @@ void collectsMetrics() {

Context context1 = listener.onStart(parent, requestAttributes, nanos(100));

Assertions.assertThat(metricReader.collectAllMetrics()).isEmpty();
assertThat(metricReader.collectAllMetrics()).isEmpty();

Context context2 = listener.onStart(Context.root(), requestAttributes, nanos(150));

Assertions.assertThat(metricReader.collectAllMetrics()).isEmpty();
assertThat(metricReader.collectAllMetrics()).isEmpty();

listener.onEnd(context1, responseAttributes, nanos(250));

Assertions.assertThat(metricReader.collectAllMetrics())
assertThat(metricReader.collectAllMetrics())
.satisfiesExactlyInAnyOrder(
metric ->
assertThat(metric)
Expand Down Expand Up @@ -109,7 +108,7 @@ void collectsMetrics() {

listener.onEnd(context2, responseAttributes, nanos(300));

Assertions.assertThat(metricReader.collectAllMetrics())
assertThat(metricReader.collectAllMetrics())
.satisfiesExactlyInAnyOrder(
metric ->
assertThat(metric)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package io.opentelemetry.instrumentation.api.internal;

import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;

import io.opentelemetry.api.metrics.DoubleHistogramBuilder;
import io.opentelemetry.api.metrics.Meter;
import io.opentelemetry.api.metrics.MeterProvider;
Expand All @@ -13,7 +15,6 @@
import io.opentelemetry.instrumentation.testing.junit.LibraryInstrumentationExtension;
import java.lang.reflect.Proxy;
import java.util.concurrent.atomic.AtomicBoolean;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

Expand All @@ -29,7 +30,7 @@ void noWarning() {
"test metrics", meter -> null, (s, doubleHistogramBuilder) -> warning.set(true));
operationMetrics.create(testing.getOpenTelemetry().getMeter("test"));

Assertions.assertThat(warning).isFalse();
assertThat(warning).isFalse();
}

@Test
Expand All @@ -40,7 +41,7 @@ void noWarningWithNoopMetrics() {
"test metrics", meter -> null, (s, doubleHistogramBuilder) -> warning.set(true));
operationMetrics.create(MeterProvider.noop().get("test"));

Assertions.assertThat(warning).isFalse();
assertThat(warning).isFalse();
}

@Test
Expand All @@ -65,7 +66,7 @@ void warning() {
});
operationMetrics.create(meter);

Assertions.assertThat(warning).isTrue();
assertThat(warning).isTrue();
}

private static DoubleHistogramBuilder proxyDoubleHistogramBuilder(Meter meter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

package io.opentelemetry.instrumentation.grpc.v1_6;

import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.*;
import static org.assertj.core.api.Assertions.assertThat;

import example.GreeterGrpc;
import example.Helloworld;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import static io.opentelemetry.instrumentation.javaagent.runtimemetrics.java8.JarAnalyzer.PACKAGE_PATH;
import static io.opentelemetry.instrumentation.javaagent.runtimemetrics.java8.JarAnalyzer.PACKAGE_TYPE;
import static io.opentelemetry.instrumentation.javaagent.runtimemetrics.java8.JarAnalyzer.PACKAGE_VERSION;
import static org.assertj.core.api.Assertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
Expand All @@ -25,7 +25,6 @@
import io.opentelemetry.api.incubator.events.EventLogger;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.sdk.testing.assertj.AttributesAssert;
import io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
Expand All @@ -41,7 +40,6 @@ class JarAnalyzerTest {

@ParameterizedTest
@MethodSource("processUrlArguments")
@SuppressWarnings("checkstyle:RegexpSinglelineJava")
void processUrl_EmitsEvents(URL archiveUrl, Consumer<AttributesAssert> attributesConsumer) {
EventLogger eventLogger = mock(EventLogger.class);
EventBuilder builder = mock(EventBuilder.class);
Expand All @@ -54,7 +52,7 @@ void processUrl_EmitsEvents(URL archiveUrl, Consumer<AttributesAssert> attribute
verify(builder).setAttributes(attributesArgumentCaptor.capture());

attributesConsumer.accept(
OpenTelemetryAssertions.assertThat(attributesArgumentCaptor.getValue()));
assertThat(attributesArgumentCaptor.getValue()));
}

private static Stream<Arguments> processUrlArguments() {
Expand Down

0 comments on commit 4ce6c49

Please sign in to comment.