jeudi 18 août 2016

Mocking generic scala method in mockito

Im working on a scala project, using Mockito as a mocking framework. Where i wanted to mock the following generic scala method:

def parseXml[T: ClassTag](xmlUrl: URL, xsdUrl: Option[URL]): Option[T] 

So when mocking i assumed i could use on of Mockito's matchers like so:

when(xmlFileUnmarshallerMock.parseXml[org.mockito.Matchers.any[AddressBook]](org.mockito.Matchers.any[URL], org.mockito.Matchers.any[Option[URL]]))
    .thenReturn(Some(defaultAddressBook))

But that won't complile, then i tried both using [Any] and [AddressBook], but the both gives the following error:

org.mockito.exceptions.misusing.InvalidUseOfMatchersException:  Invalid use of argument matchers! 3 matchers expected, 2 recorded.

Aucun commentaire:

Enregistrer un commentaire