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

Improve Varargs handling in AdditionalAnswers #2664

Merged
merged 3 commits into from Jun 11, 2022

Commits on Jun 6, 2022

  1. Improve Varargs handling in AdditionalAnswers

    Fixes: mockito#2644
    
    Fixes issues around vararg handling for the following methods in `AdditionalAnswers`:
     * `returnsFirstArg`
     * `returnsSecondArg`
     * `returnsLastArg`
     * `returnsArgAt`
     * `answer`
     * `answerVoid`
    
    These methods were not correctly handling varargs. For example,
    
    ```java
    doAnswer(answerVoid(
          (VoidAnswer2<String, Object[]>) logger::info
       )).when(mock)
          .info(any(), (Object[]) any());
    
    mock.info("Some message with {} {} {}", "three", "parameters", "");
    ```
    
    Would previously have resulted in a `ClassCastException` being thrown from the `mock.info` call.  This was because the `answerVoid` method was not taking into account that the second parameter was a varargs parameter and was attempting to pass the second actual argument `"three"`, rather than the second _raw_ argument `["three", "parameters", ""]`.
    big-andy-coates committed Jun 6, 2022
    Copy the full SHA
    459efad View commit details
    Browse the repository at this point in the history
  2. Move getRawArguments to InvocationOnMock

    avoiding having to cast to `Invocation`
    big-andy-coates committed Jun 6, 2022
    Copy the full SHA
    104b72d View commit details
    Browse the repository at this point in the history

Commits on Jun 11, 2022

  1. Copy the full SHA
    7ed9b26 View commit details
    Browse the repository at this point in the history