Class TestObservationRegistryAssert

All Implemented Interfaces:
org.assertj.core.api.Assert<TestObservationRegistryAssert,TestObservationRegistry>, org.assertj.core.api.Descriptable<TestObservationRegistryAssert>, org.assertj.core.api.ExtensionPoints<TestObservationRegistryAssert,TestObservationRegistry>

public class TestObservationRegistryAssert extends ObservationRegistryAssert<TestObservationRegistryAssert,TestObservationRegistry>
Assertion methods for MeterRegistrys.

To create a new instance of this class, invoke assertThat(TestObservationRegistry) or then(TestObservationRegistry).

Since:
1.10.0
  • Constructor Details

  • Method Details

    • assertThat

      public static TestObservationRegistryAssert assertThat(TestObservationRegistry actual)
      Creates the assert object for TestObservationRegistry.
      Parameters:
      actual - mock observation registry to assert against
      Returns:
      meter registry assertions
    • then

      Creates the assert object for TestObservationRegistry.
      Parameters:
      actual - mock observation registry to assert against
      Returns:
      meter registry assertions
    • hasSingleObservationThat

      Verifies that there's only one Observation and continues assertions for it.
      Returns:
      this
      Throws:
      AssertionError - if there is none or more than one observation
    • hasObservationWithNameEqualTo

      public TestObservationRegistryAssert.That hasObservationWithNameEqualTo(String name)
      Verifies that there's only one Observation with a given name and continues assertions for it.
      Returns:
      this
      Throws:
      AssertionError - if there is no matching observation
    • hasObservationWithNameEqualToIgnoringCase

      public TestObservationRegistryAssert.That hasObservationWithNameEqualToIgnoringCase(String name)
      Verifies that there's at least one Observation with a given name (ignoring case) and continues assertions for the first found one.
      Returns:
      this
      Throws:
      AssertionError - if there is no matching observation
    • doesNotHaveAnyObservation

      public void doesNotHaveAnyObservation()
      Verifies that there are no observations registered.
      Throws:
      AssertionError - if there are any registered observations
    • hasHandledContextsThatSatisfy

      public TestObservationRegistryAssert hasHandledContextsThatSatisfy(org.assertj.core.api.ThrowingConsumer<List<io.micrometer.observation.Observation.Context>> contextConsumer)
      Verifies that all handled contexts satisfy the provided lambda.
      Parameters:
      contextConsumer - lambda to assert all handled contexts
      Returns:
      this
    • forAllObservationsWithNameEqualTo

      public TestObservationRegistryAssert forAllObservationsWithNameEqualTo(String name, Consumer<ObservationContextAssert> observationConsumer)
      Provides verification for all Observations having the given name.

      Examples:

      
       // assertions succeed
       assertThat(testObservationRegistry).forAllObservationsWithNameEqualTo("foo", observationContextAssert -> observationContextAssert.hasError());
      
       // assertions fail - assuming that there was a foo observation but none had errors
       assertThat(testObservationRegistry).forAllObservationsWithNameEqualTo("foo", observationContextAssert -> observationContextAssert.hasError());
      Parameters:
      name - searched Observation name
      observationConsumer - assertion to be executed for each Observation
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual value is null.
      AssertionError - if there is no Observation with the given name
      AssertionError - if there is an Observation with the given name but the additional assertion is not successful
    • forAllObservationsWithNameEqualToIgnoreCase

      public TestObservationRegistryAssert forAllObservationsWithNameEqualToIgnoreCase(String name, Consumer<ObservationContextAssert> observationConsumer)
      Provides verification for all Observations having the given name (ignoring case).

      Examples:

      
       // assertions succeed
       assertThat(testObservationRegistry).forAllObservationsWithNameEqualTo("foo", observationContextAssert -> observationContextAssert.hasError());
      
       // assertions fail - assuming that there was a foo observation but none had errors
       assertThat(testObservationRegistry).forAllObservationsWithNameEqualTo("foo", observationContextAssert -> observationContextAssert.hasError());
      Parameters:
      name - searched Observation name (ignoring case)
      observationConsumer - assertion to be executed for each Observation
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual value is null.
      AssertionError - if there is no Observation with the given name (ignoring case)
      AssertionError - if there is an Observation with the given name (ignoring case) but the additional assertion is not successful
    • hasNumberOfObservationsEqualTo

      public TestObservationRegistryAssert hasNumberOfObservationsEqualTo(int expectedNumberOfObservations)
      Verifies that there is a proper number of Observations.

      Examples:

      
       // assertions succeed
       assertThat(testObservationRegistry).hasNumberOfObservationsEqualTo(1);
      
       // assertions fail - assuming that there was only 1 observation
       assertThat(testObservationRegistry).hasNumberOfObservationsEqualTo(2);
      Parameters:
      expectedNumberOfObservations - expected number of Observations
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual value is null.
      AssertionError - if the number of Observations is different from the desired one
    • hasNumberOfObservationsWithNameEqualTo

      public TestObservationRegistryAssert hasNumberOfObservationsWithNameEqualTo(String observationName, int expectedNumberOfObservations)
      Verifies that there is a proper number of Observations with the given name.

      Examples:

      
       // assertions succeed
       assertThat(testObservationRegistry).hasNumberOfObservationsWithNameEqualTo("foo", 1);
      
       // assertions fail - assuming that there is only 1 observation with that name
       assertThat(testObservationRegistry).hasNumberOfObservationsWithNameEqualTo("foo", 2);
      Parameters:
      observationName - Observation name
      expectedNumberOfObservations - expected number of Observations with the given name
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual value is null.
      AssertionError - if the number of properly named Observations is different from the desired one
    • hasNumberOfObservationsWithNameEqualToIgnoreCase

      public TestObservationRegistryAssert hasNumberOfObservationsWithNameEqualToIgnoreCase(String observationName, int expectedNumberOfObservations)
      Verifies that there is a proper number of Observations with the given name (ignoring case).

      Examples:

      
       // assertions succeed
       assertThat(testObservationRegistry).hasNumberOfObservationsWithNameEqualToIgnoreCase("foo", 1);
      
       // assertions fail - assuming that there's only 1 such observation
       assertThat(testObservationRegistry).hasNumberOfObservationsWithNameEqualToIgnoreCase("foo", 2);
      Parameters:
      observationName - Observation name
      expectedNumberOfObservations - expected number of Observations with the given name (ignoring case)
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual value is null.
      AssertionError - if the number of properly named Observations is different from the desired one
    • hasAnObservationWithAKeyValue

      public TestObservationRegistryAssert hasAnObservationWithAKeyValue(String key, String value)
      Verifies that there is an Observation with a key value.

      Examples:

      
       // assertions succeed
       assertThat(testObservationRegistry).hasAnObservationWithAKeyValue("foo", "bar");
      
       // assertions fail - assuming that there is no such a key value in any observation
       assertThat(testObservationRegistry).hasAnObservationWithAKeyValue("foo", "bar");
      Parameters:
      key - expected key name
      value - expected key value
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual value is null.
      AssertionError - if there is no Observation with given key name and value
    • hasAnObservationWithAKeyValue

      public TestObservationRegistryAssert hasAnObservationWithAKeyValue(io.micrometer.common.KeyValue keyValue)
      Verifies that there is an Observation with a key value.

      Examples:

      
       // 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"));
      Parameters:
      keyValue - expected key value
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual value is null.
      AssertionError - if there is no Observation with given key name and value
      Since:
      1.12.0
    • hasAnObservationWithAKeyName

      public TestObservationRegistryAssert hasAnObservationWithAKeyName(String key)
      Verifies that there is an Observation with a key name.

      Examples:

      
       // assertions succeed
       assertThat(testObservationRegistry).hasAnObservationWithAKeyName("foo");
      
       // assertions fail - assuming that there are no observations with such a key name
       assertThat(testObservationRegistry).hasAnObservationWithAKeyName("foo");
      Parameters:
      key - expected key name
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual value is null.
      AssertionError - if there is no Observation with given key name
    • hasAnObservationWithAKeyValue

      public TestObservationRegistryAssert hasAnObservationWithAKeyValue(io.micrometer.common.docs.KeyName key, String value)
      Verifies that there is an Observation with a key value.

      Examples:

      
       // assertions succeed
       assertThat(testObservationRegistry).hasAnObservationWithAKeyValue(SomeKeyName.FOO, "bar");
      
       // assertions fail - assuming that there are no observations with such a key value
       assertThat(testObservationRegistry).hasAnObservationWithAKeyValue(SomeKeyName.FOO, "baz");
      Parameters:
      key - expected key name
      value - expected key value
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual value is null.
      AssertionError - if there is no Observation with given key name and value
    • hasAnObservationWithAKeyName

      public TestObservationRegistryAssert hasAnObservationWithAKeyName(io.micrometer.common.docs.KeyName key)
      Verifies that there is an Observation with a key name.

      Examples:

      
       // assertions succeed
       assertThat(testObservationRegistry).hasAnObservationWithAKeyName(SomeKeyName.FOO);
      
       // assertions fail - assuming that there are no observation with such a key name
       assertThat(testObservationRegistry).hasAnObservationWithAKeyName(SomeKeyName.FOO);
      Parameters:
      key - expected key name
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual value is null.
      AssertionError - if there is no Observation with given key name
    • hasAnObservation

      public TestObservationRegistryAssert hasAnObservation(Consumer<ObservationContextAssert> observationConsumer)
      Provides verification for all Observations.

      Examples:

      
       // assertions succeed
       assertThat(testObservationRegistry).hasAnObservation(observationContextAssert -> observationContextAssert.hasNameEqualTo("foo").hasError());
      
       // assertions fail - assuming that there was a foo observation but none had errors
       assertThat(testObservationRegistry).hasAnObservation(observationContextAssert -> observationContextAssert.hasNameEqualTo("foo").hasError());
      Parameters:
      observationConsumer - assertion to be executed for each Observation
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual value is null.
      AssertionError - if there is no Observation that passes the assertion
      Since:
      1.11.0