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

Side by Side Diff: pkg/analysis_server_client/test/analysis_server_client_test.dart

Issue 2994723003: Add analysis_server_client without analysis_server (Closed)
Patch Set: feedback fixes Created 3 years, 4 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 unified diff | Download patch
« no previous file with comments | « pkg/analysis_server_client/pubspec.yaml ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2017, 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 import 'dart:async';
6 import 'dart:convert';
7 import 'dart:io';
8
9 import 'package:analysis_server_client/analysis_server_client.dart';
10 import 'package:mockito/mockito.dart';
11 import 'package:test/test.dart';
12
13 void main() {
14 Process _process;
15 AnalysisServerClient serverWrapper;
16
17 setUp(() async {
18 _process = new MockProcess();
19 serverWrapper = new AnalysisServerClient(_process);
20 when(_process.stdin).thenReturn(<int>[]);
21 });
22
23 test('test_listenToOutput_good', () async {
24 when(_process.stdout).thenReturn(_goodMessage());
25
26 final future = serverWrapper.send('blahMethod', null);
27 serverWrapper.listenToOutput();
28
29 final response = await future;
30 expect(response, new isInstanceOf<Map>());
31 final responseAsMap = response as Map;
32 expect(responseAsMap['foo'], 'bar');
33 });
34
35 test('test_listenToOutput_error', () async {
36 when(_process.stdout).thenReturn(_badMessage());
37 final future = serverWrapper.send('blahMethod', null);
38 future.catchError((e) {
39 expect(e, new isInstanceOf<ServerErrorMessage>());
40 final e2 = e as ServerErrorMessage;
41 expect(e2.code, 'someErrorCode');
42 expect(e2.message, 'something went wrong');
43 expect(e2.stackTrace, 'some long stack trace');
44 });
45 serverWrapper.listenToOutput();
46 });
47
48 test('test_listenToOutput_event', () async {
49 when(_process.stdout).thenReturn(_eventMessage());
50
51 void eventHandler(String event, Map<String, Object> params) {
52 expect(event, 'fooEvent');
53 expect(params.length, 2);
54 expect(params['foo'] as String, 'bar');
55 expect(params['baz'] as String, 'bang');
56 }
57
58 serverWrapper.send('blahMethod', null);
59 serverWrapper.listenToOutput(notificationProcessor: eventHandler);
60 });
61 }
62
63 Stream<List<int>> _goodMessage() async* {
64 yield UTF8.encoder.convert('Observatory listening on foo bar\n');
65 final sampleJson = {
66 'id': '0',
67 'result': {'foo': 'bar'}
68 };
69 yield UTF8.encoder.convert(JSON.encode(sampleJson));
70 }
71
72 final _badErrorMessage = {
73 'code': 'someErrorCode',
74 'message': 'something went wrong',
75 'stackTrace': 'some long stack trace'
76 };
77
78 Stream<List<int>> _badMessage() async* {
79 yield UTF8.encoder.convert('Observatory listening on foo bar\n');
80 final sampleJson = {'id': '0', 'error': _badErrorMessage};
81 yield UTF8.encoder.convert(JSON.encode(sampleJson));
82 }
83
84 Stream<List<int>> _eventMessage() async* {
85 yield UTF8.encoder.convert('Observatory listening on foo bar\n');
86 final sampleJson = {
87 'event': 'fooEvent',
88 'params': {'foo': 'bar', 'baz': 'bang'}
89 };
90 yield UTF8.encoder.convert(JSON.encode(sampleJson));
91 }
92
93 class MockProcess extends Mock implements Process {}
OLDNEW
« no previous file with comments | « pkg/analysis_server_client/pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698