Interface EventAsserting

All Known Implementing Classes:
CommandHandlingTestFixture.EventAsserter

public interface EventAsserting
Interface for comprehensive assertions on captured events, providing access to payload, meta-data, and subject. Instances are obtained via ExpectDsl.EventValidator.asserting(Consumer).

The API follows a consistent pattern for each event aspect:

All methods return this to allow method chaining.

  • Method Details

    • payloadType

      EventAsserting payloadType(Class<?> type)
      Asserts that the event payload is an instance of the specified type.
      Parameters:
      type - the expected payload class
      Returns:
      this for further assertions
      Throws:
      AssertionError - if the payload is not assignable to the expected type
    • payload

      <E> EventAsserting payload(E expected)
      Asserts that the event payload equals the expected value using Object.equals(Object).
      Type Parameters:
      E - the payload type
      Parameters:
      expected - the expected payload
      Returns:
      this for further assertions
      Throws:
      AssertionError - if the payloads are not equal
    • payloadExtracting

      <E, R> EventAsserting payloadExtracting(Function<E,R> extractor, R expected)
      Extracts a value from the event payload and asserts it equals the expected value. Useful for comparing specific fields without matching the entire payload.

      Example: a.payloadExtracting((MyEvent e) -> e.name(), "expected-name")

      Type Parameters:
      E - the payload type
      R - the extracted value type
      Parameters:
      extractor - function to extract a value from the payload
      expected - the expected extracted value (may be null)
      Returns:
      this for further assertions
      Throws:
      AssertionError - if the extracted values are not equal
    • payloadSatisfying

      <E> EventAsserting payloadSatisfying(Consumer<E> assertion)
      Asserts that the event payload satisfies custom assertions.
      Type Parameters:
      E - the payload type
      Parameters:
      assertion - consumer receiving the payload
      Returns:
      this for further assertions
      Throws:
      AssertionError - if thrown by the consumer
    • metaData

      EventAsserting metaData(Map<String,?> expected)
      Asserts that the event meta-data equals the expected map using Object.equals(Object).
      Parameters:
      expected - the expected meta-data
      Returns:
      this for further assertions
      Throws:
      AssertionError - if the meta-data maps are not equal
    • metaDataSatisfying

      EventAsserting metaDataSatisfying(Consumer<Map<String,?>> assertion)
      Asserts that the event meta-data satisfies custom assertions.
      Parameters:
      assertion - consumer receiving the meta-data map
      Returns:
      this for further assertions
      Throws:
      AssertionError - if thrown by the consumer
    • noMetaData

      EventAsserting noMetaData()
      Asserts that the event has no meta-data (empty map).
      Returns:
      this for further assertions
      Throws:
      AssertionError - if the meta-data is not empty
    • subject

      EventAsserting subject(String expected)
      Asserts that the event subject equals the expected value.
      Parameters:
      expected - the expected subject
      Returns:
      this for further assertions
      Throws:
      AssertionError - if the subjects are not equal
    • subjectSatisfying

      EventAsserting subjectSatisfying(Consumer<String> assertion)
      Asserts that the event subject satisfies custom assertions.
      Parameters:
      assertion - consumer receiving the subject
      Returns:
      this for further assertions
      Throws:
      AssertionError - if thrown by the consumer
    • commandSubject

      EventAsserting commandSubject()
      Asserts that the event subject equals the command's subject. Convenience method equivalent to subject(command.getSubject()).
      Returns:
      this for further assertions
      Throws:
      AssertionError - if the subjects do not match