| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library mocks; | 5 library mocks; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 | 9 |
| 10 @MirrorsUsed(targets: 'mocks', override: '*') | 10 @MirrorsUsed(targets: 'mocks', override: '*') |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 mismatchDescription.add(' and has error $error'); | 275 mismatchDescription.add(' and has error $error'); |
| 276 } | 276 } |
| 277 } | 277 } |
| 278 return mismatchDescription; | 278 return mismatchDescription; |
| 279 } | 279 } |
| 280 } | 280 } |
| 281 | 281 |
| 282 | 282 |
| 283 /** | 283 /** |
| 284 * A [Matcher] that check that the given [Response] has an expected identifier | 284 * A [Matcher] that check that the given [Response] has an expected identifier |
| 285 * and has an error. | 285 * and has an error. The error code may optionally be checked. |
| 286 */ | 286 */ |
| 287 Matcher isResponseFailure(String id) => new _IsResponseFailure(id); | 287 Matcher isResponseFailure(String id, [RequestErrorCode code]) => |
| 288 new _IsResponseFailure(id, code); |
| 288 | 289 |
| 289 /** | 290 /** |
| 290 * A [Matcher] that check that there are no `error` in a given [Response]. | 291 * A [Matcher] that check that there are no `error` in a given [Response]. |
| 291 */ | 292 */ |
| 292 class _IsResponseFailure extends Matcher { | 293 class _IsResponseFailure extends Matcher { |
| 293 final String _id; | 294 final String _id; |
| 295 final RequestErrorCode _code; |
| 294 | 296 |
| 295 _IsResponseFailure(this._id); | 297 _IsResponseFailure(this._id, this._code); |
| 296 | 298 |
| 297 @override | 299 @override |
| 298 Description describe(Description description) { | 300 Description describe(Description description) { |
| 299 return description.addDescriptionOf( | 301 description = description.add( |
| 300 'response with identifier "$_id" and an error'); | 302 'response with identifier "$_id" and an error'); |
| 303 if (_code != null) { |
| 304 description = description.add(' with code ${this._code.name}'); |
| 305 } |
| 306 return description; |
| 301 } | 307 } |
| 302 | 308 |
| 303 @override | 309 @override |
| 304 bool matches(item, Map matchState) { | 310 bool matches(item, Map matchState) { |
| 305 Response response = item; | 311 Response response = item; |
| 306 return response.id == _id && response.error != null; | 312 if (response.id != _id || response.error == null) { |
| 313 return false; |
| 314 } |
| 315 if (_code != null && response.error.code != _code) { |
| 316 return false; |
| 317 } |
| 318 return true; |
| 307 } | 319 } |
| 308 | 320 |
| 309 @override | 321 @override |
| 310 Description describeMismatch(item, Description mismatchDescription, | 322 Description describeMismatch(item, Description mismatchDescription, |
| 311 Map matchState, bool verbose) { | 323 Map matchState, bool verbose) { |
| 312 Response response = item; | 324 Response response = item; |
| 313 var id = response.id; | 325 var id = response.id; |
| 314 RequestError error = response.error; | 326 RequestError error = response.error; |
| 315 mismatchDescription.add('has identifier "$id"'); | 327 mismatchDescription.add('has identifier "$id"'); |
| 316 if (error == null) { | 328 if (error == null) { |
| 317 mismatchDescription.add(' and has no error'); | 329 mismatchDescription.add(' and has no error'); |
| 330 } else { |
| 331 mismatchDescription.add(' and has error code ${response.error.code.name}')
; |
| 318 } | 332 } |
| 319 return mismatchDescription; | 333 return mismatchDescription; |
| 320 } | 334 } |
| 321 } | 335 } |
| 322 | 336 |
| 323 | 337 |
| 324 /** | 338 /** |
| 325 * A mock [PackageMapProvider]. | 339 * A mock [PackageMapProvider]. |
| 326 */ | 340 */ |
| 327 class MockPackageMapProvider implements PackageMapProvider { | 341 class MockPackageMapProvider implements PackageMapProvider { |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 StringTypedMock(this._toString); | 498 StringTypedMock(this._toString); |
| 485 | 499 |
| 486 @override | 500 @override |
| 487 String toString() { | 501 String toString() { |
| 488 if (_toString != null) { | 502 if (_toString != null) { |
| 489 return _toString; | 503 return _toString; |
| 490 } | 504 } |
| 491 return super.toString(); | 505 return super.toString(); |
| 492 } | 506 } |
| 493 } | 507 } |
| OLD | NEW |