Delegate should throw a consistent and descriptive exception on any sort of method signature mismatch #473
Tested with version 1.36
I also believe that (3) does not provide a useful message in it. It seems to be a side-effect of jmockit trying to access the delegate's result while transferring to the caller. It does not point to the problem (as opposed to 1 and 2 which are quite descriptive). Here are the stack traces:
testNumArgs: java.lang.IllegalArgumentException: Failure to invoke method: public int DelegateProblemTest$3$1.delegate(byte)
testNumArgs: java.lang.IllegalArgumentException: Failure to invoke method: public int DelegateProblemTest$2$1.delegate(float,int)
testRetValType: java.lang.ClassCastException: java.lang.Byte cannot be cast to java.lang.Integer
I suggest that the return type is checked explicitly for the case of Void in (3) to produce something similar to (2) (java.lang.Void cannot be cast to java.lang.Integer). I also suggest that the ClassCastException be converted to an IllegalArgument exception as in (1), since from the perspective of JMockIt you are providing an incorrect argument (the delegate does not contain what it should) and is more appropriate.
Unit test which demonstrates the issue follows below: