I tried to create mock for java.time.ZonedDateTime using PowerMockito and I was expecting the mock object for ZonedDateTime. Instead, actual object is getting created and he
Create a method in your class like
public class SomeClass{
public static void main(String[] args) {
LocalDateTime now = getCurrentLocalDateTime();
System.out.println(now);
}
private LocalDateTime getCurrentLocalDateTime() {
return LocalDateTime.now();
}
}
And in the Test Class you use
@PrepareForTest(SomeClass.class)
@RunWith(PowerMockRunner.class)
In TestCase
LocalDateTime tommorow= LocalDateTime.now().plusDays(1);
SomeClass classUnderTest = PowerMockito.spy(new SomeClass());
PowerMockito.when(classUnderTest, "getCurrentLocalDateTime").thenReturn(tommorow);