Using Mockito to mock a local variable of a method

前端 未结 3 1347
走了就别回头了
走了就别回头了 2020-12-13 00:36

I have a class A that needs to the tested. The following is the definition of A:

public class A {
    public void methodOne(int arg         


        
3条回答
  •  渐次进展
    2020-12-13 00:50

    The best way to deal with such a problem is to use an injected Clock service, used to get new instances of DateTime. That way, your test can inject a mock Clock, which returns a specific DateTime instead of the current time.

    Note that the new Java 8 time API defines such a Clock class, specifically for that purpose.

提交回复
热议问题