google / gwtmockito

Better GWT unit testing
https://google.github.io/gwtmockito
Apache License 2.0
157 stars 50 forks source link

Try to use exact type provider first. #17

Closed reimai closed 10 years ago

reimai commented 10 years ago

Hello,

I've got an issue with the current provider resolving behavior:

I registered a provider for MyMessages.class which extends com.google.gwt.i18n.client.Messages.class, and now attempt to get MyMessages mock gives me MyMessages or Messages depending on luck and hashCodes, because there is already a default provider for Messages.

Using exact type provider if you've got one would be nice.

ekuefler commented 10 years ago

Thanks for pointing this out and sending a patch! I agree this is a problem. I think your fix helps but isn't quite general enough. I think we want to choose the most specific provider possible, even if it isn't an exact type. So if I have class A extend B extends C, and providers for B and C, I should always get the provider for B when I try to GWT.create A even though it isn't the exact type. I'll merge your change for now and see if I can find a good way to generalize it today.

ekuefler commented 10 years ago

Okay, I just pushed 9a4a4f1b1068b44f5cdae7fdcced0b5676f8caec to handle the general case. When looking for providers, it now takes the set of all legal providers and filters it down to only a type that isn't assignable from any other types, throwing an error if no such type exists. I think this should give you the behavior you want - let me know!

reimai commented 10 years ago

Yes, this is great and looks like the only way to get closest type without using reflection. And I've just noticed that my "solution" won't even compile 8]. Thank you! Would it also be updated in maven?

2013/10/14 Erik Kuefler notifications@github.com

Okay, I just pushed 9a4a4f1https://github.com/google/gwtmockito/commit/9a4a4f1b1068b44f5cdae7fdcced0b5676f8caecto handle the general case. When looking for providers, it now takes the set of all legal providers and filters it down to only a type that isn't assignable from any other types, throwing an error if no such type exists. I think this should give you the behavior you want - let me know!

— Reply to this email directly or view it on GitHubhttps://github.com/google/gwtmockito/pull/17#issuecomment-26229826 .

ekuefler commented 10 years ago

I've pushed a new version 1.1.2 to Maven including your change, it should be available in a few hours once the central repository syncs it. Thanks for contributing!

reimai commented 10 years ago

Got an update, thanks! Could you please fix a typo in readme.md: reimei should be reimai.

2013/10/16 Erik Kuefler notifications@github.com

I've pushed a new version 1.1.2 to Maven including your change, it should be available in a few hours once the central repository syncs it. Thanks for contributing!

— Reply to this email directly or view it on GitHubhttps://github.com/google/gwtmockito/pull/17#issuecomment-26400579 .

ekuefler commented 10 years ago

Sorry about that, fixed! On Oct 16, 2013 6:05 AM, "rei mai" notifications@github.com wrote:

Got an update, thanks! Could you please fix a typo in readme.md: reimei should be reimai.

2013/10/16 Erik Kuefler notifications@github.com

I've pushed a new version 1.1.2 to Maven including your change, it should be available in a few hours once the central repository syncs it. Thanks for contributing!

— Reply to this email directly or view it on GitHub< https://github.com/google/gwtmockito/pull/17#issuecomment-26400579> .

— Reply to this email directly or view it on GitHubhttps://github.com/google/gwtmockito/pull/17#issuecomment-26415637 .