Mockito: How to mock an interface of JodaTime

前端 未结 3 1039
时光说笑
时光说笑 2020-12-09 06:06

I use JodaTime#DateTime, and I need to mock its behavior. Since it is not possible to directly mock JodaTime#DateTime, I create an interface of it<

3条回答
  •  误落风尘
    2020-12-09 06:32

    I think you're definitely on the right path. Creating the Clock interface for mocking is definitely a good idea.

    One thing I don't see in your code: injecting the mocked clock into the printProcessor. After creating the mock, I think you need something along the lines of:

    printProcessor.setClock(clock)
    

    (this goes before you call getPrintJobName. This setter should set the jodaTime property in your PrintProcessor class)

    I'm used to EasyMock, so I might be wrong, but I'm pretty sure you will also need to set expectations for the getFourPM_EST and getSevenPM_EST calls.

提交回复
热议问题