diff --git a/docs/apidiffs/current_vs_latest/opentelemetry-sdk-testing.txt b/docs/apidiffs/current_vs_latest/opentelemetry-sdk-testing.txt index 157b9149b5..aa71c04fb1 100644 --- a/docs/apidiffs/current_vs_latest/opentelemetry-sdk-testing.txt +++ b/docs/apidiffs/current_vs_latest/opentelemetry-sdk-testing.txt @@ -1,4 +1,7 @@ Comparing source compatibility of against +*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.sdk.testing.assertj.HistogramPointAssert (not serializable) + === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 + +++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.assertj.HistogramPointAssert hasBucketBoundaries(double[], org.assertj.core.data.Offset) +++ NEW CLASS: PUBLIC(+) FINAL(+) io.opentelemetry.sdk.testing.assertj.LogRecordDataAssert (not serializable) +++ CLASS FILE FORMAT VERSION: 52.0 <- n.a. +++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.assertj.LogRecordDataAssert hasAttributes(io.opentelemetry.api.common.Attributes) diff --git a/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/assertj/HistogramPointAssert.java b/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/assertj/HistogramPointAssert.java index 2861725620..3ce2fe38d2 100644 --- a/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/assertj/HistogramPointAssert.java +++ b/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/assertj/HistogramPointAssert.java @@ -6,12 +6,14 @@ package io.opentelemetry.sdk.testing.assertj; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.within; import io.opentelemetry.sdk.metrics.data.DoubleExemplarData; import io.opentelemetry.sdk.metrics.data.HistogramPointData; import java.util.Arrays; import java.util.function.Consumer; import org.assertj.core.api.Assertions; +import org.assertj.core.data.Offset; /** * Test assertions for {@link HistogramPointData}. @@ -68,9 +70,20 @@ public final class HistogramPointAssert * @param boundaries The set of bucket boundaries in the same order as the expected collection. */ public HistogramPointAssert hasBucketBoundaries(double... boundaries) { + return hasBucketBoundaries(boundaries, within(0.000_001)); + } + + /** + * Asserts the {@code boundaries} field matches the expected value. The boundaries are may vary + * with a specified precision. + * + * @param boundaries The set of bucket boundaries in the same order as the expected collection. + * @param precision The precision under which boundaries may vary. + */ + public HistogramPointAssert hasBucketBoundaries(double[] boundaries, Offset precision) { isNotNull(); - Double[] bigBoundaries = Arrays.stream(boundaries).boxed().toArray(Double[]::new); - Assertions.assertThat(actual.getBoundaries()).as("boundaries").containsExactly(bigBoundaries); + double[] actualBoundaries = actual.getBoundaries().stream().mapToDouble(d -> d).toArray(); + Assertions.assertThat(actualBoundaries).as("boundaries").containsExactly(boundaries, precision); return this; } diff --git a/sdk/testing/src/test/java/io/opentelemetry/sdk/testing/assertj/MetricAssertionsTest.java b/sdk/testing/src/test/java/io/opentelemetry/sdk/testing/assertj/MetricAssertionsTest.java index a5507ab045..7d9fba741e 100644 --- a/sdk/testing/src/test/java/io/opentelemetry/sdk/testing/assertj/MetricAssertionsTest.java +++ b/sdk/testing/src/test/java/io/opentelemetry/sdk/testing/assertj/MetricAssertionsTest.java @@ -11,6 +11,7 @@ import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equal import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.Assertions.offset; +import static org.assertj.core.api.Assertions.within; import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; @@ -981,7 +982,8 @@ class MetricAssertionsTest { .hasMax(7.0) .hasMin(4.0) .hasCount(3) - .hasBucketBoundaries(10.0))); + .hasBucketBoundaries(10.0) + .hasBucketBoundaries(new double[] {10.1}, within(0.1)))); assertThat(HISTOGRAM_METRIC_DELTA).hasHistogramSatisfying(histogram -> histogram.isDelta()); } @@ -1044,6 +1046,15 @@ class MetricAssertionsTest { histogram.hasPointsSatisfying( point -> point.hasBucketBoundaries(11.0)))) .isInstanceOf(AssertionError.class); + assertThatThrownBy( + () -> + assertThat(HISTOGRAM_METRIC) + .hasHistogramSatisfying( + histogram -> + histogram.hasPointsSatisfying( + point -> + point.hasBucketBoundaries(new double[] {11.0}, within(0.1))))) + .isInstanceOf(AssertionError.class); } @Test