withCapture not working when captureing VariableArguments as Array #271

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

Projects

None yet

2 participants

@btfurukawatkr

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

@btfurukawatkr

@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