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:convert'; | |
9 import 'dart:io'; | 8 import 'dart:io'; |
10 | 9 |
11 /** | 10 /** |
12 * A mock [WebSocket] for testing. | 11 * A mock [WebSocket] for testing. |
13 */ | 12 */ |
14 class MockSocket<T> implements WebSocket { | 13 class MockSocket<T> implements WebSocket { |
15 | 14 |
16 final JsonEncoder jsonEncoder = const JsonEncoder(null); | |
17 | |
18 final JsonDecoder jsonDecoder = const JsonDecoder(null); | |
19 | |
20 StreamController controller = new StreamController(); | 15 StreamController controller = new StreamController(); |
21 MockSocket twin; | 16 MockSocket twin; |
22 Stream stream; | 17 Stream stream; |
23 | 18 |
24 factory MockSocket.pair() { | 19 factory MockSocket.pair() { |
25 MockSocket socket1 = new MockSocket(); | 20 MockSocket socket1 = new MockSocket(); |
26 MockSocket socket2 = new MockSocket(); | 21 MockSocket socket2 = new MockSocket(); |
27 socket1.twin = socket2; | 22 socket1.twin = socket2; |
28 socket2.twin = socket1; | 23 socket2.twin = socket1; |
29 socket1.stream = socket2.controller.stream; | 24 socket1.stream = socket2.controller.stream; |
(...skipping 13 matching lines...) Expand all Loading... |
43 .then((_) => twin.controller.close()); | 38 .then((_) => twin.controller.close()); |
44 | 39 |
45 StreamSubscription<T> listen(void onData(T event), | 40 StreamSubscription<T> listen(void onData(T event), |
46 { Function onError, void onDone(), bool cancelOnError}) => | 41 { Function onError, void onDone(), bool cancelOnError}) => |
47 stream.listen(onData, onError: onError, onDone: onDone, | 42 stream.listen(onData, onError: onError, onDone: onDone, |
48 cancelOnError: cancelOnError); | 43 cancelOnError: cancelOnError); |
49 | 44 |
50 Stream<T> where(bool test(T)) => stream.where(test); | 45 Stream<T> where(bool test(T)) => stream.where(test); |
51 | 46 |
52 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 47 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
53 } | 48 } |
OLD | NEW |