SVCS - English Documentation
Loading...
Searching...
No Matches
svcs::test::cli::mocks::MockSubject Class Reference

A mock implementation of ISubject for testing event-driven components. More...

#include <MockSubject.hxx>

Inheritance diagram for svcs::test::cli::mocks::MockSubject:
svcs::services::ISubject

Public Member Functions

void attach (std::shared_ptr< IObserver > observer) override
 Satisfies the ISubject interface, but performs no operation.
void detach (std::shared_ptr< IObserver > observer) override
 Satisfies the ISubject interface, but performs no operation.
void notify (const Event &event) const override
 Captures the event into the internal notifications vector.
void clear ()
 Clears all captured notifications.
bool containsMessage (const std::string &message) const
 Checks if any captured notification's details contain the specified message substring.
bool containsEventType (Event::Type type) const
 Checks if any captured notification matches the specified Event Type.
void storeNotification (const Event &event)
 Stores a notification in the internal vector (alias for notify functionality).
void clearNotifications ()
 Clears all notifications from the internal storage.
const std::vector< Event > & getNotifications () const
 Returns a constant reference to the notifications vector for inspection.
Public Member Functions inherited from svcs::services::ISubject
virtual ~ISubject ()=default
 Virtual destructor.

Public Attributes

std::vector< Eventnotifications
 Stores a history of all events received via the notify() method for assertion.

Additional Inherited Members

Protected Attributes inherited from svcs::services::ISubject
std::vector< IObserver * > observers
 Collection of registered observers.

Detailed Description

A mock implementation of ISubject for testing event-driven components.

This mock allows test cases to:

  1. Capture all events published via notify() method.
  2. Inspect captured events for specific types or messages.
  3. Clear the event history between test cases.
  4. Verify that specific events were published during execution.

Member Function Documentation

◆ attach()

void svcs::test::cli::mocks::MockSubject::attach ( std::shared_ptr< IObserver > observer)
inlineoverridevirtual

Satisfies the ISubject interface, but performs no operation.

Parameters
observerThe observer to attach (unused in mock).

Implements svcs::services::ISubject.

◆ containsEventType()

bool svcs::test::cli::mocks::MockSubject::containsEventType ( Event::Type type) const
inlinenodiscard

Checks if any captured notification matches the specified Event Type.

Parameters
typeThe Event::Type enumeration value to search for.
Returns
true if an event of the specified type is found, false otherwise.

◆ containsMessage()

bool svcs::test::cli::mocks::MockSubject::containsMessage ( const std::string & message) const
inlinenodiscard

Checks if any captured notification's details contain the specified message substring.

Parameters
messageThe substring to search for within notification details.
Returns
true if a matching message is found, false otherwise.

◆ detach()

void svcs::test::cli::mocks::MockSubject::detach ( std::shared_ptr< IObserver > observer)
inlineoverridevirtual

Satisfies the ISubject interface, but performs no operation.

Parameters
observerThe observer to detach (unused in mock).

Implements svcs::services::ISubject.

◆ getNotifications()

const std::vector< Event > & svcs::test::cli::mocks::MockSubject::getNotifications ( ) const
inlinenodiscard

Returns a constant reference to the notifications vector for inspection.

Returns
Constant reference to the vector of captured events.

◆ notify()

void svcs::test::cli::mocks::MockSubject::notify ( const Event & event) const
inlineoverridevirtual

Captures the event into the internal notifications vector.

This is the core testing function, allowing test cases to verify that the correct events were published.

Parameters
eventThe constant reference to the event structure to be captured.

Implements svcs::services::ISubject.

◆ storeNotification()

void svcs::test::cli::mocks::MockSubject::storeNotification ( const Event & event)
inline

Stores a notification in the internal vector (alias for notify functionality).

Parameters
eventThe event to store.

The documentation for this class was generated from the following file: