verifyInOrder top-level property

void Function<T>(List<T> recordedInvocations) verifyInOrder

Verify that a list of methods on a mock object have been called with the given arguments. For example:

verifyInOrder([cat.eatFood("Milk"), cat.sound(), cat.eatFood(any)]);

This verifies that eatFood was called with "Milk", soundwas called with no arguments, andeatFood` was then called with some argument.

Note: verifyInOrder only verifies that each call was made in the order given, but not that those were the only calls. In the example above, if other calls were made to eatFood or sound between the three given calls, or before or after them, the verification will still succeed.


_InOrderVerification get verifyInOrder {
  if (_verifyCalls.isNotEmpty) {
    throw StateError(_verifyCalls.join());
  _verificationInProgress = true;
  return <T>(List<T> _) {
    _verificationInProgress = false;
    DateTime dt = DateTime.fromMillisecondsSinceEpoch(0);
    var tmpVerifyCalls = List<_VerifyCall>.from(_verifyCalls);
    List<RealCall> matchedCalls = [];
    for (_VerifyCall verifyCall in tmpVerifyCalls) {
      RealCall matched = verifyCall._findAfter(dt);
      if (matched != null) {
        dt = matched.timeStamp;
      } else {
        Set<Mock> mocks =
   vc) => vc.mock).toSet();
        List<RealCall> allInvocations =
            mocks.expand((m) => m._realCalls).toList(growable: false);
            .sort((inv1, inv2) => inv1.timeStamp.compareTo(inv2.timeStamp));
        String otherCalls = "";
        if (allInvocations.isNotEmpty) {
          otherCalls = " All calls: ${allInvocations.join(", ")}";
        fail('Matching call #${tmpVerifyCalls.indexOf(verifyCall)} '
            'not found.$otherCalls');
    for (var call in matchedCalls) {
      call.verified = true;