IllegalArgumentException: Class java.time.Duration is not mockable #375

novaterata opened this Issue Dec 21, 2016 · 0 comments


None yet

2 participants


Please provide the following information:

  • Version of JMockit that was used:

  • Description of the problem or enhancement request:


import mockit.Expectations;
import mockit.Mocked;
import org.junit.Test;

import java.time.Duration;

import static;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;

public class ConcerningDurationProvider {

    public void shouldThrowIllegalArgumentException(@Mocked DurationProvider durationProvider) {
        DurationConsumer durationConsumer = new DurationConsumer(durationProvider);
        new Expectations() {{
            result = Duration.ofSeconds(123);
        assertThat(durationConsumer.getDuration(), is(equalTo(Duration.ofSeconds(123))));

    public interface DurationProvider {
        Duration getDuration();

    public static class DurationConsumer {
        private final DurationProvider durationProvider;

        public DurationConsumer(DurationProvider durationProvider) {

            this.durationProvider = durationProvider;

        public Duration getDuration() {
            return durationProvider.getDuration();


I'd expect this to pass, but instead I'm getting:

java.lang.IllegalArgumentException: Class java.time.Duration is not mockable


Why? I'm not mocking a Duration

@rliesenfeld rliesenfeld self-assigned this Dec 22, 2016
@rliesenfeld rliesenfeld added the bug label Dec 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment