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

Closed
novaterata opened this Issue Dec 21, 2016 · 1 comment

Comments

3 participants
@novaterata

novaterata commented Dec 21, 2016

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

@nicktar

This comment has been minimized.

Show comment
Hide comment
@nicktar

nicktar Jul 13, 2017

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

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