| 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 import 'package:analysis_server/plugin/protocol/protocol.dart' | 10 import 'package:analysis_server/plugin/protocol/protocol.dart' |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 responsesReceived.add(response); | 245 responsesReceived.add(response); |
| 246 // Wrap send response in future to simulate WebSocket. | 246 // Wrap send response in future to simulate WebSocket. |
| 247 new Future(() => responseController.add(response)); | 247 new Future(() => responseController.add(response)); |
| 248 } | 248 } |
| 249 | 249 |
| 250 Future<Response> waitForResponse(Request request) { | 250 Future<Response> waitForResponse(Request request) { |
| 251 String id = request.id; | 251 String id = request.id; |
| 252 pumpEventQueue().then((_) { | 252 pumpEventQueue().then((_) { |
| 253 responseController.addError(new NoResponseException(request)); | 253 responseController.addError(new NoResponseException(request)); |
| 254 }); | 254 }); |
| 255 return responseController.stream.firstWhere((response) { | 255 return new Future<Response>(() => |
| 256 return response.id == id; | 256 responseController.stream.firstWhere((response) => response.id == id)); |
| 257 }); | |
| 258 } | 257 } |
| 259 } | 258 } |
| 260 | 259 |
| 261 /** | 260 /** |
| 262 * A mock [ServerOperation] for testing [AnalysisServer]. | 261 * A mock [ServerOperation] for testing [AnalysisServer]. |
| 263 */ | 262 */ |
| 264 class MockServerOperation implements PerformAnalysisOperation { | 263 class MockServerOperation implements PerformAnalysisOperation { |
| 265 final ServerOperationPriority priority; | 264 final ServerOperationPriority priority; |
| 266 final MockServerOperationPerformFunction _perform; | 265 final MockServerOperationPerformFunction _perform; |
| 267 | 266 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 290 factory MockSocket.pair() { | 289 factory MockSocket.pair() { |
| 291 MockSocket<T> socket1 = new MockSocket<T>(); | 290 MockSocket<T> socket1 = new MockSocket<T>(); |
| 292 MockSocket<T> socket2 = new MockSocket<T>(); | 291 MockSocket<T> socket2 = new MockSocket<T>(); |
| 293 socket1.twin = socket2; | 292 socket1.twin = socket2; |
| 294 socket2.twin = socket1; | 293 socket2.twin = socket1; |
| 295 socket1.stream = socket2.controller.stream; | 294 socket1.stream = socket2.controller.stream; |
| 296 socket2.stream = socket1.controller.stream; | 295 socket2.stream = socket1.controller.stream; |
| 297 return socket1; | 296 return socket1; |
| 298 } | 297 } |
| 299 | 298 |
| 300 void add(T text) => controller.add(text); | 299 void add(dynamic text) => controller.add(text as T); |
| 301 | 300 |
| 302 void allowMultipleListeners() { | 301 void allowMultipleListeners() { |
| 303 stream = stream.asBroadcastStream(); | 302 stream = stream.asBroadcastStream(); |
| 304 } | 303 } |
| 305 | 304 |
| 306 Future close([int code, String reason]) => | 305 Future close([int code, String reason]) => |
| 307 controller.close().then((_) => twin.controller.close()); | 306 controller.close().then((_) => twin.controller.close()); |
| 308 | 307 |
| 309 StreamSubscription<T> listen(void onData(T event), | 308 StreamSubscription<T> listen(void onData(dynamic event), |
| 310 {Function onError, void onDone(), bool cancelOnError}) => | 309 {Function onError, void onDone(), bool cancelOnError}) => |
| 311 stream.listen(onData, | 310 stream.listen((T data) => onData(data), |
| 312 onError: onError, onDone: onDone, cancelOnError: cancelOnError); | 311 onError: onError, onDone: onDone, cancelOnError: cancelOnError); |
| 313 | 312 |
| 314 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 313 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 315 | 314 |
| 316 Stream<T> where(bool test(T t)) => stream.where(test); | 315 Stream<T> where(bool test(dynamic t)) => stream.where((T data) => test(data)); |
| 317 } | 316 } |
| 318 | 317 |
| 319 class MockSource extends StringTypedMock implements Source { | 318 class MockSource extends StringTypedMock implements Source { |
| 320 MockSource([String name = 'mocked.dart']) : super(name); | 319 MockSource([String name = 'mocked.dart']) : super(name); |
| 321 } | 320 } |
| 322 | 321 |
| 323 class MockTopLevelVariableElement extends TypedMock | 322 class MockTopLevelVariableElement extends TypedMock |
| 324 implements TopLevelVariableElement { | 323 implements TopLevelVariableElement { |
| 325 final ElementKind kind = ElementKind.TOP_LEVEL_VARIABLE; | 324 final ElementKind kind = ElementKind.TOP_LEVEL_VARIABLE; |
| 326 } | 325 } |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 } | 434 } |
| 436 return mismatchDescription; | 435 return mismatchDescription; |
| 437 } | 436 } |
| 438 | 437 |
| 439 @override | 438 @override |
| 440 bool matches(item, Map matchState) { | 439 bool matches(item, Map matchState) { |
| 441 Response response = item; | 440 Response response = item; |
| 442 return response != null && response.id == _id && response.error == null; | 441 return response != null && response.id == _id && response.error == null; |
| 443 } | 442 } |
| 444 } | 443 } |
| OLD | NEW |