2

I usually use Hamcrest like this:

doNothing().when(entityManagerMock).persist(any(Point.class));

then I have tried to write the same syntax on this:

doNothing().when(locationTagsMock).persistLocationTag(any(LocationTag.class));

But I got compilation error which forced me to re-factor my code to this:

doNothing().when(locationTagsMock).persistLocationTag((LocationTag) any(LocationTag.class));

Why is the casting needed all the sudden?

How can I avoid it, if at all?

Maciej Kowalski
  • 25,605
  • 12
  • 54
  • 63
Elad Benda
  • 35,076
  • 87
  • 265
  • 471

1 Answers1

1

According to Doppelganger's comment on the answer to Using Mockito's generic "any()" method, you've got a conflict between hamcrest's any() and mockito's any().

Community
  • 1
  • 1
schnitz
  • 190
  • 2
  • 9
  • 1
    Either static import just the one intended (which I think is actually the mockito one), or import that class non-statically, or fully qualify the reference. – schnitz Nov 01 '14 at 15:03