alexruiz / fest-assert-2.x

FEST Fluent Assertions 2.x
http://fest.easytesting.org
Apache License 2.0
401 stars 69 forks source link

MapEntry should use generics for key and value #81

Open Crazyjavahacking opened 12 years ago

Crazyjavahacking commented 12 years ago

MapEntry should use generics for key and value: MapEntry<K, V>.

Then it makes sense to change the MapAssert<K,V>.contains(MapEntry) to MapAssert<K,V>.contains(MapEntry<K,V>). Maybe even MapEntry<? extends K, ? extends V>.

I will be willing to provide a patch for it.

joel-costigliola commented 12 years ago

Good idea ! Using MapEntry<? extends K, ? extends V> seems more flexible but I'm not sure it will be consistent with MapAssert actual generic parameters. Unless you are very comfortable with generics or see some use case needing it, we may start with MapEntry<K,V>.

Thanks for proposing to provide a patch, please have a look at our updated contributor guide : https://github.com/alexruiz/fest-assert-2.x/wiki/Contributor-guidelines

ash2k commented 12 years ago

I tried to do that some time ago and thought this causes too many varargs warnings. But they are not "bad" warnings, we just can't mark them as safe with @safevarargs (because we target Java 5+ not 7+). Anyway there is no need for public MapEntry class - use Map.Entry interface instead. It'll make API more compatible.

Crazyjavahacking commented 12 years ago

You can use @SuppressWarnings("unchecked") or @SuppressWarnings("rawtypes") depending of what is wrong with generics.

joel-costigliola commented 12 years ago

I think Alex (Ruiz) tried to use Map.Entry without success, unfortunately I can't remember why. @Crazyjavahacking if you want to give a shot why not, but I do trust Mikhail (ash2k) opinion on generics. Choice is yours !

ash2k commented 12 years ago

The refactoring i tried to do is on a computer i have no access to right now but i'll be able to push the code to my clone of this repo in a few days. So we will be able to review it and make our minds if it's a good thing to do.

ash2k commented 12 years ago

So here it is ash2k/fest-assert-2.x@1e6c79f0aeec9ad0fab1aeca06f39b85d3466321

ash2k commented 12 years ago

I just added one more commit to the branch so here you can see branch to master comparison https://github.com/ash2k/fest-assert-2.x/compare/type-safe-map