| 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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 196 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 197 } | 197 } |
| 198 | 198 |
| 199 /** | 199 /** |
| 200 * A mock [Source]. Particularly useful when all that is needed is the | 200 * A mock [Source]. Particularly useful when all that is needed is the |
| 201 * encoding. | 201 * encoding. |
| 202 */ | 202 */ |
| 203 class MockSource extends Mock implements Source { | 203 class MockSource extends Mock implements Source { |
| 204 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 204 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 205 } | 205 } |
| 206 |
| 207 |
| 208 /** |
| 209 * A [Matcher] that check that the given [Response] has an expected identifier |
| 210 * and no error. |
| 211 */ |
| 212 Matcher isResponseSuccess(String id) => new _IsResponseSuccess(id); |
| 213 |
| 214 /** |
| 215 * A [Matcher] that check that there are no `error` in a given [Response]. |
| 216 */ |
| 217 class _IsResponseSuccess extends Matcher { |
| 218 final String _id; |
| 219 |
| 220 _IsResponseSuccess(this._id); |
| 221 |
| 222 @override |
| 223 Description describe(Description description) { |
| 224 return description.addDescriptionOf( |
| 225 'response with identifier "$_id" and without error'); |
| 226 } |
| 227 |
| 228 @override |
| 229 bool matches(item, Map matchState) { |
| 230 Response response = item; |
| 231 return response.id == _id && response.error == null; |
| 232 } |
| 233 |
| 234 @override |
| 235 Description describeMismatch(item, Description mismatchDescription, |
| 236 Map matchState, bool verbose) { |
| 237 Response response = item; |
| 238 var id = response.id; |
| 239 RequestError error = response.error; |
| 240 mismatchDescription.add('has identifier "$id"'); |
| 241 if (error != null) { |
| 242 mismatchDescription.add(' and has error $error'); |
| 243 } |
| 244 return mismatchDescription; |
| 245 } |
| 246 } |
| 247 |
| 248 |
| 249 /** |
| 250 * A [Matcher] that check that the given [Response] has an expected identifier |
| 251 * and has an error. |
| 252 */ |
| 253 Matcher isResponseFailure(String id) => new _IsResponseFailure(id); |
| 254 |
| 255 /** |
| 256 * A [Matcher] that check that there are no `error` in a given [Response]. |
| 257 */ |
| 258 class _IsResponseFailure extends Matcher { |
| 259 final String _id; |
| 260 |
| 261 _IsResponseFailure(this._id); |
| 262 |
| 263 @override |
| 264 Description describe(Description description) { |
| 265 return description.addDescriptionOf( |
| 266 'response with identifier "$_id" and an error'); |
| 267 } |
| 268 |
| 269 @override |
| 270 bool matches(item, Map matchState) { |
| 271 Response response = item; |
| 272 return response.id == _id && response.error != null; |
| 273 } |
| 274 |
| 275 @override |
| 276 Description describeMismatch(item, Description mismatchDescription, |
| 277 Map matchState, bool verbose) { |
| 278 Response response = item; |
| 279 var id = response.id; |
| 280 RequestError error = response.error; |
| 281 mismatchDescription.add('has identifier "$id"'); |
| 282 if (error == null) { |
| 283 mismatchDescription.add(' and has no error'); |
| 284 } |
| 285 return mismatchDescription; |
| 286 } |
| 287 } |
| OLD | NEW |