blob: de744b64cb8487ed7dc87050219a2b69fbf5c1b6 [file] [log] [blame]
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer_plugin/protocol/protocol.dart';
import 'package:test/test.dart';
/// A [Matcher] that check that the given [Response] has an expected identifier
/// and no error.
Matcher isResponseSuccess(String id) => _IsResponseSuccess(id);
/// A [Matcher] that check that there are no `error` in a given [Response].
class _IsResponseSuccess extends Matcher {
final String _id;
Description describe(Description description) {
return description
.addDescriptionOf('response with identifier "$_id" and without error');
Description describeMismatch(
item, Description mismatchDescription, Map matchState, bool verbose) {
Response response = item as Response;
if (response == null) {
mismatchDescription.add('is null response');
} else {
var id =;
var error = response.error;
mismatchDescription.add('has identifier "$id"');
if (error != null) {
mismatchDescription.add(' and has error $error');
return mismatchDescription;
bool matches(item, Map matchState) {
Response response = item as Response;
return response != null && == _id && response.error == null;