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

Side by Side Diff: pkg/unittest/test/mock_test.dart

Issue 11770004: Rename Date to DateTime. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments and keep Backwards-compatibility class Date. Created 7 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « pkg/unittest/lib/src/test_case.dart ('k') | runtime/bin/secure_socket.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library mock_test; 5 library mock_test;
6 import 'package:unittest/unittest.dart'; 6 import 'package:unittest/unittest.dart';
7 import 'package:unittest/mock.dart'; 7 import 'package:unittest/mock.dart';
8 8
9 class MockList extends Mock implements List { 9 class MockList extends Mock implements List {
10 } 10 }
11 11
12 class Foo { 12 class Foo {
13 sum(a, b, c) => a + b + c; 13 sum(a, b, c) => a + b + c;
14 } 14 }
15 15
16 class FooSpy extends Mock implements Foo { 16 class FooSpy extends Mock implements Foo {
17 Foo real; 17 Foo real;
18 FooSpy() { 18 FooSpy() {
19 real = new Foo(); 19 real = new Foo();
20 this.when(callsTo('sum')).alwaysCall(real.sum); 20 this.when(callsTo('sum')).alwaysCall(real.sum);
21 } 21 }
22 } 22 }
23 23
24 makeTestLogEntry(String methodName, List args, int time, 24 makeTestLogEntry(String methodName, List args, int time,
25 [String mockName]) { 25 [String mockName]) {
26 LogEntry e = new LogEntry(mockName, methodName, args, Action.IGNORE); 26 LogEntry e = new LogEntry(mockName, methodName, args, Action.IGNORE);
27 e.time = new Date.fromMillisecondsSinceEpoch(time, isUtc: true); 27 e.time = new DateTime.fromMillisecondsSinceEpoch(time, isUtc: true);
28 return e; 28 return e;
29 } 29 }
30 30
31 makeTestLog() { 31 makeTestLog() {
32 LogEntryList logList = new LogEntryList('test'); 32 LogEntryList logList = new LogEntryList('test');
33 List args = new List(); 33 List args = new List();
34 logList.add(makeTestLogEntry('a', args, 1000)); 34 logList.add(makeTestLogEntry('a', args, 1000));
35 logList.add(makeTestLogEntry('b', args, 2000)); 35 logList.add(makeTestLogEntry('b', args, 2000));
36 logList.add(makeTestLogEntry('c', args, 3000)); 36 logList.add(makeTestLogEntry('c', args, 3000));
37 return logList; 37 return logList;
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 // No restriction on entry. 213 // No restriction on entry.
214 expect(logList.findLogEntry(null, 0), 0); 214 expect(logList.findLogEntry(null, 0), 0);
215 expect(logList.findLogEntry(null, 1), 1); 215 expect(logList.findLogEntry(null, 1), 1);
216 expect(logList.findLogEntry(null, 2), 2); 216 expect(logList.findLogEntry(null, 2), 2);
217 expect(logList.findLogEntry(null, 3), -1); 217 expect(logList.findLogEntry(null, 3), -1);
218 }); 218 });
219 219
220 test('Mocking: from,after,before,until', () { 220 test('Mocking: from,after,before,until', () {
221 LogEntryList logList = makeTestLog(); 221 LogEntryList logList = makeTestLog();
222 LogEntryList log2; 222 LogEntryList log2;
223 Date t0 = new Date.fromMillisecondsSinceEpoch(0, isUtc: true); 223 DateTime t0 = new DateTime.fromMillisecondsSinceEpoch(0, isUtc: true);
224 Date t1000 = new Date.fromMillisecondsSinceEpoch(1000, isUtc: true); 224 DateTime t1000 = new DateTime.fromMillisecondsSinceEpoch(1000, isUtc: true);
225 Date t2000 = new Date.fromMillisecondsSinceEpoch(2000, isUtc: true); 225 DateTime t2000 = new DateTime.fromMillisecondsSinceEpoch(2000, isUtc: true);
226 Date t3000 = new Date.fromMillisecondsSinceEpoch(3000, isUtc: true); 226 DateTime t3000 = new DateTime.fromMillisecondsSinceEpoch(3000, isUtc: true);
227 Date t4000 = new Date.fromMillisecondsSinceEpoch(4000, isUtc: true); 227 DateTime t4000 = new DateTime.fromMillisecondsSinceEpoch(4000, isUtc: true);
228 228
229 log2 = logList.before(t0); 229 log2 = logList.before(t0);
230 expect(log2.logs, hasLength(0)); 230 expect(log2.logs, hasLength(0));
231 expect(log2.filter, 'test before 1970-01-01 00:00:00.000Z'); 231 expect(log2.filter, 'test before 1970-01-01 00:00:00.000Z');
232 log2 = logList.until(t0); 232 log2 = logList.until(t0);
233 expect(log2.logs, hasLength(0)); 233 expect(log2.logs, hasLength(0));
234 expect(log2.filter, 'test until 1970-01-01 00:00:00.000Z'); 234 expect(log2.filter, 'test until 1970-01-01 00:00:00.000Z');
235 log2 = logList.from(t0); 235 log2 = logList.from(t0);
236 expect(log2.logs, hasLength(3)); 236 expect(log2.logs, hasLength(3));
237 expect(log2.first.methodName, 'a'); 237 expect(log2.first.methodName, 'a');
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 expect(log2.logs, hasLength(3)); 299 expect(log2.logs, hasLength(3));
300 expect(log2.first.methodName, 'a'); 300 expect(log2.first.methodName, 'a');
301 expect(log2.last.methodName, 'c'); 301 expect(log2.last.methodName, 'c');
302 log2 = logList.from(t4000); 302 log2 = logList.from(t4000);
303 expect(log2.logs, hasLength(0)); 303 expect(log2.logs, hasLength(0));
304 log2 = logList.after(t4000); 304 log2 = logList.after(t4000);
305 expect(log2.logs, hasLength(0)); 305 expect(log2.logs, hasLength(0));
306 }); 306 });
307 307
308 test('Mocking: inplace from,after,before,until', () { 308 test('Mocking: inplace from,after,before,until', () {
309 Date t0 = new Date.fromMillisecondsSinceEpoch(0, isUtc: true); 309 DateTime t0 = new DateTime.fromMillisecondsSinceEpoch(0, isUtc: true);
310 Date t1000 = new Date.fromMillisecondsSinceEpoch(1000, isUtc: true); 310 DateTime t1000 = new DateTime.fromMillisecondsSinceEpoch(1000, isUtc: true);
311 Date t2000 = new Date.fromMillisecondsSinceEpoch(2000, isUtc: true); 311 DateTime t2000 = new DateTime.fromMillisecondsSinceEpoch(2000, isUtc: true);
312 Date t3000 = new Date.fromMillisecondsSinceEpoch(3000, isUtc: true); 312 DateTime t3000 = new DateTime.fromMillisecondsSinceEpoch(3000, isUtc: true);
313 Date t4000 = new Date.fromMillisecondsSinceEpoch(4000, isUtc: true); 313 DateTime t4000 = new DateTime.fromMillisecondsSinceEpoch(4000, isUtc: true);
314 314
315 LogEntryList logList = makeTestLog().before(t0, true); 315 LogEntryList logList = makeTestLog().before(t0, true);
316 expect(logList.logs, hasLength(0)); 316 expect(logList.logs, hasLength(0));
317 expect(logList.filter, 'test before 1970-01-01 00:00:00.000Z'); 317 expect(logList.filter, 'test before 1970-01-01 00:00:00.000Z');
318 logList = makeTestLog().until(t0, true); 318 logList = makeTestLog().until(t0, true);
319 expect(logList.logs, hasLength(0)); 319 expect(logList.logs, hasLength(0));
320 expect(logList.filter, 'test until 1970-01-01 00:00:00.000Z'); 320 expect(logList.filter, 'test until 1970-01-01 00:00:00.000Z');
321 logList = makeTestLog().from(t0, true); 321 logList = makeTestLog().from(t0, true);
322 expect(logList.logs, hasLength(3)); 322 expect(logList.logs, hasLength(3));
323 expect(logList.first.methodName, 'a'); 323 expect(logList.first.methodName, 'a');
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 expect(log.logs, hasLength(6)); 628 expect(log.logs, hasLength(6));
629 expect(log.logs.every((e) => e.mockName == 'm2' || e.mockName == 'm3'), 629 expect(log.logs.every((e) => e.mockName == 'm2' || e.mockName == 'm3'),
630 isTrue); 630 isTrue);
631 m2.clearLogs(); 631 m2.clearLogs();
632 expect(log.logs, hasLength(3)); 632 expect(log.logs, hasLength(3));
633 expect(log.logs.every((e) => e.mockName =='m3'), isTrue); 633 expect(log.logs.every((e) => e.mockName =='m3'), isTrue);
634 m3.clearLogs(); 634 m3.clearLogs();
635 expect(log.logs, hasLength(0)); 635 expect(log.logs, hasLength(0));
636 }); 636 });
637 } 637 }
OLDNEW
« no previous file with comments | « pkg/unittest/lib/src/test_case.dart ('k') | runtime/bin/secure_socket.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698