local Rx = require 'Rx'

local Notification = Rx.Notification
local Recorded = Rx.testing.Recorded

--------------------------------------------------------------------------------

local mockObserverPrototype = {

    Rx.Observer, -- superclass

    scheduler = false,

    messages = false,

}

--------------------------------------------------------------------------------

function mockObserverPrototype:__init(scheduler)

    self.scheduler = scheduler
    self.messages = {}

end

--------------------------------------------------------------------------------

local function addMessage(self, notification)

    local messages = self.messages
    local nMessages = #messages

    messages[nMessages + 1] = Recorded(self.scheduler:clock(), notification)

end

--------------------------------------------------------------------------------

function mockObserverPrototype:onNext(...)

    addMessage(self, Notification.createOnNext(...))

end

--------------------------------------------------------------------------------

function mockObserverPrototype:onError(...)

    addMessage(self, Notification.createOnError(...))

end

--------------------------------------------------------------------------------

function mockObserverPrototype:onCompleted()

    addMessage(self, Notification.createOnCompleted())

end

--------------------------------------------------------------------------------

return Rx.Class('Rx.testing.MockObserver', mockObserverPrototype)
