OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 library test.protocol; | |
6 | |
7 import '../lib/src/protocol.dart'; | |
devoncarew
2014/01/20 22:35:01
Can use a self-reference, or not.
nit: I generall
Brian Wilkerson
2014/01/21 03:21:20
Done.
| |
8 | |
9 import 'package:unittest/matcher.dart'; | |
10 import 'package:unittest/unittest.dart'; | |
11 | |
12 main() { | |
13 group('Request', () { | |
14 test('getParameter_defined', RequestTest.getParameter_defined); | |
15 test('getParameter_undefined', RequestTest.getParameter_undefined); | |
16 test('getRequiredParameter_defined', RequestTest.getRequiredParameter_define d); | |
17 test('getRequiredParameter_undefined', RequestTest.getRequiredParameter_unde fined); | |
18 }); | |
19 group('Response', () { | |
20 test('create_contextDoesNotExist', ResponseTest.create_contextDoesNotExist); | |
21 test('create_invalidRequestFormat', ResponseTest.create_invalidRequestFormat ); | |
22 test('create_missingRequiredParameter', ResponseTest.create_missingRequiredP arameter); | |
23 test('create_unknownRequest', ResponseTest.create_unknownRequest); | |
24 test('setResult', ResponseTest.setResult); | |
25 }); | |
26 } | |
27 | |
28 class RequestTest { | |
29 static void getParameter_defined() { | |
30 String name = 'name'; | |
31 String value = 'value'; | |
32 Request request = new Request('0', ''); | |
33 request.setParameter(name, value); | |
34 expect(request.getParameter(name), equals(value)); | |
35 } | |
36 | |
37 static void getParameter_undefined() { | |
38 String name = 'name'; | |
39 Request request = new Request('0', ''); | |
40 expect(request.getParameter(name), isNull); | |
41 } | |
42 | |
43 static void getRequiredParameter_defined() { | |
44 String name = 'name'; | |
45 String value = 'value'; | |
46 Request request = new Request('0', ''); | |
47 request.setParameter(name, value); | |
48 expect(request.getRequiredParameter(name), equals(value)); | |
49 } | |
50 | |
51 static void getRequiredParameter_undefined() { | |
52 String name = 'name'; | |
53 Request request = new Request('0', ''); | |
54 expect(() => request.getRequiredParameter(name), throwsA(new isInstanceOf<Re questFailure>())); | |
55 } | |
56 } | |
57 | |
58 class ResponseTest { | |
59 static void create_contextDoesNotExist() { | |
60 Response response = new Response.contextDoesNotExist(new Request('0', '')); | |
61 expect(response.id, equals('0')); | |
62 expect(response.error, isNotNull); | |
63 expect(response.toJson(), equals({ | |
64 Response.ID: '0', | |
65 Response.ERROR: 'Context does not exist' | |
66 })); | |
67 } | |
68 | |
69 static void create_invalidRequestFormat() { | |
70 Response response = new Response.invalidRequestFormat(); | |
71 expect(response.id, equals('')); | |
72 expect(response.error, isNotNull); | |
73 expect(response.toJson(), equals({ | |
74 Response.ID: '', | |
75 Response.ERROR: 'Invalid request' | |
76 })); | |
77 } | |
78 | |
79 static void create_missingRequiredParameter() { | |
80 Response response = new Response.missingRequiredParameter(new Request('0', ' '), 'x'); | |
81 expect(response.id, equals('0')); | |
82 expect(response.error, isNotNull); | |
83 expect(response.toJson(), equals({ | |
84 Response.ID: '0', | |
85 Response.ERROR: 'Missing required parameter: x' | |
86 })); | |
87 } | |
88 | |
89 static void create_unknownRequest() { | |
90 Response response = new Response.unknownRequest(new Request('0', '')); | |
91 expect(response.id, equals('0')); | |
92 expect(response.error, isNotNull); | |
93 expect(response.toJson(), equals({ | |
94 Response.ID: '0', | |
95 Response.ERROR: 'Unknown request' | |
96 })); | |
97 } | |
98 | |
99 static void setResult() { | |
100 String resultName = 'name'; | |
101 String resultValue = 'value'; | |
102 Response response = new Response('0'); | |
103 response.setResult(resultName, resultValue); | |
104 expect(response.toJson(), equals({ | |
105 Response.ID: '0', | |
106 Response.ERROR: null, | |
107 Response.RESULT: { | |
108 resultName: resultValue | |
109 } | |
110 })); | |
111 } | |
112 } | |
OLD | NEW |