We recently changed the API on one of our services, it used to be:
def updateSubtitle(subtitleId: String...): Subtitle
Now it is:
def updateSubtitle(subtitleId: UUID, ...): Subtitle
And previously we wrote our expectations like so:
there was one(subtitleService).updateSubtitle(eq(subtitleId), ...)
This won't work anymore because subtitleId is now a UUID instead of a String. I've had to change eq(subtitleId) to any[UUID] however this is too generic as it doesn't actually test for the subtitleId value, it only cares that a value of type UUID was passed.
How can I get an eq matcher to work with UUID?
eq(subtitleId)does work withUUIDbecause theUUID.equalsmethod is correctly implemented (https://docs.oracle.com/javase/6/docs/api/java/util/UUID.html#equals(java.lang.Object).You may be having issues with the naming clash between
scala.AnyRef.eqandorg.mockito.Matchers.eq(see https://github.com/etorreborre/specs2/issues/361). This can be solved by either:Matchers.eq(i.e.one(subtitleService).updateSubtitle(org.mockito.Matchers.eq(subtitleId), ...)) orMatchers.eqname (i.e.import org.mockito.Matchers.{eq => meq, _}and changing your matcher use accordingly tomeq(subtitleId)