tw_wasInvoked method

bool tw_wasInvoked({
  1. String? key,
  2. int? atLeastNumTimes,
  3. int? atMostNumItems,
  4. int? exactlyNumTimes,
})

Check whether a method was invoked at least, at most, or exactly a given number of times.

Implementation

bool tw_wasInvoked({ String? key, int? atLeastNumTimes, int? atMostNumItems, int? exactlyNumTimes }) {
	assert(exactlyNumTimes == null || (atLeastNumTimes == null && atMostNumItems == null));

	List<_InvocationData> arrToCheck = [ ];
	if (key == null) {
		for (List<_InvocationData> arr in this._mapInvocations.values) {
			arrToCheck.addAll(arr);
		}
	}
	else if (this._mapInvocations.containsKey(key)) {
		arrToCheck = this._mapInvocations[key]!;
	}
	else {
		if (exactlyNumTimes != null && exactlyNumTimes == 0) {
			return true;
		}
		return false;
	}

	//int numTimes = this._mapInvocations[key]!.length;
	int numTimes = arrToCheck.length;
	if (atLeastNumTimes != null && numTimes < atLeastNumTimes) {
		return false;
	}
	if (atMostNumItems != null && numTimes > atMostNumItems) {
		return false;
	}
	if (exactlyNumTimes != null && numTimes != exactlyNumTimes) {
		return false;
	}

	if ((atLeastNumTimes ?? atMostNumItems ?? exactlyNumTimes) == null) {
		return (numTimes > 0);
	}

	return true;
}