call method

T call(
  1. List arguments
)

Call the instance with arguments, which will try to match them with the existing mocks.

Returns the previously provided return value of type T if a matching mock exists.

Throws a InvalidNanoMockCallException if no mock exists.

Implementation

T call(List<dynamic> arguments) {
  // Process each mock.
  for (_Mock<T> mock in _mocks) {
    // Check if the arguments of the current mock matches the given arguments.
    if (listsEqual(arguments, mock.arguments)) {
      // A match has been found.

      // Increment the number of calls to the mock.
      mock.calls++;

      // Return the mock's result.
      return mock.result;
    }
  }

  // Throw an InvalidNanoMockCallException since no matching mock exists.
  throw InvalidNanoMockCallException(arguments);
}