open-telemetry / open-telemetry/opentelemetry-java
Avoid extending assertj Assertions in OpenTelemetryAssertions
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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