Skip to content
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

Add hasAnObservationWithAKeyValue() variant with KeyValue #4040

Merged
merged 1 commit into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.micrometer.observation.tck;

import io.micrometer.common.KeyValue;
import io.micrometer.common.docs.KeyName;
import io.micrometer.observation.Observation;
import org.assertj.core.api.ThrowingConsumer;
Expand Down Expand Up @@ -345,6 +346,25 @@ public TestObservationRegistryAssert hasAnObservationWithAKeyValue(String key, S
return this;
}

/**
* Verifies that there is an Observation with a key value.
* <p>
* Examples: <pre><code class='java'>
* // assertions succeed
* assertThat(testObservationRegistry).hasAnObservationWithAKeyValue(KeyValue.of("foo", "bar"));
*
* // assertions fail - assuming that there is no such a key value in any observation
* assertThat(testObservationRegistry).hasAnObservationWithAKeyValue(KeyValue.of("foo", "bar"));</code></pre>
* @param keyValue expected key value
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if there is no Observation with given key name and value
* @since 1.12.0
*/
public TestObservationRegistryAssert hasAnObservationWithAKeyValue(KeyValue keyValue) {
return hasAnObservationWithAKeyValue(keyValue.getKey(), keyValue.getValue());
}

/**
* Verifies that there is an Observation with a key name.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.micrometer.observation.tck;

import io.micrometer.common.KeyValue;
import io.micrometer.common.docs.KeyName;
import io.micrometer.observation.Observation;
import io.micrometer.observation.ObservationRegistry;
Expand Down Expand Up @@ -306,6 +307,9 @@ void should_fail_when_key_value_not_matched() {
thenThrownBy(
() -> TestObservationRegistryAssert.assertThat(registry).hasAnObservationWithAKeyValue("key", "value"))
.isInstanceOf(AssertionError.class);

thenThrownBy(() -> TestObservationRegistryAssert.assertThat(registry)
.hasAnObservationWithAKeyValue(KeyValue.of("key", "value"))).isInstanceOf(AssertionError.class);
}

@Test
Expand All @@ -314,6 +318,9 @@ void should_not_fail_when_key_value_matched() {

thenNoException().isThrownBy(
() -> TestObservationRegistryAssert.assertThat(registry).hasAnObservationWithAKeyValue("foo", "bar"));

thenNoException().isThrownBy(() -> TestObservationRegistryAssert.assertThat(registry)
.hasAnObservationWithAKeyValue(KeyValue.of("foo", "bar")));
}

@Test
Expand Down