initially, I had this piece of production code:
interface ActionSequence {
public List<Actions> getActions();
I tested classes implementing that interface with something like this:
assertThat(sequenceUnderTest.getActions(), is(Arrays.asList(action1, action2));
Then I figured that it might be beneficial to change the production interface to:
public List<? extends Action> getActions() {
(to allow me to return lists of subclasses of Action).
But now eclipse tells me:
The method assertThat(T, Matcher<? super T>) in the type Assert is not applicable for the arguments (List<capture#1-of ? extends Action>, Matcher<List<Action>>)
I figured: when I change the class that implements ActionInterface to do
@Override
public List<SomeSubClassOfAction> getActions()
(instead of keeping the wildcard) ... then everything works. But why?
>. In this case, your code will compile, so I suppose you used some version before JUnit 4.11. See http://stackoverflow.com/questions/27256429/is-org-junit-assert-assertthat-better-than-org-hamcrest-matcherassert-assertthat for details on this JUnit change
– stefan.m Jan 15 '16 at 13:47