Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

charlesritchea opened this issue Dec 21, 2016 · 1 comment


Copy link

@charlesritchea charlesritchea commented Dec 21, 2016

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

This comment has been minimized.

Copy link

@nicktar nicktar commented Jul 13, 2017

Shouldn't this be extended to exclude all non-mockable types from cascading? I'm refering to java.lang.*

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants
You can’t perform that action at this time.