TacapeForte / android-mock

Automatically exported from code.google.com/p/android-mock
0 stars 0 forks source link

Cannot use null parameters for constructor #1

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
Try to mock a class by passing null parameters for its constructor.

What is the expected output? What do you see instead?
Expected: would work
Actual: can't find constructor

Suggested solution:
Allow specifying the specific constructor or parameter types to use.

Ideal solution:
Not having to run any constructor (like Objenesis does).

Original issue reported on code.google.com by rdama...@google.com on 18 Aug 2010 at 6:15

GoogleCodeExporter commented 8 years ago
As you mentioned to me offline, the way to do serialization-reflection on 
Android is summed up here: 
http://stackoverflow.com/questions/3121515/is-it-possible-to-bypass-constructors
-when-instantiating-objects-in-android

I was already investigating this and had got as far as needing to ask precisely 
the question in the link above.  Using the desktop version of 
serialization-reflection, I already had a working prototype of Android Mock 
that bypassed constructors so it should be a pretty straightforward task now to 
sort it out permanently.

In the very short term, casting the null to an appropriate parameter will sort 
matters out, but it's an ugly hack.

Original comment by swoodw...@google.com on 2 Nov 2010 at 9:23

GoogleCodeExporter commented 8 years ago
Casting doesn't work - it works in setting generic parameters (meaning if you 
have a <T> in the method definition, it'll get set correctly, but you'll have 
no way of passing the correct parameter to getConstructor).

What you'd need is something like this:
http://easymock.org/api/easymockclassextension/2.5.2/org/easymock/classextension
/IMockBuilder.html

That was contributed by us to easymock, btw - if you search the internal google 
codebase you'll find the original MockBuilder too.

Original comment by rdama...@google.com on 4 Nov 2010 at 11:22