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

Closed
btfurukawatkr opened this Issue Apr 6, 2016 · 2 comments

Comments

2 participants
@btfurukawatkr

btfurukawatkr commented Apr 6, 2016

Please provide the following information:

  • Version of JMockit that was used:
    1.20
  • 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 ?

@rliesenfeld

This comment has been minimized.

Show comment
Hide comment
@rliesenfeld

rliesenfeld Apr 6, 2016

Member

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.

Member

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.

@btfurukawatkr

This comment has been minimized.

Show comment
Hide comment
@btfurukawatkr

btfurukawatkr Apr 7, 2016

@rliesenfeld
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.

btfurukawatkr commented Apr 7, 2016

@rliesenfeld
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.

@rliesenfeld rliesenfeld added the bug label Apr 8, 2016

@rliesenfeld rliesenfeld self-assigned this Apr 8, 2016

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