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

withCapture not working when captureing VariableArguments as Array #271

btfurukawatkr opened this issue Apr 6, 2016 · 2 comments


Copy link

@btfurukawatkr btfurukawatkr commented Apr 6, 2016

Please provide the following information:

  • Version of JMockit that was used:
  • Description of the problem or enhancement request:
    I tried to test a code like this and verify the values set to it
    public static void logInfoId(String msgId, String... any) {

with a test code like below

        new NonStrictExpectations(HogeUtils.class) {
                HogeUtils.logInfoId(anyString, (String[])any);

        HogeUtils.logInfoId(new String("testID"), new String[]{"hogehoge", "111", "222", "333"});

        new Verifications() {{
            List<String> idList = new ArrayList<>();
            List<String[]> messagesList = new ArrayList<>();

            HogeUtils.logInfoId(withCapture(idList), withCapture(messagesList));

            assertThat(idList.get(0), is("testID"));
            assertThat(messagesList.get(0), is(new String[]{"hogehoge", "111", "222", "333"}));

but the captured values in messagesList was just "hogehoge", and all the other arguments looks like it's lost.

I tried testing with

    public static void logInfoId(String msgId, String[] any) {

and successfully captured all the String Array values, so I am guessing that jmockit is not capable of captureing VariableArguments, or is there any way to capture VariableArguments ?

Copy link

@rliesenfeld rliesenfeld commented Apr 6, 2016

It seems to be a bug in the use of withCapture(List) for a varargs parameter.

If you only need to capture arguments for one call to logInfoId, though, it would be simpler (and it would work) to use withCapture() instead.

Copy link

@btfurukawatkr btfurukawatkr commented Apr 7, 2016

thanks for your comment.
actually, I need to capture arguments for multiple calls, so I was trying a testcode by using withCapture(List).
now I know that it's a bug, I'll consider another way of verifying my case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

No branches or pull requests

2 participants