I'm unhappily dealing with an interface someone defined with the following
public Map<?, ?> getMap(String key);
I'm trying to write unit tests that consume this interface.
Map<String,String> pageMaps = new HashMap<String,String();
pageMaps.put(EmptyResultsHandler.PAGEIDENT,"boogie");
pageMaps.put(EmptyResultsHandler.BROWSEPARENTNODEID, "Chompie");
Map<?,?> stupid = (Map<?, ?>)pageMaps;
EasyMock.expect(config.getMap("sillyMap")).andReturn(stupid);
and the compiler is borking.
The method andReturn(Map<capture#5-of ?,capture#6-of ?>) in the type IExpectationSetters<Map<capture#5-of ?,capture#6-of ?>> is not applicable for the arguments (Map<capture#7-of ?,capture#8-of ?>)
If I try to use pageMaps directly, it tells me:
The method andReturn(Map<capture#5-of ?,capture#6-of ?>) in the type IExpectationSetters<Map<capture#5-of ?,capture#6-of ?>> is not applicable for the arguments (Map<String,String>)
If I make pageMaps a Map<?,?>, I can't put Strings inside of it.
The method put(capture#3-of ?, capture#4-of ?) in the type Map<capture#3-of ?,capture#4-of ?> is not applicable for the arguments (String, String)
I've seen some client code that does ugly unchecked conversions, like
@SuppressWarnings("unchecked")
final Map<String, String> emptySearchResultsPageMaps = (Map<String, String>) conf.getMap("emptySearchResultsPage");
How do I get data into a Map<?,?>, or convert my Map<String,String> to Map<?,?> ?
pageMaps?EasyMock.expect(config.getMap("sillyMap")).andReturn(pageMaps);