enable Travis-CI (#23)
* enable Travis-CI
* dartfmt
* Add analysis options
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..63f5e5e
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,22 @@
+language: dart
+
+dart:
+ - dev
+ - stable
+
+dart_task:
+ - test
+ - dartanalyzer
+
+matrix:
+ include:
+ - dart: dev
+ dart_task: dartfmt
+
+# Only building master means that we don't run two builds for each pull request.
+branches:
+ only: [master]
+
+cache:
+ directories:
+ - $HOME/.pub-cache
diff --git a/analysis_options.yaml b/analysis_options.yaml
new file mode 100644
index 0000000..a10d4c5
--- /dev/null
+++ b/analysis_options.yaml
@@ -0,0 +1,2 @@
+analyzer:
+ strong-mode: true
diff --git a/lib/error_code.dart b/lib/error_code.dart
index 7dd8079..eb2d9be 100644
--- a/lib/error_code.dart
+++ b/lib/error_code.dart
@@ -39,11 +39,17 @@
/// If [errorCode] isn't defined in the JSON-RPC 2.0 spec, returns null.
String name(int errorCode) {
switch (errorCode) {
- case PARSE_ERROR: return "parse error";
- case INVALID_REQUEST: return "invalid request";
- case METHOD_NOT_FOUND: return "method not found";
- case INVALID_PARAMS: return "invalid parameters";
- case INTERNAL_ERROR: return "internal error";
- default: return null;
+ case PARSE_ERROR:
+ return "parse error";
+ case INVALID_REQUEST:
+ return "invalid request";
+ case METHOD_NOT_FOUND:
+ return "method not found";
+ case INVALID_PARAMS:
+ return "invalid parameters";
+ case INTERNAL_ERROR:
+ return "internal error";
+ default:
+ return null;
}
}
diff --git a/lib/src/channel_manager.dart b/lib/src/channel_manager.dart
index 8981d68..162c9ef 100644
--- a/lib/src/channel_manager.dart
+++ b/lib/src/channel_manager.dart
@@ -51,15 +51,12 @@
}
_listenCalled = true;
- _channel.stream.listen(handleInput,
- onError: (error, stackTrace) {
- _doneCompleter.completeError(error, stackTrace);
- _channel.sink.close();
- },
- onDone: () {
- if (!_doneCompleter.isCompleted) _doneCompleter.complete();
- },
- cancelOnError: true);
+ _channel.stream.listen(handleInput, onError: (error, stackTrace) {
+ _doneCompleter.completeError(error, stackTrace);
+ _channel.sink.close();
+ }, onDone: () {
+ if (!_doneCompleter.isCompleted) _doneCompleter.complete();
+ }, cancelOnError: true);
return done;
}
diff --git a/lib/src/client.dart b/lib/src/client.dart
index 7cd4282..3607c4a 100644
--- a/lib/src/client.dart
+++ b/lib/src/client.dart
@@ -137,10 +137,7 @@
}
if (isClosed) throw new StateError("The client is closed.");
- var message = <String, dynamic>{
- "jsonrpc": "2.0",
- "method": method
- };
+ var message = <String, dynamic>{"jsonrpc": "2.0", "method": method};
if (id != null) message["id"] = id;
if (parameters != null) message["params"] = parameters;
@@ -190,10 +187,10 @@
if (response.containsKey("result")) {
request.completer.complete(response["result"]);
} else {
- request.completer.completeError(new RpcException(
- response["error"]["code"],
- response["error"]["message"],
- data: response["error"]["data"]),
+ request.completer.completeError(
+ new RpcException(
+ response["error"]["code"], response["error"]["message"],
+ data: response["error"]["data"]),
request.chain);
}
}
diff --git a/lib/src/peer.dart b/lib/src/peer.dart
index c663da2..18cac07 100644
--- a/lib/src/peer.dart
+++ b/lib/src/peer.dart
@@ -56,10 +56,10 @@
/// [Peer.listen] is called.
Peer.withoutJson(StreamChannel channel)
: _manager = new ChannelManager("Peer", channel) {
- _server = new Server.withoutJson(new StreamChannel(
- _serverIncomingForwarder.stream, channel.sink));
- _client = new Client.withoutJson(new StreamChannel(
- _clientIncomingForwarder.stream, channel.sink));
+ _server = new Server.withoutJson(
+ new StreamChannel(_serverIncomingForwarder.stream, channel.sink));
+ _client = new Client.withoutJson(
+ new StreamChannel(_clientIncomingForwarder.stream, channel.sink));
}
// Client methods.
@@ -92,8 +92,9 @@
} else {
_serverIncomingForwarder.add(message);
}
- } else if (message is List && message.isNotEmpty &&
- message.first is Map) {
+ } else if (message is List &&
+ message.isNotEmpty &&
+ message.first is Map) {
if (message.first.containsKey('result') ||
message.first.containsKey('error')) {
_clientIncomingForwarder.add(message);
diff --git a/lib/src/server.dart b/lib/src/server.dart
index b85a46f..98f472b 100644
--- a/lib/src/server.dart
+++ b/lib/src/server.dart
@@ -168,11 +168,7 @@
// response, even if one is generated on the server.
if (!request.containsKey('id')) return null;
- return {
- 'jsonrpc': '2.0',
- 'result': result,
- 'id': request['id']
- };
+ return {'jsonrpc': '2.0', 'result': result, 'id': request['id']};
} catch (error, stackTrace) {
if (error is RpcException) {
if (error.code == error_code.INVALID_REQUEST ||
@@ -196,40 +192,54 @@
/// Validates that [request] matches the JSON-RPC spec.
void _validateRequest(request) {
if (request is! Map) {
- throw new RpcException(error_code.INVALID_REQUEST, 'Request must be '
+ throw new RpcException(
+ error_code.INVALID_REQUEST,
+ 'Request must be '
'an Array or an Object.');
}
if (!request.containsKey('jsonrpc')) {
- throw new RpcException(error_code.INVALID_REQUEST, 'Request must '
+ throw new RpcException(
+ error_code.INVALID_REQUEST,
+ 'Request must '
'contain a "jsonrpc" key.');
}
if (request['jsonrpc'] != '2.0') {
- throw new RpcException(error_code.INVALID_REQUEST, 'Invalid JSON-RPC '
+ throw new RpcException(
+ error_code.INVALID_REQUEST,
+ 'Invalid JSON-RPC '
'version ${JSON.encode(request['jsonrpc'])}, expected "2.0".');
}
if (!request.containsKey('method')) {
- throw new RpcException(error_code.INVALID_REQUEST, 'Request must '
+ throw new RpcException(
+ error_code.INVALID_REQUEST,
+ 'Request must '
'contain a "method" key.');
}
var method = request['method'];
if (request['method'] is! String) {
- throw new RpcException(error_code.INVALID_REQUEST, 'Request method must '
+ throw new RpcException(
+ error_code.INVALID_REQUEST,
+ 'Request method must '
'be a string, but was ${JSON.encode(method)}.');
}
var params = request['params'];
if (request.containsKey('params') && params is! List && params is! Map) {
- throw new RpcException(error_code.INVALID_REQUEST, 'Request params must '
+ throw new RpcException(
+ error_code.INVALID_REQUEST,
+ 'Request params must '
'be an Array or an Object, but was ${JSON.encode(params)}.');
}
var id = request['id'];
if (id != null && id is! String && id is! num) {
- throw new RpcException(error_code.INVALID_REQUEST, 'Request id must be a '
+ throw new RpcException(
+ error_code.INVALID_REQUEST,
+ 'Request id must be a '
'string, number, or null, but was ${JSON.encode(id)}.');
}
}
diff --git a/test/client/client_test.dart b/test/client/client_test.dart
index 5147a0b..1648df0 100644
--- a/test/client/client_test.dart
+++ b/test/client/client_test.dart
@@ -16,17 +16,15 @@
test("sends a message and returns the response", () {
controller.expectRequest((request) {
- expect(request, allOf([
- containsPair('jsonrpc', '2.0'),
- containsPair('method', 'foo'),
- containsPair('params', {'param': 'value'})
- ]));
+ expect(
+ request,
+ allOf([
+ containsPair('jsonrpc', '2.0'),
+ containsPair('method', 'foo'),
+ containsPair('params', {'param': 'value'})
+ ]));
- return {
- 'jsonrpc': '2.0',
- 'result': 'bar',
- 'id': request['id']
- };
+ return {'jsonrpc': '2.0', 'result': 'bar', 'id': request['id']};
});
expect(controller.client.sendRequest("foo", {'param': 'value'}),
@@ -35,11 +33,13 @@
test("sends a notification and expects no response", () {
controller.expectRequest((request) {
- expect(request, equals({
- 'jsonrpc': '2.0',
- 'method': 'foo',
- 'params': {'param': 'value'}
- }));
+ expect(
+ request,
+ equals({
+ 'jsonrpc': '2.0',
+ 'method': 'foo',
+ 'params': {'param': 'value'}
+ }));
});
controller.client.sendNotification("foo", {'param': 'value'});
@@ -47,11 +47,13 @@
test("sends a notification with positional parameters", () {
controller.expectRequest((request) {
- expect(request, equals({
- 'jsonrpc': '2.0',
- 'method': 'foo',
- 'params': ['value1', 'value2']
- }));
+ expect(
+ request,
+ equals({
+ 'jsonrpc': '2.0',
+ 'method': 'foo',
+ 'params': ['value1', 'value2']
+ }));
});
controller.client.sendNotification("foo", ['value1', 'value2']);
@@ -59,10 +61,7 @@
test("sends a notification with no parameters", () {
controller.expectRequest((request) {
- expect(request, equals({
- 'jsonrpc': '2.0',
- 'method': 'foo'
- }));
+ expect(request, equals({'jsonrpc': '2.0', 'method': 'foo'}));
});
controller.client.sendNotification("foo");
@@ -72,31 +71,22 @@
controller.expectRequest((request) {
expect(request, new isInstanceOf<List>());
expect(request, hasLength(3));
- expect(request[0], equals({
- 'jsonrpc': '2.0',
- 'method': 'foo'
- }));
- expect(request[1], allOf([
- containsPair('jsonrpc', '2.0'),
- containsPair('method', 'bar'),
- containsPair('params', {'param': 'value'})
- ]));
- expect(request[2], allOf([
- containsPair('jsonrpc', '2.0'),
- containsPair('method', 'baz')
- ]));
+ expect(request[0], equals({'jsonrpc': '2.0', 'method': 'foo'}));
+ expect(
+ request[1],
+ allOf([
+ containsPair('jsonrpc', '2.0'),
+ containsPair('method', 'bar'),
+ containsPair('params', {'param': 'value'})
+ ]));
+ expect(
+ request[2],
+ allOf(
+ [containsPair('jsonrpc', '2.0'), containsPair('method', 'baz')]));
return [
- {
- 'jsonrpc': '2.0',
- 'result': 'baz response',
- 'id': request[2]['id']
- },
- {
- 'jsonrpc': '2.0',
- 'result': 'bar response',
- 'id': request[1]['id']
- }
+ {'jsonrpc': '2.0', 'result': 'baz response', 'id': request[2]['id']},
+ {'jsonrpc': '2.0', 'result': 'bar response', 'id': request[1]['id']}
];
});
@@ -113,31 +103,22 @@
controller.expectRequest((request) {
expect(request, new isInstanceOf<List>());
expect(request, hasLength(3));
- expect(request[0], equals({
- 'jsonrpc': '2.0',
- 'method': 'foo'
- }));
- expect(request[1], allOf([
- containsPair('jsonrpc', '2.0'),
- containsPair('method', 'bar'),
- containsPair('params', {'param': 'value'})
- ]));
- expect(request[2], allOf([
- containsPair('jsonrpc', '2.0'),
- containsPair('method', 'baz')
- ]));
+ expect(request[0], equals({'jsonrpc': '2.0', 'method': 'foo'}));
+ expect(
+ request[1],
+ allOf([
+ containsPair('jsonrpc', '2.0'),
+ containsPair('method', 'bar'),
+ containsPair('params', {'param': 'value'})
+ ]));
+ expect(
+ request[2],
+ allOf(
+ [containsPair('jsonrpc', '2.0'), containsPair('method', 'baz')]));
return [
- {
- 'jsonrpc': '2.0',
- 'result': 'baz response',
- 'id': request[2]['id']
- },
- {
- 'jsonrpc': '2.0',
- 'result': 'bar response',
- 'id': request[1]['id']
- }
+ {'jsonrpc': '2.0', 'result': 'baz response', 'id': request[2]['id']},
+ {'jsonrpc': '2.0', 'result': 'bar response', 'id': request[1]['id']}
];
});
@@ -158,10 +139,10 @@
test("reports an error from the server", () {
controller.expectRequest((request) {
- expect(request, allOf([
- containsPair('jsonrpc', '2.0'),
- containsPair('method', 'foo')
- ]));
+ expect(
+ request,
+ allOf(
+ [containsPair('jsonrpc', '2.0'), containsPair('method', 'foo')]));
return {
'jsonrpc': '2.0',
@@ -195,46 +176,25 @@
controller.expectRequest((request) {
controller.sendJsonResponse("{invalid");
controller.sendResponse("not a map");
+ controller.sendResponse(
+ {'jsonrpc': 'wrong version', 'result': 'wrong', 'id': request['id']});
+ controller.sendResponse({'jsonrpc': '2.0', 'result': 'wrong'});
+ controller.sendResponse({'jsonrpc': '2.0', 'id': request['id']});
+ controller.sendResponse(
+ {'jsonrpc': '2.0', 'error': 'not a map', 'id': request['id']});
controller.sendResponse({
- 'jsonrpc': 'wrong version',
- 'result': 'wrong',
+ 'jsonrpc': '2.0',
+ 'error': {'code': 'not an int', 'message': 'dang yo'},
'id': request['id']
});
controller.sendResponse({
'jsonrpc': '2.0',
- 'result': 'wrong'
- });
- controller.sendResponse({
- 'jsonrpc': '2.0',
- 'id': request['id']
- });
- controller.sendResponse({
- 'jsonrpc': '2.0',
- 'error': 'not a map',
- 'id': request['id']
- });
- controller.sendResponse({
- 'jsonrpc': '2.0',
- 'error': {
- 'code': 'not an int',
- 'message': 'dang yo'
- },
- 'id': request['id']
- });
- controller.sendResponse({
- 'jsonrpc': '2.0',
- 'error': {
- 'code': 123,
- 'message': 0xDEADBEEF
- },
+ 'error': {'code': 123, 'message': 0xDEADBEEF},
'id': request['id']
});
- return pumpEventQueue().then((_) => {
- 'jsonrpc': '2.0',
- 'result': 'right',
- 'id': request['id']
- });
+ return pumpEventQueue().then(
+ (_) => {'jsonrpc': '2.0', 'result': 'right', 'id': request['id']});
});
expect(controller.client.sendRequest("foo"), completion(equals('right')));
diff --git a/test/client/stream_test.dart b/test/client/stream_test.dart
index fb71f17..94a0604 100644
--- a/test/client/stream_test.dart
+++ b/test/client/stream_test.dart
@@ -24,16 +24,13 @@
client.listen();
expect(requestController.stream.first.then((request) {
- expect(request, allOf([
- containsPair('jsonrpc', '2.0'),
- containsPair('method', 'foo')
- ]));
+ expect(
+ request,
+ allOf(
+ [containsPair('jsonrpc', '2.0'), containsPair('method', 'foo')]));
- responseController.add({
- 'jsonrpc': '2.0',
- 'result': 'bar',
- 'id': request['id']
- });
+ responseController
+ .add({'jsonrpc': '2.0', 'result': 'bar', 'id': request['id']});
}), completes);
client.sendRequest('foo');
diff --git a/test/client/utils.dart b/test/client/utils.dart
index 9b35da5..cd53493 100644
--- a/test/client/utils.dart
+++ b/test/client/utils.dart
@@ -35,13 +35,15 @@
/// null, no response is sent. Otherwise, the return value is encoded and sent
/// as the response.
void expectRequest(callback(request)) {
- expect(_requestController.stream.first.then((request) {
- return callback(JSON.decode(request));
- }).then((response) {
- if (response == null) return;
- if (response is! String) response = JSON.encode(response);
- _responseController.add(response);
- }), completes);
+ expect(
+ _requestController.stream.first.then((request) {
+ return callback(JSON.decode(request));
+ }).then((response) {
+ if (response == null) return;
+ if (response is! String) response = JSON.encode(response);
+ _responseController.add(response);
+ }),
+ completes);
}
/// Sends [response], a decoded response, to [client].
diff --git a/test/peer_test.dart b/test/peer_test.dart
index 5241e15..f2ab5b1 100644
--- a/test/peer_test.dart
+++ b/test/peer_test.dart
@@ -27,71 +27,59 @@
group("like a client,", () {
test("can send a message and receive a response", () {
expect(outgoing.first.then((request) {
- expect(request, equals({
- "jsonrpc": "2.0",
- "method": "foo",
- "params": {"bar": "baz"},
- "id": 0
- }));
- incoming.add({
- "jsonrpc": "2.0",
- "result": "qux",
- "id": 0
- });
+ expect(
+ request,
+ equals({
+ "jsonrpc": "2.0",
+ "method": "foo",
+ "params": {"bar": "baz"},
+ "id": 0
+ }));
+ incoming.add({"jsonrpc": "2.0", "result": "qux", "id": 0});
}), completes);
peer.listen();
- expect(peer.sendRequest("foo", {"bar": "baz"}),
- completion(equals("qux")));
+ expect(
+ peer.sendRequest("foo", {"bar": "baz"}), completion(equals("qux")));
});
test("can send a batch of messages and receive a batch of responses", () {
expect(outgoing.first.then((request) {
- expect(request, equals([
- {
- "jsonrpc": "2.0",
- "method": "foo",
- "params": {"bar": "baz"},
- "id": 0
- },
- {
- "jsonrpc": "2.0",
- "method": "a",
- "params": {"b": "c"},
- "id": 1
- },
- {
- "jsonrpc": "2.0",
- "method": "w",
- "params": {"x": "y"},
- "id": 2
- }
- ]));
+ expect(
+ request,
+ equals([
+ {
+ "jsonrpc": "2.0",
+ "method": "foo",
+ "params": {"bar": "baz"},
+ "id": 0
+ },
+ {
+ "jsonrpc": "2.0",
+ "method": "a",
+ "params": {"b": "c"},
+ "id": 1
+ },
+ {
+ "jsonrpc": "2.0",
+ "method": "w",
+ "params": {"x": "y"},
+ "id": 2
+ }
+ ]));
incoming.add([
- {
- "jsonrpc": "2.0",
- "result": "qux",
- "id": 0
- },
- {
- "jsonrpc": "2.0",
- "result": "d",
- "id": 1
- },
- {
- "jsonrpc": "2.0",
- "result": "z",
- "id": 2
- }
+ {"jsonrpc": "2.0", "result": "qux", "id": 0},
+ {"jsonrpc": "2.0", "result": "d", "id": 1},
+ {"jsonrpc": "2.0", "result": "z", "id": 2}
]);
}), completes);
peer.listen();
peer.withBatch(() {
- expect(peer.sendRequest("foo", {"bar": "baz"}),
- completion(equals("qux")));
+ expect(
+ peer.sendRequest("foo", {"bar": "baz"}), completion(equals("qux")));
expect(peer.sendRequest("a", {"b": "c"}), completion(equals("d")));
expect(peer.sendRequest("w", {"x": "y"}), completion(equals("z")));
});
@@ -100,11 +88,8 @@
group("like a server,", () {
test("can receive a call and return a response", () {
- expect(outgoing.first, completion(equals({
- "jsonrpc": "2.0",
- "result": "qux",
- "id": 0
- })));
+ expect(outgoing.first,
+ completion(equals({"jsonrpc": "2.0", "result": "qux", "id": 0})));
peer.registerMethod("foo", (_) => "qux");
peer.listen();
@@ -118,23 +103,13 @@
});
test("can receive a batch of calls and return a batch of responses", () {
- expect(outgoing.first, completion(equals([
- {
- "jsonrpc": "2.0",
- "result": "qux",
- "id": 0
- },
- {
- "jsonrpc": "2.0",
- "result": "d",
- "id": 1
- },
- {
- "jsonrpc": "2.0",
- "result": "z",
- "id": 2
- }
- ])));
+ expect(
+ outgoing.first,
+ completion(equals([
+ {"jsonrpc": "2.0", "result": "qux", "id": 0},
+ {"jsonrpc": "2.0", "result": "d", "id": 1},
+ {"jsonrpc": "2.0", "result": "z", "id": 2}
+ ])));
peer.registerMethod("foo", (_) => "qux");
peer.registerMethod("a", (_) => "d");
@@ -169,16 +144,20 @@
var jsonPeer = new json_rpc.Peer(
new StreamChannel(incomingController.stream, outgoingController));
- expect(outgoingController.stream.first.then(JSON.decode), completion({
- "jsonrpc": "2.0",
- "error": {
- 'code': error_code.PARSE_ERROR,
- "message": startsWith("Invalid JSON: "),
- // TODO(nweiz): Always expect the source when sdk#25655 is fixed.
- "data": {'request': anyOf([isNull, '{invalid'])}
- },
- "id": null
- }));
+ expect(
+ outgoingController.stream.first.then(JSON.decode),
+ completion({
+ "jsonrpc": "2.0",
+ "error": {
+ 'code': error_code.PARSE_ERROR,
+ "message": startsWith("Invalid JSON: "),
+ // TODO(nweiz): Always expect the source when sdk#25655 is fixed.
+ "data": {
+ 'request': anyOf([isNull, '{invalid'])
+ }
+ },
+ "id": null
+ }));
jsonPeer.listen();
@@ -186,21 +165,23 @@
});
test("returns a response for incorrectly-structured JSON", () {
- expect(outgoing.first, completion({
- "jsonrpc": "2.0",
- "error": {
- 'code': error_code.INVALID_REQUEST,
- "message": 'Request must contain a "jsonrpc" key.',
- "data": {'request': {'completely': 'wrong'}}
- },
- "id": null
- }));
+ expect(
+ outgoing.first,
+ completion({
+ "jsonrpc": "2.0",
+ "error": {
+ 'code': error_code.INVALID_REQUEST,
+ "message": 'Request must contain a "jsonrpc" key.',
+ "data": {
+ 'request': {'completely': 'wrong'}
+ }
+ },
+ "id": null
+ }));
peer.listen();
- incoming.add({
- "completely": "wrong"
- });
+ incoming.add({"completely": "wrong"});
});
});
}
diff --git a/test/server/batch_test.dart b/test/server/batch_test.dart
index 11ec66e..3257256 100644
--- a/test/server/batch_test.dart
+++ b/test/server/batch_test.dart
@@ -12,60 +12,106 @@
setUp(() {
controller = new ServerController();
controller.server
- ..registerMethod('foo', () => 'foo')
- ..registerMethod('id', (params) => params.value)
- ..registerMethod('arg', (params) => params['arg'].value);
+ ..registerMethod('foo', () => 'foo')
+ ..registerMethod('id', (params) => params.value)
+ ..registerMethod('arg', (params) => params['arg'].value);
});
test('handles a batch of requests', () {
- expect(controller.handleRequest([
- {'jsonrpc': '2.0', 'method': 'foo', 'id': 1},
- {'jsonrpc': '2.0', 'method': 'id', 'params': ['value'], 'id': 2},
- {'jsonrpc': '2.0', 'method': 'arg', 'params': {'arg': 'value'}, 'id': 3}
- ]), completion(equals([
- {'jsonrpc': '2.0', 'result': 'foo', 'id': 1},
- {'jsonrpc': '2.0', 'result': ['value'], 'id': 2},
- {'jsonrpc': '2.0', 'result': 'value', 'id': 3}
- ])));
+ expect(
+ controller.handleRequest([
+ {'jsonrpc': '2.0', 'method': 'foo', 'id': 1},
+ {
+ 'jsonrpc': '2.0',
+ 'method': 'id',
+ 'params': ['value'],
+ 'id': 2
+ },
+ {
+ 'jsonrpc': '2.0',
+ 'method': 'arg',
+ 'params': {'arg': 'value'},
+ 'id': 3
+ }
+ ]),
+ completion(equals([
+ {'jsonrpc': '2.0', 'result': 'foo', 'id': 1},
+ {
+ 'jsonrpc': '2.0',
+ 'result': ['value'],
+ 'id': 2
+ },
+ {'jsonrpc': '2.0', 'result': 'value', 'id': 3}
+ ])));
});
test('handles errors individually', () {
- expect(controller.handleRequest([
- {'jsonrpc': '2.0', 'method': 'foo', 'id': 1},
- {'jsonrpc': '2.0', 'method': 'zap', 'id': 2},
- {'jsonrpc': '2.0', 'method': 'arg', 'params': {'arg': 'value'}, 'id': 3}
- ]), completion(equals([
- {'jsonrpc': '2.0', 'result': 'foo', 'id': 1},
- {
- 'jsonrpc': '2.0',
- 'id': 2,
- 'error': {
- 'code': error_code.METHOD_NOT_FOUND,
- 'message': 'Unknown method "zap".',
- 'data': {'request': {'jsonrpc': '2.0', 'method': 'zap', 'id': 2}},
- }
- },
- {'jsonrpc': '2.0', 'result': 'value', 'id': 3}
- ])));
+ expect(
+ controller.handleRequest([
+ {'jsonrpc': '2.0', 'method': 'foo', 'id': 1},
+ {'jsonrpc': '2.0', 'method': 'zap', 'id': 2},
+ {
+ 'jsonrpc': '2.0',
+ 'method': 'arg',
+ 'params': {'arg': 'value'},
+ 'id': 3
+ }
+ ]),
+ completion(equals([
+ {'jsonrpc': '2.0', 'result': 'foo', 'id': 1},
+ {
+ 'jsonrpc': '2.0',
+ 'id': 2,
+ 'error': {
+ 'code': error_code.METHOD_NOT_FOUND,
+ 'message': 'Unknown method "zap".',
+ 'data': {
+ 'request': {'jsonrpc': '2.0', 'method': 'zap', 'id': 2}
+ },
+ }
+ },
+ {'jsonrpc': '2.0', 'result': 'value', 'id': 3}
+ ])));
});
test('handles notifications individually', () {
- expect(controller.handleRequest([
- {'jsonrpc': '2.0', 'method': 'foo', 'id': 1},
- {'jsonrpc': '2.0', 'method': 'id', 'params': ['value']},
- {'jsonrpc': '2.0', 'method': 'arg', 'params': {'arg': 'value'}, 'id': 3}
- ]), completion(equals([
- {'jsonrpc': '2.0', 'result': 'foo', 'id': 1},
- {'jsonrpc': '2.0', 'result': 'value', 'id': 3}
- ])));
+ expect(
+ controller.handleRequest([
+ {'jsonrpc': '2.0', 'method': 'foo', 'id': 1},
+ {
+ 'jsonrpc': '2.0',
+ 'method': 'id',
+ 'params': ['value']
+ },
+ {
+ 'jsonrpc': '2.0',
+ 'method': 'arg',
+ 'params': {'arg': 'value'},
+ 'id': 3
+ }
+ ]),
+ completion(equals([
+ {'jsonrpc': '2.0', 'result': 'foo', 'id': 1},
+ {'jsonrpc': '2.0', 'result': 'value', 'id': 3}
+ ])));
});
test('returns nothing if every request is a notification', () {
- expect(controller.handleRequest([
- {'jsonrpc': '2.0', 'method': 'foo'},
- {'jsonrpc': '2.0', 'method': 'id', 'params': ['value']},
- {'jsonrpc': '2.0', 'method': 'arg', 'params': {'arg': 'value'}}
- ]), doesNotComplete);
+ expect(
+ controller.handleRequest([
+ {'jsonrpc': '2.0', 'method': 'foo'},
+ {
+ 'jsonrpc': '2.0',
+ 'method': 'id',
+ 'params': ['value']
+ },
+ {
+ 'jsonrpc': '2.0',
+ 'method': 'arg',
+ 'params': {'arg': 'value'}
+ }
+ ]),
+ doesNotComplete);
});
test('returns an error if the batch is empty', () {
@@ -74,16 +120,26 @@
});
test('disallows nested batches', () {
- expect(controller.handleRequest([
- [{'jsonrpc': '2.0', 'method': 'foo', 'id': 1}]
- ]), completion(equals([{
- 'jsonrpc': '2.0',
- 'id': null,
- 'error': {
- 'code': error_code.INVALID_REQUEST,
- 'message': 'Request must be an Array or an Object.',
- 'data': {'request': [{'jsonrpc': '2.0', 'method': 'foo', 'id': 1}]}
- }
- }])));
+ expect(
+ controller.handleRequest([
+ [
+ {'jsonrpc': '2.0', 'method': 'foo', 'id': 1}
+ ]
+ ]),
+ completion(equals([
+ {
+ 'jsonrpc': '2.0',
+ 'id': null,
+ 'error': {
+ 'code': error_code.INVALID_REQUEST,
+ 'message': 'Request must be an Array or an Object.',
+ 'data': {
+ 'request': [
+ {'jsonrpc': '2.0', 'method': 'foo', 'id': 1}
+ ]
+ }
+ }
+ }
+ ])));
});
}
diff --git a/test/server/invalid_request_test.dart b/test/server/invalid_request_test.dart
index cd54b6f..e62558f 100644
--- a/test/server/invalid_request_test.dart
+++ b/test/server/invalid_request_test.dart
@@ -17,65 +17,61 @@
});
test("requests must have a jsonrpc key", () {
- expectErrorResponse(controller, {
- 'method': 'foo',
- 'id': 1234
- }, error_code.INVALID_REQUEST, 'Request must contain a "jsonrpc" key.');
+ expectErrorResponse(controller, {'method': 'foo', 'id': 1234},
+ error_code.INVALID_REQUEST, 'Request must contain a "jsonrpc" key.');
});
test("the jsonrpc version must be 2.0", () {
- expectErrorResponse(controller, {
- 'jsonrpc': '1.0',
- 'method': 'foo',
- 'id': 1234
- }, error_code.INVALID_REQUEST,
+ expectErrorResponse(
+ controller,
+ {'jsonrpc': '1.0', 'method': 'foo', 'id': 1234},
+ error_code.INVALID_REQUEST,
'Invalid JSON-RPC version "1.0", expected "2.0".');
});
test("requests must have a method key", () {
- expectErrorResponse(controller, {
- 'jsonrpc': '2.0',
- 'id': 1234
- }, error_code.INVALID_REQUEST, 'Request must contain a "method" key.');
+ expectErrorResponse(controller, {'jsonrpc': '2.0', 'id': 1234},
+ error_code.INVALID_REQUEST, 'Request must contain a "method" key.');
});
test("request method must be a string", () {
- expectErrorResponse(controller, {
- 'jsonrpc': '2.0',
- 'method': 1234,
- 'id': 1234
- }, error_code.INVALID_REQUEST,
+ expectErrorResponse(
+ controller,
+ {'jsonrpc': '2.0', 'method': 1234, 'id': 1234},
+ error_code.INVALID_REQUEST,
'Request method must be a string, but was 1234.');
});
test("request params must be an Array or Object", () {
- expectErrorResponse(controller, {
- 'jsonrpc': '2.0',
- 'method': 'foo',
- 'params': 1234,
- 'id': 1234
- }, error_code.INVALID_REQUEST,
+ expectErrorResponse(
+ controller,
+ {'jsonrpc': '2.0', 'method': 'foo', 'params': 1234, 'id': 1234},
+ error_code.INVALID_REQUEST,
'Request params must be an Array or an Object, but was 1234.');
});
test("request id may not be an Array or Object", () {
- expect(controller.handleRequest({
- 'jsonrpc': '2.0',
- 'method': 'foo',
- 'id': {'bad': 'id'}
- }), completion(equals({
- 'jsonrpc': '2.0',
- 'id': null,
- 'error': {
- 'code': error_code.INVALID_REQUEST,
- 'message': 'Request id must be a string, number, or null, but was '
- '{"bad":"id"}.',
- 'data': {'request': {
+ expect(
+ controller.handleRequest({
'jsonrpc': '2.0',
'method': 'foo',
'id': {'bad': 'id'}
- }}
- }
- })));
+ }),
+ completion(equals({
+ 'jsonrpc': '2.0',
+ 'id': null,
+ 'error': {
+ 'code': error_code.INVALID_REQUEST,
+ 'message': 'Request id must be a string, number, or null, but was '
+ '{"bad":"id"}.',
+ 'data': {
+ 'request': {
+ 'jsonrpc': '2.0',
+ 'method': 'foo',
+ 'id': {'bad': 'id'}
+ }
+ }
+ }
+ })));
});
}
diff --git a/test/server/parameters_test.dart b/test/server/parameters_test.dart
index e7cb9f2..c970bef 100644
--- a/test/server/parameters_test.dart
+++ b/test/server/parameters_test.dart
@@ -20,32 +20,29 @@
"date-time": "1990-01-01 00:00:00.000",
"uri": "http://dartlang.org",
"invalid-uri": "http://[::1",
- "map": {
- "num": 4.2,
- "bool": false
- }
+ "map": {"num": 4.2, "bool": false}
});
});
test("value returns the wrapped value", () {
- expect(parameters.value, equals({
- "num": 1.5,
- "int": 1,
- "bool": true,
- "string": "zap",
- "list": [1, 2, 3],
- "date-time": "1990-01-01 00:00:00.000",
- "uri": "http://dartlang.org",
- "invalid-uri": "http://[::1",
- "map": {
- "num": 4.2,
- "bool": false
- }
- }));
+ expect(
+ parameters.value,
+ equals({
+ "num": 1.5,
+ "int": 1,
+ "bool": true,
+ "string": "zap",
+ "list": [1, 2, 3],
+ "date-time": "1990-01-01 00:00:00.000",
+ "uri": "http://dartlang.org",
+ "invalid-uri": "http://[::1",
+ "map": {"num": 4.2, "bool": false}
+ }));
});
test("[int] throws a parameter error", () {
- expect(() => parameters[0],
+ expect(
+ () => parameters[0],
throwsInvalidParams('Parameters for method "foo" must be passed by '
'position.'));
});
@@ -59,7 +56,8 @@
});
test("[].value fails for absent parameters", () {
- expect(() => parameters['fblthp'].value,
+ expect(
+ () => parameters['fblthp'].value,
throwsInvalidParams('Request for method "foo" is missing required '
'parameter "fblthp".'));
});
@@ -86,19 +84,22 @@
});
test("[].asNum fails for non-numeric parameters", () {
- expect(() => parameters['bool'].asNum,
+ expect(
+ () => parameters['bool'].asNum,
throwsInvalidParams('Parameter "bool" for method "foo" must be a '
'number, but was true.'));
});
test("[].asNumOr fails for non-numeric parameters", () {
- expect(() => parameters['bool'].asNumOr(7),
+ expect(
+ () => parameters['bool'].asNumOr(7),
throwsInvalidParams('Parameter "bool" for method "foo" must be a '
'number, but was true.'));
});
test("[].asNum fails for absent parameters", () {
- expect(() => parameters['fblthp'].asNum,
+ expect(
+ () => parameters['fblthp'].asNum,
throwsInvalidParams('Request for method "foo" is missing required '
'parameter "fblthp".'));
});
@@ -116,7 +117,8 @@
});
test("[].asInt fails for non-integer parameters", () {
- expect(() => parameters['bool'].asInt,
+ expect(
+ () => parameters['bool'].asInt,
throwsInvalidParams('Parameter "bool" for method "foo" must be an '
'integer, but was true.'));
});
@@ -134,7 +136,8 @@
});
test("[].asBoolOr fails for non-boolean parameters", () {
- expect(() => parameters['int'].asBool,
+ expect(
+ () => parameters['int'].asBool,
throwsInvalidParams('Parameter "int" for method "foo" must be a '
'boolean, but was 1.'));
});
@@ -152,7 +155,8 @@
});
test("[].asString fails for non-string parameters", () {
- expect(() => parameters['int'].asString,
+ expect(
+ () => parameters['int'].asString,
throwsInvalidParams('Parameter "int" for method "foo" must be a '
'string, but was 1.'));
});
@@ -170,7 +174,8 @@
});
test("[].asList fails for non-list parameters", () {
- expect(() => parameters['int'].asList,
+ expect(
+ () => parameters['int'].asList,
throwsInvalidParams('Parameter "int" for method "foo" must be an '
'Array, but was 1.'));
});
@@ -184,12 +189,13 @@
});
test("[].asMapOr returns map parameters", () {
- expect(parameters['map'].asMapOr({}),
- equals({"num": 4.2, "bool": false}));
+ expect(
+ parameters['map'].asMapOr({}), equals({"num": 4.2, "bool": false}));
});
test("[].asMap fails for non-map parameters", () {
- expect(() => parameters['int'].asMap,
+ expect(
+ () => parameters['int'].asMap,
throwsInvalidParams('Parameter "int" for method "foo" must be an '
'Object, but was 1.'));
});
@@ -208,7 +214,8 @@
});
test("[].asDateTime fails for non-date/time parameters", () {
- expect(() => parameters['int'].asDateTime,
+ expect(
+ () => parameters['int'].asDateTime,
throwsInvalidParams('Parameter "int" for method "foo" must be a '
'string, but was 1.'));
});
@@ -219,13 +226,15 @@
});
test("[].asDateTime fails for non-date/time parameters", () {
- expect(() => parameters['int'].asDateTime,
+ expect(
+ () => parameters['int'].asDateTime,
throwsInvalidParams('Parameter "int" for method "foo" must be a '
'string, but was 1.'));
});
test("[].asDateTime fails for invalid date/times", () {
- expect(() => parameters['string'].asDateTime,
+ expect(
+ () => parameters['string'].asDateTime,
throwsInvalidParams('Parameter "string" for method "foo" must be a '
'valid date/time, but was "zap".\n'
'Invalid date format'));
@@ -241,7 +250,8 @@
});
test("[].asUri fails for non-URI parameters", () {
- expect(() => parameters['int'].asUri,
+ expect(
+ () => parameters['int'].asUri,
throwsInvalidParams('Parameter "int" for method "foo" must be a '
'string, but was 1.'));
});
@@ -252,13 +262,15 @@
});
test("[].asUri fails for non-URI parameters", () {
- expect(() => parameters['int'].asUri,
+ expect(
+ () => parameters['int'].asUri,
throwsInvalidParams('Parameter "int" for method "foo" must be a '
'string, but was 1.'));
});
test("[].asUri fails for invalid URIs", () {
- expect(() => parameters['invalid-uri'].asUri,
+ expect(
+ () => parameters['invalid-uri'].asUri,
throwsInvalidParams('Parameter "invalid-uri" for method "foo" must '
'be a valid URI, but was "http://[::1".\n'
'Missing end `]` to match `[` in host'));
@@ -269,7 +281,8 @@
setUp(() => nested = parameters['map']);
test("[int] fails with a type error", () {
- expect(() => nested[0],
+ expect(
+ () => nested[0],
throwsInvalidParams('Parameter "map" for method "foo" must be an '
'Array, but was {"num":4.2,"bool":false}.'));
});
@@ -280,7 +293,8 @@
});
test("[].value fails for absent parameters", () {
- expect(() => nested['fblthp'].value,
+ expect(
+ () => nested['fblthp'].value,
throwsInvalidParams('Request for method "foo" is missing required '
'parameter map.fblthp.'));
});
@@ -290,7 +304,8 @@
});
test("typed getters fail for incorrectly-typed parameters", () {
- expect(() => nested['bool'].asNum,
+ expect(
+ () => nested['bool'].asNum,
throwsInvalidParams('Parameter map.bool for method "foo" must be '
'a number, but was false.'));
});
@@ -301,7 +316,8 @@
setUp(() => nested = parameters['list']);
test("[string] fails with a type error", () {
- expect(() => nested['foo'],
+ expect(
+ () => nested['foo'],
throwsInvalidParams('Parameter "list" for method "foo" must be an '
'Object, but was [1,2,3].'));
});
@@ -312,7 +328,8 @@
});
test("[].value fails for absent parameters", () {
- expect(() => nested[5].value,
+ expect(
+ () => nested[5].value,
throwsInvalidParams('Request for method "foo" is missing required '
'parameter list[5].'));
});
@@ -322,7 +339,8 @@
});
test("typed getters fail for incorrectly-typed parameters", () {
- expect(() => nested[0].asBool,
+ expect(
+ () => nested[0].asBool,
throwsInvalidParams('Parameter list[0] for method "foo" must be '
'a boolean, but was 1.'));
});
@@ -338,7 +356,8 @@
});
test("[string] throws a parameter error", () {
- expect(() => parameters['foo'],
+ expect(
+ () => parameters['foo'],
throwsInvalidParams('Parameters for method "foo" must be passed by '
'name.'));
});
@@ -348,7 +367,8 @@
});
test("[].value fails for out-of-range parameters", () {
- expect(() => parameters[10].value,
+ expect(
+ () => parameters[10].value,
throwsInvalidParams('Request for method "foo" is missing required '
'parameter 11.'));
});
@@ -364,10 +384,18 @@
test("with a complex parameter path", () {
var parameters = new json_rpc.Parameters("foo", {
- 'bar baz': [0, 1, 2, {'bang.zap': {'\n': 'qux'}}]
+ 'bar baz': [
+ 0,
+ 1,
+ 2,
+ {
+ 'bang.zap': {'\n': 'qux'}
+ }
+ ]
});
- expect(() => parameters['bar baz'][3]['bang.zap']['\n']['bip'],
+ expect(
+ () => parameters['bar baz'][3]['bang.zap']['\n']['bip'],
throwsInvalidParams('Parameter "bar baz"[3]."bang.zap"."\\n" for '
'method "foo" must be an Object, but was "qux".'));
});
diff --git a/test/server/server_test.dart b/test/server/server_test.dart
index ef2e45b..cfe8b2f 100644
--- a/test/server/server_test.dart
+++ b/test/server/server_test.dart
@@ -19,75 +19,70 @@
return {'params': params.value};
});
- expect(controller.handleRequest({
- 'jsonrpc': '2.0',
- 'method': 'foo',
- 'params': {'param': 'value'},
- 'id': 1234
- }), completion(equals({
- 'jsonrpc': '2.0',
- 'result': {'params': {'param': 'value'}},
- 'id': 1234
- })));
+ expect(
+ controller.handleRequest({
+ 'jsonrpc': '2.0',
+ 'method': 'foo',
+ 'params': {'param': 'value'},
+ 'id': 1234
+ }),
+ completion(equals({
+ 'jsonrpc': '2.0',
+ 'result': {
+ 'params': {'param': 'value'}
+ },
+ 'id': 1234
+ })));
});
test("calls a method that takes no parameters", () {
controller.server.registerMethod('foo', () => 'foo');
- expect(controller.handleRequest({
- 'jsonrpc': '2.0',
- 'method': 'foo',
- 'id': 1234
- }), completion(equals({
- 'jsonrpc': '2.0',
- 'result': 'foo',
- 'id': 1234
- })));
+ expect(
+ controller
+ .handleRequest({'jsonrpc': '2.0', 'method': 'foo', 'id': 1234}),
+ completion(equals({'jsonrpc': '2.0', 'result': 'foo', 'id': 1234})));
});
test("a method that takes no parameters rejects parameters", () {
controller.server.registerMethod('foo', () => 'foo');
- expectErrorResponse(controller, {
- 'jsonrpc': '2.0',
- 'method': 'foo',
- 'params': {},
- 'id': 1234
- },
+ expectErrorResponse(
+ controller,
+ {'jsonrpc': '2.0', 'method': 'foo', 'params': {}, 'id': 1234},
error_code.INVALID_PARAMS,
'No parameters are allowed for method "foo".');
});
test("an unexpected error in a method is captured", () {
- controller.server.registerMethod('foo', () => throw new FormatException('bad format'));
+ controller.server
+ .registerMethod('foo', () => throw new FormatException('bad format'));
- expect(controller.handleRequest({
- 'jsonrpc': '2.0',
- 'method': 'foo',
- 'id': 1234
- }), completion({
- 'jsonrpc': '2.0',
- 'id': 1234,
- 'error': {
- 'code': error_code.SERVER_ERROR,
- 'message': 'bad format',
- 'data': {
- 'request': {'jsonrpc': '2.0', 'method': 'foo', 'id': 1234},
- 'full': 'FormatException: bad format',
- 'stack': new isInstanceOf<String>()
- }
- }
- }));
+ expect(
+ controller
+ .handleRequest({'jsonrpc': '2.0', 'method': 'foo', 'id': 1234}),
+ completion({
+ 'jsonrpc': '2.0',
+ 'id': 1234,
+ 'error': {
+ 'code': error_code.SERVER_ERROR,
+ 'message': 'bad format',
+ 'data': {
+ 'request': {'jsonrpc': '2.0', 'method': 'foo', 'id': 1234},
+ 'full': 'FormatException: bad format',
+ 'stack': new isInstanceOf<String>()
+ }
+ }
+ }));
});
test("doesn't return a result for a notification", () {
controller.server.registerMethod('foo', (args) => 'result');
- expect(controller.handleRequest({
- 'jsonrpc': '2.0',
- 'method': 'foo',
- 'params': {}
- }), doesNotComplete);
+ expect(
+ controller
+ .handleRequest({'jsonrpc': '2.0', 'method': 'foo', 'params': {}}),
+ doesNotComplete);
});
test("includes the error data in the response", () {
@@ -95,12 +90,9 @@
throw new json_rpc.RpcException(5, 'Error message.', data: 'data value');
});
- expectErrorResponse(controller, {
- 'jsonrpc': '2.0',
- 'method': 'foo',
- 'params': {},
- 'id': 1234
- },
+ expectErrorResponse(
+ controller,
+ {'jsonrpc': '2.0', 'method': 'foo', 'params': {}, 'id': 1234},
5,
'Error message.',
data: 'data value');
@@ -114,7 +106,9 @@
'code': error_code.PARSE_ERROR,
'message': startsWith("Invalid JSON: "),
// TODO(nweiz): Always expect the source when sdk#25655 is fixed.
- 'data': {'request': anyOf([isNull, 'invalid json {'])}
+ 'data': {
+ 'request': anyOf([isNull, 'invalid json {'])
+ }
},
'id': null
});
@@ -124,61 +118,60 @@
group("fallbacks", () {
test("calls a fallback if no method matches", () {
controller.server
- ..registerMethod('foo', () => 'foo')
- ..registerMethod('bar', () => 'foo')
- ..registerFallback((params) => {'fallback': params.value});
+ ..registerMethod('foo', () => 'foo')
+ ..registerMethod('bar', () => 'foo')
+ ..registerFallback((params) => {'fallback': params.value});
- expect(controller.handleRequest({
- 'jsonrpc': '2.0',
- 'method': 'baz',
- 'params': {'param': 'value'},
- 'id': 1234
- }), completion(equals({
- 'jsonrpc': '2.0',
- 'result': {'fallback': {'param': 'value'}},
- 'id': 1234
- })));
+ expect(
+ controller.handleRequest({
+ 'jsonrpc': '2.0',
+ 'method': 'baz',
+ 'params': {'param': 'value'},
+ 'id': 1234
+ }),
+ completion(equals({
+ 'jsonrpc': '2.0',
+ 'result': {
+ 'fallback': {'param': 'value'}
+ },
+ 'id': 1234
+ })));
});
test("calls the first matching fallback", () {
controller.server
- ..registerFallback((params) =>
- throw new json_rpc.RpcException.methodNotFound(params.method))
- ..registerFallback((params) => 'fallback 2')
- ..registerFallback((params) => 'fallback 3');
+ ..registerFallback((params) =>
+ throw new json_rpc.RpcException.methodNotFound(params.method))
+ ..registerFallback((params) => 'fallback 2')
+ ..registerFallback((params) => 'fallback 3');
- expect(controller.handleRequest({
- 'jsonrpc': '2.0',
- 'method': 'fallback 2',
- 'id': 1234
- }), completion(equals({
- 'jsonrpc': '2.0',
- 'result': 'fallback 2',
- 'id': 1234
- })));
+ expect(
+ controller.handleRequest(
+ {'jsonrpc': '2.0', 'method': 'fallback 2', 'id': 1234}),
+ completion(
+ equals({'jsonrpc': '2.0', 'result': 'fallback 2', 'id': 1234})));
});
test("an unexpected error in a fallback is captured", () {
- controller.server.registerFallback((_) =>
- throw new FormatException('bad format'));
+ controller.server
+ .registerFallback((_) => throw new FormatException('bad format'));
- expect(controller.handleRequest({
- 'jsonrpc': '2.0',
- 'method': 'foo',
- 'id': 1234
- }), completion({
- 'jsonrpc': '2.0',
- 'id': 1234,
- 'error': {
- 'code': error_code.SERVER_ERROR,
- 'message': 'bad format',
- 'data': {
- 'request': {'jsonrpc': '2.0', 'method': 'foo', 'id': 1234},
- 'full': 'FormatException: bad format',
- 'stack': new isInstanceOf<String>()
- }
- }
- }));
+ expect(
+ controller
+ .handleRequest({'jsonrpc': '2.0', 'method': 'foo', 'id': 1234}),
+ completion({
+ 'jsonrpc': '2.0',
+ 'id': 1234,
+ 'error': {
+ 'code': error_code.SERVER_ERROR,
+ 'message': 'bad format',
+ 'data': {
+ 'request': {'jsonrpc': '2.0', 'method': 'foo', 'id': 1234},
+ 'full': 'FormatException: bad format',
+ 'stack': new isInstanceOf<String>()
+ }
+ }
+ }));
});
});
diff --git a/test/server/stream_test.dart b/test/server/stream_test.dart
index bc320ed..19629e7 100644
--- a/test/server/stream_test.dart
+++ b/test/server/stream_test.dart
@@ -34,11 +34,15 @@
'id': 1234
});
- expect(responseController.stream.first, completion(equals({
- 'jsonrpc': '2.0',
- 'result': {'params': {'param': 'value'}},
- 'id': 1234
- })));
+ expect(
+ responseController.stream.first,
+ completion(equals({
+ 'jsonrpc': '2.0',
+ 'result': {
+ 'params': {'param': 'value'}
+ },
+ 'id': 1234
+ })));
});
test(".listen returns when the controller is closed", () {
diff --git a/test/server/utils.dart b/test/server/utils.dart
index f2345fc..ca2b277 100644
--- a/test/server/utils.dart
+++ b/test/server/utils.dart
@@ -44,21 +44,20 @@
/// Expects that [controller]'s server will return an error response to
/// [request] with the given [errorCode], [message], and [data].
-void expectErrorResponse(ServerController controller, request, int errorCode,
- String message, {data}) {
+void expectErrorResponse(
+ ServerController controller, request, int errorCode, String message,
+ {data}) {
var id;
if (request is Map) id = request['id'];
if (data == null) data = {'request': request};
- expect(controller.handleRequest(request), completion(equals({
- 'jsonrpc': '2.0',
- 'id': id,
- 'error': {
- 'code': errorCode,
- 'message': message,
- 'data': data
- }
- })));
+ expect(
+ controller.handleRequest(request),
+ completion(equals({
+ 'jsonrpc': '2.0',
+ 'id': id,
+ 'error': {'code': errorCode, 'message': message, 'data': data}
+ })));
}
/// Returns a matcher that matches a [json_rpc.RpcException] with an