Custom matching functions

When built-in argument matchers aren’t sufficient, custom matchers can be written. A custom argument matcher simply needs to take in the argument as a parameter and return true if it matches, and false if it does not. This custom boolean function can then be passed to the special match function.

  1. every {
  2. mockedCar.drive(match { engine ->
  3. engine.type === "Diesel"
  4. })
  5. } returns true

If the argument is nullable, a variant called matchNullable can be used instead.

  1. every {
  2. mockedCar.drive(matchNullable { engine ->
  3. engine != null && engine.type === "Diesel"
  4. })
  5. } returns true

Matcher subclass

TODO extend Matcher<T>

Inline extension function helper

TODO MockKMatcherScope extension function