Index: pkg/analysis_server/test/mocks.dart |
diff --git a/pkg/analysis_server/test/mocks.dart b/pkg/analysis_server/test/mocks.dart |
index 186d6d079ef6ea9f0bc6c5ab67fee1550766f5f1..1c87b0e331bd0b7d75ef2cd5c316f3ae46c82633 100644 |
--- a/pkg/analysis_server/test/mocks.dart |
+++ b/pkg/analysis_server/test/mocks.dart |
@@ -4,15 +4,35 @@ |
library mocks; |
-import 'package:analysis_server/src/channel.dart'; |
+import 'dart:io'; |
+import 'dart:async'; |
/** |
- * Instances of the class [MockChannel] implement a [CommunicationChannel] that |
- * does nothing in response to every method invoked on it. |
+ * A mock [WebSocket] that immediately passes data to the listener. |
*/ |
-class MockChannel implements CommunicationChannel { |
- dynamic noSuchMethod(Invocation invocation) { |
- // Do nothing |
+class MockSocket<T> implements WebSocket { |
+ var onData; |
+ StreamSubscription<T> listen(void onData(T event), |
+ {Function onError, void onDone(), bool cancelOnError}) { |
+ this.onData = onData; |
return null; |
} |
+ void add(T event) => onData(event); |
+ noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
} |
+ |
+/** |
+ * A mock [WebSocket] for sending invalid JSON data and counting responses. |
+ */ |
+class InvalidJsonMockSocket<T> implements WebSocket { |
+ int responseCount = 0; |
+ var onData; |
+ StreamSubscription<T> listen(void onData(T event), |
+ {Function onError, void onDone(), bool cancelOnError}) { |
+ this.onData = onData; |
+ return null; |
+ } |
+ void addInvalid(T event) => onData(event); |
+ void add(T event) { responseCount++; } |
+ noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
+} |