Mocking LocalDateTime with PowerMockito
<p>I'm trying to mock a class using <code>LocalDateTime</code> objects in a method. Mocking the class causes a: </p>

<blockquote>
  <p>java.lang.IllegalStateException Reason: [source error]
  toInstant(java.time.ZoneOffset) not found in java.time.LocalDateTime</p>
</blockquote>

<p>I've found <a href="https://stackoverflow.com/questions/36908084/powermock-does-not-create-mock-for-java-time-zoneddatetime">this</a> related question (the class is final) - and tried to do so in the test setUp:</p>

<pre><code>PowerMockito.mockStatic(LocalDateTime.class);
</code></pre>

<p>But I still get the same error. A non-working test set-up is:</p>

<pre><code>@Before
public void setUp() {
    PowerMockito.mockStatic(LocalDateTime.class);
    LocalDateTime ld = LocalDateTime.now();
    Instant now = Instant.now();
    now.atOffset(ZoneOffset.UTC);
    PowerMockito.when(LocalDateTime.toInstant(any(ZoneOffset.class))).thenReturn(now); // &lt;= fails with above exception
}
</code></pre>

<p>How can I mock correctly the <code>LocalDateTime</code> class so that Mockito can call the method <code>toInstant</code>?</p>