 kTestFilename = 'test.log'
 
 describe 'ProcessingChainEntrance', ->
+  setup_mocking()
+
   beforeEach (done) ->
-    @journal = sinon.mock(new Journal(kTestFilename))
-    @replication = sinon.mock({start: (->), send: (->)})
-    @engine = sinon.mock(new TradeEngine())
-    @pce = new ProcessingChainEntrance(@engine.object, @journal.object, @replication.object)
-    done()
+    @journal = new Journal(kTestFilename)
+    @replication = {start: (->), send: (->)}
+    @engine = new TradeEngine()
 
-  afterEach (done) ->
-    @journal.verify()
-    @replication.verify()
-    @engine.verify()
+    @mockify 'journal'
+    @mockify 'replication'
+    @mockify 'engine'
+
+    @pce = new ProcessingChainEntrance(@engine, @journal, @replication)
     done()
 
   it 'should intialize the transaction log and replication when starting', (done) ->
-    @journal.expects('start').once().returns(then: ->)
-    @replication.expects('start').once().returns(then: ->)
+    @_journal.expects('start').once().returns(then: ->)
+    @_replication.expects('start').once().returns(then: ->)
 
     @pce.start()
     done()


    operation = {kind: "TEST"}
    messageJson = JSON.stringify(operation)
    @journal.expects('record').once().withArgs(messageJson).returns(deferred.promise)
    @replication.expects('send').once().withArgs(messageJson).returns(deferred.promise)
    @engine.expects('execute_operation').once().withArgs(operation).returns("success")

    onComplete = (result) ->
      result.should.equal "success"

    deferred = Q.defer()
    deferred.resolve(undefined)

    @_journal.expects('record').once().returns(deferred.promise)
    @_replication.expects('send').once().returns(deferred.promise)
    @_engine.expects('execute_operation').once().throws("failure")

    onError = (error) ->
      error.name.should.equal "failure"
