from ._MessageBusStub import MessageBusStub
from testdoubleutil import SpyCall


class MessageBusSpy(MessageBusStub):
    def __init__(self, send_message_ret=None, publish_event_ret=None):
        super(MessageBusSpy, self).__init__(send_message_ret, publish_event_ret)

        self.publish_event_call = SpyCall()
        self.send_message_call = SpyCall()
        self.subscribe_call = SpyCall()
        self.reply_message_call = SpyCall()
        self.reply_event_call = SpyCall()

    def publish_event(self, event):
        self.publish_event_call.register_call(event)
        return super(MessageBusSpy, self).publish_event(event)

    def send_message(self, component, message):
        self.send_message_call.register_call(component, message)
        return super(MessageBusSpy, self).send_message(component, message)

    def subscribe(self, subject):
        self.subscribe_call.register_call(subject)

    def reply_message(self, message, reply_message):
        self.reply_message_call.register_call(message, reply_message)

    def reply_event(self, event, reply_message):
        self.reply_event_call.register_call(event, reply_message)
