Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Unified Diff: pkg/analysis_server/test/mocks.dart

Issue 196993003: add sdkPath and enable tests (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analysis_server/test/domain_server_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/test/mocks.dart
diff --git a/pkg/analysis_server/test/mocks.dart b/pkg/analysis_server/test/mocks.dart
index 88a6744c908c20e1ab6b1d67540ac375126fee66..82b15fa88d5b7db145336f54fdc30106719ea831 100644
--- a/pkg/analysis_server/test/mocks.dart
+++ b/pkg/analysis_server/test/mocks.dart
@@ -7,14 +7,29 @@ library mocks;
import 'dart:async';
import 'dart:io';
+import 'package:analysis_server/src/analysis_server.dart';
import 'package:analysis_server/src/channel.dart';
import 'package:analysis_server/src/protocol.dart';
+import 'package:unittest/matcher.dart';
+
+/**
+ * Answer the path the the SDK relative to the currently running script
+ * or throw an exception if it cannot be found.
+ */
+String get sdkPath {
+ Uri sdkUri = Uri.base.resolveUri(Platform.script).resolve('../../../sdk/');
+ // Verify that the internal library file exists
+ Uri libFileUri = sdkUri.resolve('lib/_internal/libraries.dart');
+ if (!new File.fromUri(libFileUri).existsSync()) {
+ throw 'Expected Dart SDK at ${sdkUri.path}';
+ }
+ return sdkUri.path;
+}
/**
* A mock [WebSocket] for testing.
*/
class MockSocket<T> implements WebSocket {
-
StreamController controller = new StreamController();
MockSocket twin;
Stream stream;
@@ -51,18 +66,48 @@ class MockSocket<T> implements WebSocket {
}
/**
- * A mock [ServerCommunicationChannel] channel that does nothing.
+ * A mock [ServerCommunicationChannel] for testing [AnalysisServer].
*/
class MockServerChannel implements ServerCommunicationChannel {
+ StreamController<Request> requestController = new StreamController<Request>();
+ StreamController<Response> responseController = new StreamController<Response>();
+ StreamController<Notification> notificationController = new StreamController<Notification>();
+
+ List<Response> responsesReceived = [];
+ List<Notification> notificationsReceived = [];
+
+ MockServerChannel() {
+ }
+
@override
void listen(void onRequest(Request request), {void onError(), void onDone()}) {
+ requestController.stream.listen(onRequest, onError: onError, onDone: onDone);
}
@override
void sendNotification(Notification notification) {
+ notificationsReceived.add(notification);
+ // Wrap send notification in future to simulate websocket
+ new Future(() => notificationController.add(notification));
+ }
+
+ /// Simulate request/response pair
+ Future<Response> sendRequest(Request request) {
+ var id = request.id;
+ // Wrap send request in future to simulate websocket
+ new Future(() => requestController.add(request));
+ return responseController.stream.firstWhere((response) => response.id == id);
}
@override
void sendResponse(Response response) {
+ responsesReceived.add(response);
+ // Wrap send response in future to simulate websocket
+ new Future(() => responseController.add(response));
+ }
+
+ void expectMsgCount({responseCount: 0, notificationCount: 0}) {
+ expect(responsesReceived, hasLength(responseCount));
+ expect(notificationsReceived, hasLength(notificationCount));
}
}
« no previous file with comments | « pkg/analysis_server/test/domain_server_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698