JMockit - warning when taunting methods that expect a collection

Is there a way to make the following layout work without warning without warning:

new Expectations() {{
        UrlService.addUrls((List<String>)any); result = expectedCandidates; 
}};

Method Signature UrlService.addUrls():

static List<Candidate> addUrls(List<String> urls)
+4
source share
2 answers

A better alternative is to use an argument T witnAny(T arg):

new Expectations() {{
    UrlService.addUrls(withAny(new ArrayList<String>()));
    result = expectedCandidates;
}};

Or, to disable code verification locally if your IDE supports it. With IntelliJ I can write:

new Expectations() {{
    //noinspection unchecked
    UrlService.addUrls((List<String>) any);
    result = expectedCandidates;
}};

... this is really normal. Code checks are good and that’s all, but there are always exceptional situations when you can turn them off.

+3
source

Try the following:

new Expectations() {
        {
            UrlService.addUrls(withArgThat(new IsAnything<List<String>>())); result = expectedCandidates;
        }
    };
+1
source

All Articles