expectProblem function

void expectProblem(
  1. Object? actual, {
  2. String? type,
  3. String? title,
  4. int? status,
  5. bool? recoverable,
  6. String? detail,
  7. String? instance,
  8. Map<String, Object?>? data,
})

Asserts the actual envelope matches the expected fields.

Every argument is optional; only the fields passed are checked. A null actual always fails. The matcher deliberately validates each field independently so the failure message names the first mismatched field.

Implementation

void expectProblem(
  Object? actual, {
  String? type,
  String? title,
  int? status,
  bool? recoverable,
  String? detail,
  String? instance,
  Map<String, Object?>? data,
}) {
  if (actual is! Problem) {
    _fail('expected a Problem but got ${actual.runtimeType}');
  }
  final Problem problem = actual;
  if (type != null) {
    _check(
      problem.type == type,
      'Problem.type mismatch: expected <$type> got <${problem.type}>',
    );
  }
  if (title != null) {
    _check(
      problem.title == title,
      'Problem.title mismatch: expected <$title> got <${problem.title}>',
    );
  }
  if (status != null) {
    _check(
      problem.status == status,
      'Problem.status mismatch: expected <$status> got <${problem.status}>',
    );
  }
  if (recoverable != null) {
    _check(
      problem.recoverable == recoverable,
      'Problem.recoverable mismatch: expected <$recoverable> got <${problem.recoverable}>',
    );
  }
  if (detail != null) {
    _check(
      problem.detail == detail,
      'Problem.detail mismatch: expected <$detail> got <${problem.detail}>',
    );
  }
  if (instance != null) {
    _check(
      problem.instance == instance,
      'Problem.instance mismatch: expected <$instance> got <${problem.instance}>',
    );
  }
  if (data != null) {
    _check(
      _mapsEqual(problem.data, data),
      'Problem.data mismatch: expected <$data> got <${problem.data}>',
    );
  }
}