Avatar
0
Vu Luong Anh Pundit
Cách tạo mock ScheduledExecutorService cho EzyAppContext khi test
https://github.com/youngmonkeys/ezyfox-server/issues/68
. Em dùng Mockito để khởi tạo EzyAppContext: EzyAppContext appContext = mock(EzyAppContext.class). Nhưng làm vậy context.get(ScheduledExecutorService.class) trả về null:
<img class="alignnone size-full wp-image-326" src="https://stackask.com/wp-content/uploads/2021/07/Screen-Shot-2021-07-30-at-16.52.13-1.png" alt="" />
Cho em hỏi nên khởi tạo EzyAppContext như nào ạ?
  • Answer
ezyfox ezyfox-server
Remain: 5
1 Answer
Avatar
monkey Enlightened
monkey Enlightened
The Best Answer
em khởi tạo như vậy là đúng rồi em ạ em mock tiếp thế này:
ScheduledExecutorService executorService = mock(ScheduledExecutorService.class);
when(context.get(ScheduledExecutorService.class)).thenReturn(executorService);
em nhé
  • 1
  • Reply