noushadali / powermock

Automatically exported from code.google.com/p/powermock
Apache License 2.0
0 stars 0 forks source link

Issue #465

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Run the test class attached. Error will be thrown.

What is the expected output? What do you see instead?
String "mocked" in the console but I got an error.

What version of the product are you using? On what operating system?
R: powermock-mockito-1.5.1-full.jar, jdk7.

Please provide any additional information below.

The problem is on line 37 of the class DefaultPrivatelyExpectedArguments.

Note the declaration of the following methods:

DefaultPrivatelyExpectedArguments#withArguments(Object firstArgument, Object... 
additionalArguments)
Method#invoke(Object obj, Object... args)

And the method call:
 method.invoke(mock, firstArgument, additionalArguments);

If I call the method withArguments with more than two arguments, held that: the 
call to the invoke method will always be considered to have only two 
parameters. One being the first argument and the other an array with the other 
arguments.

Solution: change the method signature to 
DefaultPrivatelyExpectedArguments#withArguments(Object... arguments) or create 
a temporary array for the arguments,

Object[] array = new Object[additionalArguments.length + 1];
array[0] = firstArgument;
System.arraycopy(additionalArguments, 0, array, 1, additionalArguments.length);
method.invoke(mock, array);

Original issue reported on code.google.com by ande.brb on 10 Oct 2013 at 1:20

Attachments:

GoogleCodeExporter commented 9 years ago
This has been fixed in trunk.

Original comment by johan.ha...@gmail.com on 21 Jan 2014 at 1:04