-
Notifications
You must be signed in to change notification settings - Fork 1k
Adjustment of behaviour of hasXAttributesSatisfying and hasXAttribute… #4882
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e1e16a0
Adjustment of behaviour of hasXAttributesSatisfying and hasXAttribute…
lmonkiewicz 2f89145
Cleanup
lmonkiewicz 55424f4
Merge remote-tracking branch 'origin/main' into 4778-signed-cla
lmonkiewicz 904cf08
Additional test coverage for new assertion method
lmonkiewicz 6b81f29
Added javadoc on assertions
lmonkiewicz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
19 changes: 18 additions & 1 deletion
19
docs/apidiffs/current_vs_latest/opentelemetry-sdk-testing.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,19 @@ | ||
| Comparing source compatibility of against | ||
| No changes. | ||
| *** MODIFIED CLASS: PUBLIC ABSTRACT io.opentelemetry.sdk.testing.assertj.AbstractPointAssert (not serializable) | ||
| === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 | ||
| +++ NEW METHOD: PUBLIC(+) FINAL(+) io.opentelemetry.sdk.testing.assertj.AbstractPointAssert hasAttributesSatisfyingExactly(io.opentelemetry.sdk.testing.assertj.AttributeAssertion[]) | ||
| +++ NEW METHOD: PUBLIC(+) FINAL(+) io.opentelemetry.sdk.testing.assertj.AbstractPointAssert hasAttributesSatisfyingExactly(java.lang.Iterable) | ||
| *** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.sdk.testing.assertj.DoubleExemplarAssert (not serializable) | ||
| === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 | ||
| +++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.assertj.DoubleExemplarAssert hasFilteredAttributesSatisfyingExactly(io.opentelemetry.sdk.testing.assertj.AttributeAssertion[]) | ||
| +++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.assertj.DoubleExemplarAssert hasFilteredAttributesSatisfyingExactly(java.lang.Iterable) | ||
| *** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.sdk.testing.assertj.EventDataAssert (not serializable) | ||
| === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 | ||
| +++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.assertj.EventDataAssert hasAttributesSatisfying(io.opentelemetry.sdk.testing.assertj.AttributeAssertion[]) | ||
| +++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.assertj.EventDataAssert hasAttributesSatisfying(java.lang.Iterable) | ||
| +++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.assertj.EventDataAssert hasAttributesSatisfyingExactly(io.opentelemetry.sdk.testing.assertj.AttributeAssertion[]) | ||
| +++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.assertj.EventDataAssert hasAttributesSatisfyingExactly(java.lang.Iterable) | ||
| *** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.sdk.testing.assertj.LongExemplarAssert (not serializable) | ||
| === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 | ||
| +++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.assertj.LongExemplarAssert hasFilteredAttributesSatisfyingExactly(io.opentelemetry.sdk.testing.assertj.AttributeAssertion[]) | ||
| +++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.assertj.LongExemplarAssert hasFilteredAttributesSatisfyingExactly(java.lang.Iterable) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -93,21 +93,41 @@ public final PointAssertT hasAttributes(Map.Entry<? extends AttributeKey<?>, ?>. | |
| } | ||
|
|
||
| /** | ||
| * Asserts the point has attributes matching all {@code assertions} and no more. Assertions can be | ||
| * created using methods like {@link OpenTelemetryAssertions#satisfies(AttributeKey, | ||
| * Asserts the point has attributes matching all {@code assertions}. Assertions can be created | ||
| * using methods like {@link OpenTelemetryAssertions#satisfies(AttributeKey, | ||
| * OpenTelemetryAssertions.LongAssertConsumer)}. | ||
| */ | ||
| public final PointAssertT hasAttributesSatisfying(AttributeAssertion... assertions) { | ||
| return hasAttributesSatisfying(Arrays.asList(assertions)); | ||
| } | ||
|
|
||
| /** | ||
| * Asserts the point has attributes matching all {@code assertions} and no more. Assertions can be | ||
| * created using methods like {@link OpenTelemetryAssertions#satisfies(AttributeKey, | ||
| * Asserts the point has attributes matching all {@code assertions}. Assertions can be created | ||
| * using methods like {@link OpenTelemetryAssertions#satisfies(AttributeKey, | ||
| * OpenTelemetryAssertions.LongAssertConsumer)}. | ||
| */ | ||
| public final PointAssertT hasAttributesSatisfying(Iterable<AttributeAssertion> assertions) { | ||
| AssertUtil.assertAttributes(actual.getAttributes(), assertions); | ||
| return myself; | ||
| } | ||
|
|
||
| /** | ||
| * Asserts the point has attributes matching all {@code assertions} and no more. Assertions can be | ||
| * created using methods like {@link OpenTelemetryAssertions#satisfies(AttributeKey, | ||
| * OpenTelemetryAssertions.LongAssertConsumer)}. | ||
| */ | ||
| public final PointAssertT hasAttributesSatisfyingExactly(AttributeAssertion... assertions) { | ||
| return hasAttributesSatisfyingExactly(Arrays.asList(assertions)); | ||
| } | ||
|
|
||
| /** | ||
| * Asserts the point has attributes matching all {@code assertions} and no more. Assertions can be | ||
| * created using methods like {@link OpenTelemetryAssertions#satisfies(AttributeKey, | ||
| * OpenTelemetryAssertions.LongAssertConsumer)}. | ||
| */ | ||
| public final PointAssertT hasAttributesSatisfyingExactly( | ||
| Iterable<AttributeAssertion> assertions) { | ||
| AssertUtil.assertAttributesExactly(actual.getAttributes(), assertions); | ||
| return myself; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add coverage for the new code?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I'll try to finish this one tomorrow :) |
||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
sdk/testing/src/test/java/io/opentelemetry/sdk/testing/assertj/AssertUtilTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.sdk.testing.assertj; | ||
|
|
||
| import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; | ||
| import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
|
||
| import io.opentelemetry.api.common.AttributeKey; | ||
| import io.opentelemetry.api.common.Attributes; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| public class AssertUtilTest { | ||
|
mateuszrzeszutek marked this conversation as resolved.
Outdated
|
||
| private static final AttributeKey<Boolean> WARM = AttributeKey.booleanKey("warm"); | ||
| private static final AttributeKey<Long> TEMPERATURE = AttributeKey.longKey("temperature"); | ||
| private static final AttributeKey<Double> LENGTH = AttributeKey.doubleKey("length"); | ||
| private static final AttributeKey<List<String>> COLORS = AttributeKey.stringArrayKey("colors"); | ||
|
|
||
| private static final Attributes ATTRIBUTES = | ||
| Attributes.builder() | ||
| .put(WARM, true) | ||
| .put(TEMPERATURE, 30) | ||
| .put(LENGTH, 1.2) | ||
| .put(COLORS, Arrays.asList("red", "blue")) | ||
| .build(); | ||
|
|
||
| @Test | ||
| void assertAttributesShouldThrowIfNoAttributeMatch() { | ||
| List<AttributeAssertion> assertions = Arrays.asList(equalTo(WARM, false)); | ||
|
|
||
| assertThatThrownBy(() -> AssertUtil.assertAttributes(ATTRIBUTES, assertions)) | ||
| .isInstanceOf(AssertionError.class); | ||
| } | ||
|
|
||
| @Test | ||
| void assertAttributesShouldNotThrowIfSomeAttributesMatch() { | ||
| List<AttributeAssertion> assertions = Arrays.asList(equalTo(WARM, true)); | ||
|
|
||
| AssertUtil.assertAttributes(ATTRIBUTES, assertions); | ||
| } | ||
|
|
||
| @Test | ||
| void assertAttributesShouldNotThrowIfAllAttributesMatch() { | ||
| List<AttributeAssertion> assertions = | ||
| Arrays.asList( | ||
| equalTo(WARM, true), | ||
| equalTo(TEMPERATURE, 30L), | ||
| equalTo(LENGTH, 1.2), | ||
| equalTo(COLORS, Arrays.asList("red", "blue"))); | ||
|
|
||
| AssertUtil.assertAttributes(ATTRIBUTES, assertions); | ||
| } | ||
|
|
||
| @Test | ||
| void assertAttributesExactlyShouldThrowIfNoAttributeMatch() { | ||
| List<AttributeAssertion> assertions = Arrays.asList(equalTo(WARM, false)); | ||
|
|
||
| assertThatThrownBy(() -> AssertUtil.assertAttributesExactly(ATTRIBUTES, assertions)) | ||
| .isInstanceOf(AssertionError.class); | ||
| } | ||
|
|
||
| @Test | ||
| void assertAttributesExactlyShouldThrowIfSomeAttributesMatch() { | ||
| List<AttributeAssertion> assertions = Arrays.asList(equalTo(WARM, true)); | ||
|
|
||
| assertThatThrownBy(() -> AssertUtil.assertAttributesExactly(ATTRIBUTES, assertions)) | ||
| .isInstanceOf(AssertionError.class); | ||
| } | ||
|
|
||
| @Test | ||
| void assertAttributesExactlyShouldNotThrowIfAllAttributesMatch() { | ||
| List<AttributeAssertion> assertions = | ||
| Arrays.asList( | ||
| equalTo(WARM, true), | ||
| equalTo(TEMPERATURE, 30L), | ||
| equalTo(LENGTH, 1.2), | ||
| equalTo(COLORS, Arrays.asList("red", "blue"))); | ||
|
|
||
| AssertUtil.assertAttributesExactly(ATTRIBUTES, assertions); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.