Skip to content

Commit f674cdd

Browse files
authored
Add hasValueSatisfying to LongPointAssert and DoublePointAssert (#8328)
1 parent 951ff73 commit f674cdd

5 files changed

Lines changed: 39 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
## Unreleased
44

5+
### SDK
6+
7+
#### Testing
8+
9+
* Add `hasValueSatisfying` to `LongPointAssert` and `DoublePointAssert` for fuzzy value matching
10+
511
## Version 1.61.0 (2026-04-10)
612

713
### API
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
Comparing source compatibility of opentelemetry-sdk-testing-1.62.0-SNAPSHOT.jar against opentelemetry-sdk-testing-1.61.0.jar
2-
No changes.
2+
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.sdk.testing.assertj.DoublePointAssert (not serializable)
3+
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
4+
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.assertj.DoublePointAssert hasValueSatisfying(java.util.function.Consumer<org.assertj.core.api.AbstractDoubleAssert<?>>)
5+
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.sdk.testing.assertj.LongPointAssert (not serializable)
6+
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
7+
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.assertj.LongPointAssert hasValueSatisfying(java.util.function.Consumer<org.assertj.core.api.AbstractLongAssert<?>>)

sdk/testing/src/main/java/io/opentelemetry/sdk/testing/assertj/DoublePointAssert.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.util.Arrays;
1313
import java.util.function.Consumer;
1414
import javax.annotation.Nullable;
15+
import org.assertj.core.api.AbstractDoubleAssert;
1516
import org.assertj.core.api.Assertions;
1617

1718
/**
@@ -33,6 +34,13 @@ public DoublePointAssert hasValue(double expected) {
3334
return this;
3435
}
3536

37+
/** Asserts the point's value satisfies the given assertion. */
38+
public DoublePointAssert hasValueSatisfying(Consumer<AbstractDoubleAssert<?>> valueAssertion) {
39+
isNotNull();
40+
valueAssertion.accept(Assertions.assertThat(actual.getValue()).as("value"));
41+
return this;
42+
}
43+
3644
/** Asserts the point has the specified exemplars, in any order. */
3745
public DoublePointAssert hasExemplars(DoubleExemplarData... exemplars) {
3846
isNotNull();

sdk/testing/src/main/java/io/opentelemetry/sdk/testing/assertj/LongPointAssert.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.util.Arrays;
1313
import java.util.function.Consumer;
1414
import javax.annotation.Nullable;
15+
import org.assertj.core.api.AbstractLongAssert;
1516

1617
/**
1718
* Assertions for an exported {@link LongPointData}.
@@ -31,6 +32,13 @@ public LongPointAssert hasValue(long expected) {
3132
return this;
3233
}
3334

35+
/** Asserts the point's value satisfies the given assertion. */
36+
public LongPointAssert hasValueSatisfying(Consumer<AbstractLongAssert<?>> valueAssertion) {
37+
isNotNull();
38+
valueAssertion.accept(assertThat(actual.getValue()).as("value"));
39+
return this;
40+
}
41+
3442
/** Asserts the point has the specified exemplars, in any order. */
3543
public LongPointAssert hasExemplars(LongExemplarData... exemplars) {
3644
isNotNull();

sdk/testing/src/test/java/io/opentelemetry/sdk/testing/assertj/MetricAssertionsTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ void doubleGauge() {
352352
.hasEpochNanos(4)
353353
.hasAttributes(Attributes.empty())
354354
.hasValue(3.0)
355+
.hasValueSatisfying(val -> val.isEqualTo(3.0))
355356
.hasExemplars(DOUBLE_EXEMPLAR2, DOUBLE_EXEMPLAR1)
356357
.hasExemplarsSatisfying(
357358
exemplar ->
@@ -857,6 +858,7 @@ void longGauge() {
857858
point ->
858859
point
859860
.hasValue(Long.MAX_VALUE)
861+
.hasValueSatisfying(val -> val.isEqualTo(Long.MAX_VALUE))
860862
.hasExemplarsSatisfying(
861863
exemplar -> exemplar.hasValue(2),
862864
exemplar ->
@@ -903,6 +905,15 @@ void longGaugeFailure() {
903905
gauge.hasPointsSatisfying(
904906
point -> point.hasValue(2), point -> point.hasValue(1))))
905907
.isInstanceOf(AssertionError.class);
908+
assertThatThrownBy(
909+
() ->
910+
assertThat(LONG_GAUGE_METRIC)
911+
.hasLongGaugeSatisfying(
912+
gauge ->
913+
gauge.hasPointsSatisfying(
914+
point -> point.hasValueSatisfying(val -> val.isNegative()),
915+
point -> point.hasValueSatisfying(val -> val.isNegative()))))
916+
.isInstanceOf(AssertionError.class);
906917
assertThatThrownBy(
907918
() ->
908919
assertThat(LONG_GAUGE_METRIC)

0 commit comments

Comments
 (0)