Here's one possibility based on this list of possible apex mocks issues
You are using Apex types as arguments to stubbed methods without a way to test equality
mocks.when(appointmentServiceMock.isSuitableForAppointment(requestDTO))
.thenReturn(true);
Since requestDTO
is an object of type AppointmentDTO
, the default equals matcher being used in appointmentServiceMock.isSuitableForAppointment(requestDTO)
will not find a match against the actual arg passed at runtime unless you have implemented an equals(Object compareTo)
and hashcode()hashcode()
public method for type AppointmentDTO
. That is, custom apextypes can't be compared for equality unless you add these two methods to the class
You can work around this at some cost in unit test completeness by using the anyObject
matcher
mocks.when(appointmentServiceMock.isSuitableForAppointment((fflib_Match.anyObject)requestDTO))
which won't care what actual requestDTO is passed to the underlying isSuitableForAppointment
method to mock the return value
Notes:
1 - Be aware when implementing equals(Object compareTo)
that JSON.serialize
is non-deterministic in how it renders its results so comparing two serialized JSONs to each other might not always work, even if the component elements are identical