org.mockito.internal.util.collections.ArrayUtils Java Examples

The following examples show how to use org.mockito.internal.util.collections.ArrayUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ArgumentsProcessor.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public static Object[] expandVarArgs(final boolean isVarArgs, final Object[] args) {
    if (!isVarArgs || new ArrayUtils().isEmpty(args) || args[args.length - 1] != null && !args[args.length - 1].getClass().isArray()) {
        return args == null ? new Object[0] : args;
    }

    final int nonVarArgsCount = args.length - 1;
    Object[] varArgs;
    if (args[nonVarArgsCount] == null) {
        // in case someone deliberately passed null varArg array
        varArgs = new Object[] { null };
    } else {
        varArgs = ArrayEquals.createObjectArray(args[nonVarArgsCount]);
    }
    final int varArgsCount = varArgs.length;
    Object[] newArgs = new Object[nonVarArgsCount + varArgsCount];
    System.arraycopy(args, 0, newArgs, 0, nonVarArgsCount);
    System.arraycopy(varArgs, 0, newArgs, nonVarArgsCount, varArgsCount);
    return newArgs;
}