I am trying to understand why this junit statement gives me a compile-time error:
Map<String, Set<String>> actual = methodToTest();
assertThat(result, hasEntry("foo", new HashSet<String>(Arrays.asList("bar"))));
If I write it like this, it works fine:
Map<String, Set<String>> actual = methodToTest();
Set<String> expected = new HashSet<String>(Arrays.asList("bar"));
assertThat(result, hasEntry("foo", expected));
The compiler error from the first example:
The method assertThat(T, Matcher<? super T>) in the type Assert is not
applicable for the arguments (Map<String,Set<String>>, Matcher<Map<?
extends String,? extends HashSet<String>>>)
HashSet<String>is a subtype Set<String>, so why doesn't it work?
acvcu source
share