Skip to content

Commit 06a968f

Browse files
committed
recycle assertions when we can
1 parent df09034 commit 06a968f

File tree

1 file changed

+24
-15
lines changed
  • jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems

1 file changed

+24
-15
lines changed

jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/MetricAssertions.java

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
package io.opentelemetry.contrib.jmxscraper.target_systems;
77

8-
import static org.assertj.core.api.Assertions.assertThat;
8+
import static io.opentelemetry.contrib.jmxscraper.assertions.Assertions.assertThat;
99

1010
import io.opentelemetry.proto.common.v1.KeyValue;
1111
import io.opentelemetry.proto.metrics.v1.Metric;
@@ -24,11 +24,11 @@ private MetricAssertions() {}
2424

2525
static void assertGauge(Metric metric, String name, String description, String unit) {
2626
assertThat(metric.getName()).isEqualTo(name);
27-
assertThat(metric.getDescription()).isEqualTo(description);
28-
assertThat(metric.getUnit()).isEqualTo(unit);
29-
assertThat(metric.hasGauge()).isTrue();
30-
assertThat(metric.getGauge().getDataPointsList())
31-
.satisfiesExactly(point -> assertThat(point.getAttributesList()).isEmpty());
27+
assertThat(metric)
28+
.hasDescription(description)
29+
.hasUnit(unit)
30+
.isGauge()
31+
.hasDataPointsWithoutAttributes();
3232
}
3333

3434
static void assertSum(Metric metric, String name, String description, String unit) {
@@ -38,12 +38,13 @@ static void assertSum(Metric metric, String name, String description, String uni
3838
static void assertSum(
3939
Metric metric, String name, String description, String unit, boolean isMonotonic) {
4040
assertThat(metric.getName()).isEqualTo(name);
41-
assertThat(metric.getDescription()).isEqualTo(description);
42-
assertThat(metric.getUnit()).isEqualTo(unit);
4341
assertThat(metric.hasSum()).isTrue();
44-
assertThat(metric.getSum().getDataPointsList())
45-
.satisfiesExactly(point -> assertThat(point.getAttributesList()).isEmpty());
4642
assertThat(metric.getSum().getIsMonotonic()).isEqualTo(isMonotonic);
43+
44+
assertThat(metric)
45+
.hasDescription(description)
46+
.hasUnit(unit)
47+
.hasDataPointsWithoutAttributes();
4748
}
4849

4950
@SafeVarargs
@@ -65,9 +66,11 @@ static void assertSumWithAttributes(
6566
String unit,
6667
boolean isMonotonic,
6768
Consumer<MapAssert<String, String>>... attributeGroupAssertions) {
69+
6870
assertThat(metric.getName()).isEqualTo(name);
6971
assertThat(metric.getDescription()).isEqualTo(description);
7072
assertThat(metric.getUnit()).isEqualTo(unit);
73+
7174
assertThat(metric.hasSum()).describedAs("sum expected").isTrue();
7275
assertThat(metric.getSum().getIsMonotonic()).isEqualTo(isMonotonic);
7376
assertAttributedPoints(metric.getSum().getDataPointsList(), attributeGroupAssertions);
@@ -81,9 +84,12 @@ static void assertSumWithAttributesMultiplePoints(
8184
String unit,
8285
boolean isMonotonic,
8386
Consumer<MapAssert<String, String>>... attributeGroupAssertions) {
87+
8488
assertThat(metric.getName()).isEqualTo(name);
85-
assertThat(metric.getDescription()).isEqualTo(description);
86-
assertThat(metric.getUnit()).isEqualTo(unit);
89+
assertThat(metric)
90+
.hasDescription(description)
91+
.hasUnit(unit);
92+
8793
assertThat(metric.hasSum()).isTrue();
8894
assertThat(metric.getSum().getIsMonotonic()).isEqualTo(isMonotonic);
8995
assertAttributedMultiplePoints(metric.getSum().getDataPointsList(), attributeGroupAssertions);
@@ -97,9 +103,12 @@ static void assertGaugeWithAttributes(
97103
String unit,
98104
Consumer<MapAssert<String, String>>... attributeGroupAssertions) {
99105
assertThat(metric.getName()).isEqualTo(name);
100-
assertThat(metric.getDescription()).isEqualTo(description);
101-
assertThat(metric.getUnit()).isEqualTo(unit);
102-
assertThat(metric.hasGauge()).isTrue();
106+
107+
assertThat(metric)
108+
.hasDescription(description)
109+
.hasUnit(unit)
110+
.isGauge();
111+
103112
assertAttributedPoints(metric.getGauge().getDataPointsList(), attributeGroupAssertions);
104113
}
105114

0 commit comments

Comments
 (0)