1

I was trying to find out if I can use something like the any argument matcher for a method with type parameters:

when(store.getItems[Product](any[FilterParams]))
        .thenReturn(allProducts)

When running the code with the above snippet, I get this error:

Invalid use of argument matchers!
2 matchers expected, 1 recorded

I guessed this would be because I passed an exact type parameter Product to the getItems method.

This does work when I pass in an actual FilterParams object:

when(store.getItems[Product](FilterParams()))
        .thenReturn(allProducts)

Is there any argument matcher that I can use for the type parameter? Or is it counter-intuitive, because whenever we're calling a function with a type parameter, we have to pass the type parameter?

Edit:

Product here isn't Scala's built-in Product trait.

The function signature of the getItems method:

def getItems[T <: ItemType : universe.TypeTag](filterParams: FilterParams): List[T]
ssmallya
  • 133
  • 3
  • 11
  • Can you please add the definition of `store.getItems`? – Tomer Shetah Mar 11 '21 at 07:33
  • @TomerShetah I've added the signature of the function to the question. Function definition involves querying the database, so thought I'd just put the signature here. Thank you. – ssmallya Mar 11 '21 at 11:10

0 Answers0