how to use mockito spy to redirect a method call?
问题 I have a method that relies on "now" Date object. I want to write a unit-test for it. So I want to inject a fake-fixed "now" date (making the test determine). I have tried to inject a spy like this: private ImagesSorter setServerWithSpyImageSorter(User user, List imagesAsInsertionOrder, Date fakeNowDate) throws IOException { ImagesSorter imagesSorter = spy(new ImagesSorter()); when(imagesSorter.sortImages(imagesAsInsertionOrder, user)).thenReturn(imagesSorter.sortImages(imagesAsInsertionOrder