thenReturnInOrder method

void thenReturnInOrder(
  1. List<T> expects
)

Store a sequence of canned responses for this method stub.

Note: expects cannot contain a Future or Stream, due to Zone considerations. To return a Future or Stream from a method stub, use thenAnswer.

Note: when the method stub is called more times than there are responses in expects, it will throw an StateError in the missing case.

Implementation

void thenReturnInOrder(List<T> expects) {
  if (expects.isEmpty) {
    throw ArgumentError('thenReturnInOrder expects should not be empty');
  }

  expects.forEach(_throwIfInvalid);

  final answers = Queue.of(expects);

  thenAnswer((_) {
    if (answers.isEmpty) {
      throw StateError('thenReturnInOrder does not have enough answers');
    }

    return answers.removeFirst();
  });
}