open-telemetry / open-telemetry/opentelemetry-java

Avoid extending assertj Assertions in OpenTelemetryAssertions

Open
#6,459 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug
Dominant language
Java
Stars
2.5k
Forks
1k
Avg merge
3d 17h
Merged PRs (30d)
58

Description

Describe the bug
Because OpenTelemetryAssertions extends Assertions, it brings in assertThat(Object) (spelled assertThat(T)) from assertj. With a static import of assertThat, the extends prevents you from mixing OpenTelemetryAssertions with Truth. Since all the methods are static, it is unclear why it even extends Assertions. I didn't see a previous issue where this was discussed.

Removing the extends would be an API breakage, and it appears this class is stable. So a fix might have to be in the form of a new class, which is unfortunate.

Steps to reproduce

import static com.google.common.truth.Truth.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;

...
// both method <T>assertThat(T) in OpenTelemetryAssertions and method assertThat(Object) in Truth match
assertThat(new Object()).isNotNull();

What did you expect to see?
Mix assertThat from multiple test libraries sources and have them only work on their specific types.

What did you see instead?
Compile error when using a static import.

Test.java:115: error: reference to assertThat is ambiguous
    assertThat(new Object()).isNotNull();
    ^
  both method <T>assertThat(T) in OpenTelemetryAssertions and method assertThat(Object) in Truth match
  where T is a type-variable:
    T extends Object declared in method <T>assertThat(T)
1 error

The workaround is to use a non-static import for OpenTelemetryAssertions and spell out OpenTelemetryAssertions.assertThat explicitly in tests instead.

What version and what artifacts are you using?
io.opentelemetry:opentelemetry-sdk-testing:1.36.0. Build environment is Gradle.

Environment
Compiler: AdoptOpenJDK 1.8.0_275-b01
OS: Debian unstable

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the OpenTelemetryAssertions class and reproduce the Java static-import example using Truth and OpenTelemetryAssertions.assertThat. Read the issue discussion about API compatibility and possible replacement classes; done means the reported ambiguous call is resolved without an unaddressed break for the stable existing API.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
testing-qa
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.