uhm not sure i understand what you’re trying to ac...
# mockk
m
uhm not sure i understand what you’re trying to achieve do you want to return a different employeeAttribute depending on the value of the parameter being passed to getEmployee?
i
and I need for every getEmployee(“1”) return a specific object, a data class, and for getEmployee(“3") i need to return a data class with different values
yes I want on the base of the id parameter getting passed to return a different
EmployeeAttribute
is working
I have to pass a different every{} returns for each id
sorry for the silly question
m
yep you can use two different
every
blocks
or use
answers
rather than
returns
answers
takes a lambda where you can put some logic to determine the value you want to be returned according to different conditions
and it also has some useful convenience methods like
firstArg()
to capture the arguments that were passed to the function being stubbed
i
Thanks
m
If I may add a thought, this case hints that you don’t need a mock here, but just a stub or a “fake object” to be precise. You can either do as Mattia suggested, or you could write a fake implementation of
EmployeesRepositoryInterface
that applies your stub logic:
Copy code
class FakeEmployeesRepository : EmployeesRepositoryInterface {
  override fun getEmployee(id: String) {
    // calculate an employee by id...
  }
}
i
thanks Matteo. well the old stub vs mock schools. Like it.
m
hehe yes, just pointing out that maybe in this case the use of mockk seems overkill to my eyes… just a personal taste. For the rest, go with mocks full steam ahead! (actually no, don’t go mock everything 😆 )
i
and never becoming too much “relaxed” about mockks 😂
fantastic tool anyway, with superb synthax
🏆 1
❤️ 1