Is it possible to freeze System.currentTimeMillis() for testing

前端 未结 6 2532
孤街浪徒
孤街浪徒 2021-02-20 02:24

For some testing purposes I would like to predict exactly what System.currentTimeMillis() will return. Is there any way in which I can freeze or manually set what w

6条回答
  •  借酒劲吻你
    2021-02-20 02:55

    The new java.time package built into Java 8 includes a java.time.Clock interface "to allow alternate clocks to be plugged in as and when required. Use this instead.

提交回复
热议问题