Skip to content

Commit 3b2944f

Browse files
authored
Coding style: simplify assertions (open-telemetry#17418)
1 parent b6d6fce commit 3b2944f

12 files changed

Lines changed: 25 additions & 34 deletions

File tree

.github/agents/code-review-and-fix.agent.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ Auto-fix boundaries:
142142
lambdas where the lambda parameter is already an `AbstractAssert` (e.g.,
143143
`AbstractStringAssert`). Calls like `taskId.contains(jobName)` on the assert object are
144144
already valid AssertJ assertions; do not wrap them in `assertThat(...).isTrue()`
145+
- AssertJ `.as(...)` descriptions and `.withFailMessage(...)` in tests — remove them
146+
and prefer direct assertions whose failure output already exposes the unexpected values
145147
- deterministic semconv constant handling aligned with repository rules
146148
- missing test-task wiring patterns with clear canonical form
147149
- missing `testInstrumentation` cross-version references — when a javaagent module belongs

.github/agents/knowledge/testing-general-patterns.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
- JUnit 5, AssertJ assertions (not JUnit `assertEquals`/`assertTrue`).
1111
- Test classes and methods should be package-private (no `public`).
12+
- Do not use AssertJ `.as(...)` descriptions or `.withFailMessage(...)` in tests.
13+
Prefer direct assertions whose failure output shows the unexpected values.
1214

1315
## Test Resource Cleanup
1416

instrumentation/c3p0-0.9/testing/src/main/java/io/opentelemetry/instrumentation/c3p0/AbstractC3p0InstrumentationTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@ void shouldReportMetrics() throws Exception {
8080
private void assertDataSourceMetrics(PooledDataSource dataSource) {
8181
String dataSourceName = dataSource.getDataSourceName();
8282

83-
assertThat(dataSourceName)
84-
.as("c3p0 generates a unique pool name if it's not explicitly provided")
85-
.isNotEmpty();
83+
assertThat(dataSourceName).isNotEmpty();
8684

8785
DbConnectionPoolMetricsAssertions.create(
8886
testing(), INSTRUMENTATION_NAME, dataSource.getDataSourceName())

instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/test/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/JettyHttpClient9HttpCallTest.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,7 @@ void inputStreamListenerBodyIsDelivered() throws Exception {
101101
body = buf.toByteArray();
102102
}
103103

104-
assertThat(body)
105-
.as(
106-
"Response body must not be empty — if it is, the OTel proxy is missing "
107-
+ "DemandedContentListener and Jetty filters it out before delivering content")
108-
.isNotEmpty();
104+
assertThat(body).isNotEmpty();
109105
assertThat(new String(body, UTF_8)).isEqualTo(EXPECTED_BODY);
110106
}
111107
}

instrumentation/oshi/library/src/test/java/io/opentelemetry/instrumentation/oshi/ProcessMetricsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ protected InstrumentationExtension testing() {
4545

4646
@Test
4747
void verifyObservablesAreNotEmpty() {
48-
assertThat(observables).as("List of observables").isNotEmpty();
48+
assertThat(observables).isNotEmpty();
4949
}
5050
}

instrumentation/oshi/library/src/test/java/io/opentelemetry/instrumentation/oshi/SystemMetricsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ protected InstrumentationExtension testing() {
4545

4646
@Test
4747
void verifyObservablesAreNotEmpty() {
48-
assertThat(observables).as("List of observables").isNotEmpty();
48+
assertThat(observables).isNotEmpty();
4949
}
5050
}

instrumentation/servlet/servlet-5.0/tomcat-testing/src/test/java/io/opentelemetry/javaagent/instrumentation/servlet/v5_0/tomcat/TomcatServlet5WebXmlFilterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ private static void copyClassFile(Class<?> clazz, File targetDir) throws Excepti
137137
String classFileName = clazz.getSimpleName() + ".class";
138138
String classResourcePath = clazz.getName().replace('.', '/') + ".class";
139139
try (InputStream is = clazz.getClassLoader().getResourceAsStream(classResourcePath)) {
140-
assertThat(is).as("Class file resource for " + clazz.getName()).isNotNull();
140+
assertThat(is).isNotNull();
141141
Files.copy(
142142
is, new File(targetDir, classFileName).toPath(), StandardCopyOption.REPLACE_EXISTING);
143143
}

instrumentation/tomcat/tomcat-jdbc/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/tomcat/jdbc/TomcatJdbcInstrumentationTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ void shouldReportMetrics() throws Exception {
6262
}
6363

6464
private static void assertConnectionPoolMetrics(String poolName) {
65-
assertThat(poolName)
66-
.as("tomcat-jdbc generates a unique pool name if it's not explicitly provided")
67-
.isNotEmpty();
65+
assertThat(poolName).isNotEmpty();
6866

6967
DbConnectionPoolMetricsAssertions.create(testing, "io.opentelemetry.tomcat-jdbc", poolName)
7068
// no timeouts happen during this test

javaagent-internal-logging-application/src/test/java/io/opentelemetry/javaagent/logging/application/ConcurrentIntegrationTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ void shouldLogEverything() throws InterruptedException {
5656

5757
futures.forEach(f -> f.cancel(true));
5858

59-
assertThat(logMessages)
60-
.as("Verify that the application logger bridge did not lose any messages")
61-
.hasSize(count.get());
59+
assertThat(logMessages).hasSize(count.get());
6260
}
6361

6462
private static final class TestLogger implements InternalLogger {

javaagent/src/test/java/io/opentelemetry/javaagent/ShadingTest.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,7 @@ void agentJarContainsOnlyExpectedEntries() throws Exception {
4747
});
4848
}
4949

50-
assertThat(unexpectedEntries)
51-
.as(
52-
"Agent jar should only contain entries with expected prefixes: %s",
53-
EXPECTED_ENTRY_PREFIXES)
54-
.isEmpty();
50+
assertThat(unexpectedEntries).isEmpty();
5551
}
5652

5753
private static String getAgentJarPath() {

0 commit comments

Comments
 (0)