Skip to content

Commit b6e5865

Browse files
authored
Junit cleanup (#1119)
* exclude hamcrest Signed-off-by: Gregor Zeitlinger <[email protected]> * simplify assertj Signed-off-by: Gregor Zeitlinger <[email protected]> * simplify assertj Signed-off-by: Gregor Zeitlinger <[email protected]> --------- Signed-off-by: Gregor Zeitlinger <[email protected]>
1 parent 2c3e258 commit b6e5865

File tree

23 files changed

+122
-143
lines changed

23 files changed

+122
-143
lines changed

integration-tests/it-common/pom.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,6 @@
2424
</license>
2525
</licenses>
2626

27-
<dependencies>
28-
<dependency>
29-
<groupId>org.testcontainers</groupId>
30-
<artifactId>testcontainers</artifactId>
31-
<scope>test</scope>
32-
</dependency>
33-
</dependencies>
34-
3527
<build>
3628
<testResources>
3729
<testResource>

integration-tests/it-exporter/it-exporter-test/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@
4242
<artifactId>prometheus-metrics-exposition-formats</artifactId>
4343
<version>${project.version}</version>
4444
</dependency>
45-
<dependency>
46-
<groupId>org.testcontainers</groupId>
47-
<artifactId>testcontainers</artifactId>
48-
<scope>test</scope>
49-
</dependency>
5045
<dependency>
5146
<groupId>commons-io</groupId>
5247
<artifactId>commons-io</artifactId>

integration-tests/it-pushgateway/pom.xml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,7 @@
4747
<artifactId>prometheus-metrics-exporter-pushgateway</artifactId>
4848
<version>${project.version}</version>
4949
</dependency>
50-
<dependency>
51-
<groupId>org.testcontainers</groupId>
52-
<artifactId>testcontainers</artifactId>
53-
<scope>test</scope>
54-
</dependency>
50+
5551
<dependency>
5652
<groupId>io.prometheus</groupId>
5753
<artifactId>it-common</artifactId>

integration-tests/it-pushgateway/src/test/java/io/prometheus/metrics/it/pushgateway/PushGatewayIT.java

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

33
import static org.assertj.core.api.Assertions.assertThat;
44
import static org.assertj.core.api.Assertions.fail;
5-
import static org.assertj.core.data.Offset.offset;
65

76
import com.jayway.jsonpath.Criteria;
87
import com.jayway.jsonpath.Filter;
@@ -180,13 +179,13 @@ public void testProtobuf() throws IOException, InterruptedException {
180179

181180
private void assertMetrics() throws IOException, InterruptedException {
182181
double value = getValue("my_batch_job_duration_seconds", "job", "pushgateway-test-app");
183-
assertThat(value).isCloseTo(0.5, offset(0.0));
182+
assertThat(value).isEqualTo(0.5);
184183
value = getValue("file_sizes_bytes_bucket", "job", "pushgateway-test-app", "le", "512");
185-
assertThat(value).isCloseTo(0.0, offset(0.0));
184+
assertThat(value).isEqualTo(0.0);
186185
value = getValue("file_sizes_bytes_bucket", "job", "pushgateway-test-app", "le", "1024");
187-
assertThat(value).isCloseTo(2.0, offset(0.0));
186+
assertThat(value).isEqualTo(2.0);
188187
value = getValue("file_sizes_bytes_bucket", "job", "pushgateway-test-app", "le", "+Inf");
189-
assertThat(value).isCloseTo(3.0, offset(0.0));
188+
assertThat(value).isEqualTo(3.0);
190189
}
191190

192191
private double getValue(String name, String... labels) throws IOException, InterruptedException {
@@ -204,7 +203,7 @@ private double getValue(String name, String... labels) throws IOException, Inter
204203

205204
private void assertNativeHistogram() throws IOException, InterruptedException {
206205
double count = getNativeHistogramCount("file_sizes_bytes", "pushgateway-test-app");
207-
assertThat(count).isCloseTo(3, offset(0.0));
206+
assertThat(count).isEqualTo(3);
208207
}
209208

210209
private double getNativeHistogramCount(String name, String job)

integration-tests/pom.xml

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
34
<modelVersion>4.0.0</modelVersion>
45

56
<parent>
@@ -49,14 +50,18 @@
4950
</plugin>
5051
</plugins>
5152
</build>
52-
<dependencyManagement>
53-
<dependencies>
54-
<dependency>
55-
<groupId>org.testcontainers</groupId>
56-
<artifactId>testcontainers</artifactId>
57-
<version>1.19.8</version>
58-
<scope>test</scope>
59-
</dependency>
60-
</dependencies>
61-
</dependencyManagement>
53+
<dependencies>
54+
<dependency>
55+
<groupId>org.testcontainers</groupId>
56+
<artifactId>junit-jupiter</artifactId>
57+
<version>1.20.2</version>
58+
<scope>test</scope>
59+
<exclusions>
60+
<exclusion>
61+
<groupId>org.hamcrest</groupId>
62+
<artifactId>hamcrest-core</artifactId>
63+
</exclusion>
64+
</exclusions>
65+
</dependency>
66+
</dependencies>
6267
</project>

prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/HistogramTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,7 @@ private void assertExemplar(Histogram histogram, double value, String... labels)
11521152
assertThat(exemplar)
11531153
.as("No exemplar found in bucket [" + lowerBound + ", " + upperBound + "]")
11541154
.isNotNull();
1155-
assertThat(exemplar.getValue()).isCloseTo(value, offset(0.0));
1155+
assertThat(exemplar.getValue()).isEqualTo(value);
11561156
assertThat(exemplar.getLabels().size())
11571157
.as("" + exemplar.getLabels())
11581158
.isEqualTo(labels.length / 2);
@@ -1354,7 +1354,7 @@ public void testNoLabelsDefaultZeroValue() {
13541354
Histogram noLabels = Histogram.builder().name("test").build();
13551355
assertThat(getBucket(noLabels, 0.005).getCount()).isZero();
13561356
assertThat(getData(noLabels).getCount()).isZero();
1357-
assertThat(getData(noLabels).getSum()).isCloseTo(0.0, offset(0.0));
1357+
assertThat(getData(noLabels).getSum()).isEqualTo(0.0);
13581358
}
13591359

13601360
private ClassicHistogramBucket getBucket(Histogram histogram, double le, String... labels) {

prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/StatefulMetricTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.prometheus.metrics.core.metrics;
22

33
import static org.assertj.core.api.Assertions.assertThat;
4-
import static org.assertj.core.data.Offset.offset;
54

65
import java.lang.reflect.Field;
76
import java.util.Map;
@@ -55,17 +54,17 @@ public void testClearNoLabels() {
5554
Counter counter = Counter.builder().name("test").build();
5655
counter.inc();
5756
assertThat(counter.collect().getDataPoints()).hasSize(1);
58-
assertThat(counter.collect().getDataPoints().get(0).getValue()).isCloseTo(1.0, offset(0.0));
57+
assertThat(counter.collect().getDataPoints().get(0).getValue()).isEqualTo(1.0);
5958

6059
counter.clear();
6160
// No labels is always present, but as no value has been observed after clear() the value should
6261
// be 0.0
6362
assertThat(counter.collect().getDataPoints()).hasSize(1);
64-
assertThat(counter.collect().getDataPoints().get(0).getValue()).isCloseTo(0.0, offset(0.0));
63+
assertThat(counter.collect().getDataPoints().get(0).getValue()).isEqualTo(0.0);
6564

6665
// Making inc() works correctly after clear()
6766
counter.inc();
6867
assertThat(counter.collect().getDataPoints()).hasSize(1);
69-
assertThat(counter.collect().getDataPoints().get(0).getValue()).isCloseTo(1.0, offset(0.0));
68+
assertThat(counter.collect().getDataPoints().get(0).getValue()).isEqualTo(1.0);
7069
}
7170
}

prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/SummaryTest.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,12 @@ public void testMaxAge() throws InterruptedException {
123123
.help("help")
124124
.register(registry);
125125
summary.observe(8.0);
126-
assertThat(getQuantile(summary, 0.99, Labels.EMPTY))
127-
.isCloseTo(8.0, offset(0.0)); // From bucket 1.
126+
assertThat(getQuantile(summary, 0.99, Labels.EMPTY)).isEqualTo(8.0); // From bucket 1.
128127
Thread.sleep(600);
129-
assertThat(getQuantile(summary, 0.99, Labels.EMPTY))
130-
.isCloseTo(8.0, offset(0.0)); // From bucket 2.
128+
assertThat(getQuantile(summary, 0.99, Labels.EMPTY)).isEqualTo(8.0); // From bucket 2.
131129
Thread.sleep(600);
132130
assertThat(getQuantile(summary, 0.99, Labels.EMPTY))
133-
.isCloseTo(Double.NaN, offset(0.0)); // Bucket 1 again, now it is empty.
131+
.isEqualTo(Double.NaN); // Bucket 1 again, now it is empty.
134132
}
135133

136134
@Test

prometheus-metrics-exporter-opentelemetry/pom.xml

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
34
<modelVersion>4.0.0</modelVersion>
45

56
<parent>
@@ -56,6 +57,12 @@
5657
<artifactId>wiremock</artifactId>
5758
<version>3.5.4</version>
5859
<scope>test</scope>
60+
<exclusions>
61+
<exclusion>
62+
<groupId>org.hamcrest</groupId>
63+
<artifactId>hamcrest-core</artifactId>
64+
</exclusion>
65+
</exclusions>
5966
</dependency>
6067
<dependency>
6168
<groupId>org.awaitility</groupId>
@@ -88,37 +95,37 @@
8895
</resource>
8996
</resources>
9097
<plugins>
91-
<plugin>
92-
<groupId>org.apache.maven.plugins</groupId>
93-
<artifactId>maven-dependency-plugin</artifactId>
94-
<version>3.6.0</version>
95-
<executions>
96-
<execution>
97-
<id>copy</id>
98-
<phase>package</phase>
99-
<goals>
100-
<goal>copy</goal>
101-
</goals>
102-
</execution>
103-
</executions>
104-
<configuration>
105-
<artifactItems>
106-
<artifactItem>
107-
<groupId>io.opentelemetry</groupId>
108-
<artifactId>opentelemetry-api</artifactId>
109-
<version>${otel.version}</version>
110-
<outputDirectory>${project.basedir}/src/main/resources/lib/</outputDirectory>
111-
</artifactItem>
112-
<artifactItem>
113-
<groupId>io.opentelemetry</groupId>
114-
<artifactId>opentelemetry-context</artifactId>
115-
<version>${otel.version}</version>
116-
<outputDirectory>${project.basedir}/src/main/resources/lib/</outputDirectory>
117-
</artifactItem>
118-
</artifactItems>
119-
<!-- other configurations here -->
120-
</configuration>
121-
</plugin>
98+
<plugin>
99+
<groupId>org.apache.maven.plugins</groupId>
100+
<artifactId>maven-dependency-plugin</artifactId>
101+
<version>3.6.0</version>
102+
<executions>
103+
<execution>
104+
<id>copy</id>
105+
<phase>package</phase>
106+
<goals>
107+
<goal>copy</goal>
108+
</goals>
109+
</execution>
110+
</executions>
111+
<configuration>
112+
<artifactItems>
113+
<artifactItem>
114+
<groupId>io.opentelemetry</groupId>
115+
<artifactId>opentelemetry-api</artifactId>
116+
<version>${otel.version}</version>
117+
<outputDirectory>${project.basedir}/src/main/resources/lib/</outputDirectory>
118+
</artifactItem>
119+
<artifactItem>
120+
<groupId>io.opentelemetry</groupId>
121+
<artifactId>opentelemetry-context</artifactId>
122+
<version>${otel.version}</version>
123+
<outputDirectory>${project.basedir}/src/main/resources/lib/</outputDirectory>
124+
</artifactItem>
125+
</artifactItems>
126+
<!-- other configurations here -->
127+
</configuration>
128+
</plugin>
122129
<!--
123130
<plugin>
124131
<groupId>org.apache.maven.plugins</groupId>

prometheus-metrics-instrumentation-caffeine/src/test/java/io/prometheus/metrics/instrumentation/caffeine/CacheMetricsCollectorTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.prometheus.metrics.instrumentation.caffeine;
22

33
import static org.assertj.core.api.Assertions.assertThat;
4-
import static org.assertj.core.data.Offset.offset;
54
import static org.mockito.ArgumentMatchers.anyString;
65
import static org.mockito.Mockito.mock;
76
import static org.mockito.Mockito.when;
@@ -120,7 +119,7 @@ private void assertCounterMetric(
120119
final CounterSnapshot.CounterDataPointSnapshot dataPointSnapshot =
121120
(CounterSnapshot.CounterDataPointSnapshot) getDataPointSnapshot(registry, name, cacheName);
122121

123-
assertThat(dataPointSnapshot.getValue()).isCloseTo(value, offset(0.0));
122+
assertThat(dataPointSnapshot.getValue()).isEqualTo(value);
124123
}
125124

126125
private DataPointSnapshot getDataPointSnapshot(

0 commit comments

Comments
 (0)