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

Closed
novaterata opened this Issue Dec 21, 2016 · 0 comments

Projects

None yet

2 participants

@novaterata

Please provide the following information:

  • Version of JMockit that was used:
    1.30

  • Description of the problem or enhancement request:

 package com.foo.bar;

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

import java.time.Duration;

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

public class ConcerningDurationProvider {

    @Test
    public void shouldThrowIllegalArgumentException(@Mocked DurationProvider durationProvider) {
        DurationConsumer durationConsumer = new DurationConsumer(durationProvider);
        new Expectations() {{
            durationProvider.getDuration();
            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

	at com.foo.bar.ConcerningDurationProvider$1.<init>(ConcerningDurationProvider.java:19)
	at com.foo.bar.ConcerningDurationProvider.shouldThrowIllegalArgumentException(ConcerningDurationProvider.java:18)

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