OLD | NEW |
| (Empty) |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
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. | |
4 | |
5 library barback.test.cancelable_future_test; | |
6 | |
7 import 'dart:async'; | |
8 | |
9 import 'package:barback/src/utils.dart'; | |
10 import 'package:barback/src/utils/cancelable_future.dart'; | |
11 import 'package:unittest/unittest.dart'; | |
12 | |
13 import 'utils.dart'; | |
14 | |
15 main() { | |
16 initConfig(); | |
17 | |
18 var completer; | |
19 var future; | |
20 setUp(() { | |
21 completer = new Completer(); | |
22 future = new CancelableFuture(completer.future); | |
23 }); | |
24 | |
25 group("when not canceled", () { | |
26 test("correctly completes successfully", () { | |
27 expect(future, completion(equals("success"))); | |
28 completer.complete("success"); | |
29 }); | |
30 | |
31 test("correctly completes with an error", () { | |
32 expect(future, throwsA(equals("error"))); | |
33 completer.completeError("error"); | |
34 }); | |
35 }); | |
36 | |
37 group("when canceled", () { | |
38 test("never completes successfully", () { | |
39 var completed = false; | |
40 future.whenComplete(() { | |
41 completed = true; | |
42 }); | |
43 | |
44 future.cancel(); | |
45 completer.complete("success"); | |
46 | |
47 expect(pumpEventQueue().then((_) => completed), completion(isFalse)); | |
48 }); | |
49 | |
50 test("never completes with an error", () { | |
51 var completed = false; | |
52 future.catchError((_) {}).whenComplete(() { | |
53 completed = true; | |
54 }); | |
55 | |
56 future.cancel(); | |
57 completer.completeError("error"); | |
58 | |
59 expect(pumpEventQueue().then((_) => completed), completion(isFalse)); | |
60 }); | |
61 }); | |
62 } | |
OLD | NEW |