lundi 2 septembre 2019

Hamcrest matchers: argument mismatch; no instance(s) of type variable

I have this verify of mock in test:

View selectedAccountView =  ...

....
    verify(myClickListener, times(1)).onClick(equalTo(selectedAccountView), any(FakeAccount.class));

and prod code:

public interface MyClickListener<T> {
  void onClick(@NonNull View clickTarget, @Nullable T selectedAccount);
}

equal signature is:

  public static <T> org.hamcrest.Matcher<T> equalTo(T operand) {     return org.hamcrest.core.IsEqual.<T>equalTo(operand);   }

but when i run the test I get a runtime error:

    verify(myClickListener, times(0)).onClick(equalTo(selectedAccountView), any(FakeAccount.class));                                                         ^   required: View,FakeAccount   found:    Matcher<View>,FakeAccount   reason: argument mismatch; no instance(s) of type variable(s) T#2 exist so that Matcher<T#2> conforms to View   where T#1,T#2 are type-variables:     T#1 extends Object declared in interface MyClickListener     T#2 extends Object declared in method <T#2>equalTo(T#2)

What am i missing? The first type is View as expected.

Aucun commentaire:

Enregistrer un commentaire