OLD | NEW |
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('unittestTest'); | 5 #library('unittestTest'); |
6 #import('../../../pkg/unittest/unittest.dart'); | 6 #import('../../../pkg/unittest/unittest.dart'); |
7 | 7 |
8 class MockList extends Mock implements List { | 8 class MockList extends Mock implements List { |
9 } | 9 } |
10 | 10 |
11 class Foo { | 11 class Foo { |
12 sum(a, b, c) => a + b + c; | 12 sum(a, b, c) => a + b + c; |
13 } | 13 } |
14 | 14 |
15 class FooSpy extends Mock implements Foo { | 15 class FooSpy extends Mock implements Foo { |
16 Foo real; | 16 Foo real; |
17 FooSpy() { | 17 FooSpy() { |
18 real = new Foo(); | 18 real = new Foo(); |
19 this.when(callsTo('sum')).alwaysCall(real.sum); | 19 this.when(callsTo('sum')).alwaysCall(real.sum); |
20 } | 20 } |
21 } | 21 } |
22 | 22 |
23 makeTestLogEntry(String methodName, List args, int time, | 23 makeTestLogEntry(String methodName, List args, int time, |
24 [String mockName]) { | 24 [String mockName]) { |
25 LogEntry e = new LogEntry(mockName, methodName, args, Action.IGNORE); | 25 LogEntry e = new LogEntry(mockName, methodName, args, Action.IGNORE); |
26 e.time = new Date.fromMillisecondsSinceEpoch(time, true); | 26 e.time = new Date.fromMillisecondsSinceEpoch(time, isUtc: true); |
27 return e; | 27 return e; |
28 } | 28 } |
29 | 29 |
30 makeTestLog() { | 30 makeTestLog() { |
31 LogEntryList logList = new LogEntryList('test'); | 31 LogEntryList logList = new LogEntryList('test'); |
32 List args = new List(); | 32 List args = new List(); |
33 logList.add(makeTestLogEntry('a', args, 1000)); | 33 logList.add(makeTestLogEntry('a', args, 1000)); |
34 logList.add(makeTestLogEntry('b', args, 2000)); | 34 logList.add(makeTestLogEntry('b', args, 2000)); |
35 logList.add(makeTestLogEntry('c', args, 3000)); | 35 logList.add(makeTestLogEntry('c', args, 3000)); |
36 return logList; | 36 return logList; |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 // No restriction on entry. | 212 // No restriction on entry. |
213 expect(logList.findLogEntry(null, 0), 0); | 213 expect(logList.findLogEntry(null, 0), 0); |
214 expect(logList.findLogEntry(null, 1), 1); | 214 expect(logList.findLogEntry(null, 1), 1); |
215 expect(logList.findLogEntry(null, 2), 2); | 215 expect(logList.findLogEntry(null, 2), 2); |
216 expect(logList.findLogEntry(null, 3), -1); | 216 expect(logList.findLogEntry(null, 3), -1); |
217 }); | 217 }); |
218 | 218 |
219 test('Mocking: from,after,before,until', () { | 219 test('Mocking: from,after,before,until', () { |
220 LogEntryList logList = makeTestLog(); | 220 LogEntryList logList = makeTestLog(); |
221 LogEntryList log2; | 221 LogEntryList log2; |
222 Date t0 = new Date.fromMillisecondsSinceEpoch(0, true); | 222 Date t0 = new Date.fromMillisecondsSinceEpoch(0, isUtc: true); |
223 Date t1000 = new Date.fromMillisecondsSinceEpoch(1000, true); | 223 Date t1000 = new Date.fromMillisecondsSinceEpoch(1000, isUtc: true); |
224 Date t2000 = new Date.fromMillisecondsSinceEpoch(2000, true); | 224 Date t2000 = new Date.fromMillisecondsSinceEpoch(2000, isUtc: true); |
225 Date t3000 = new Date.fromMillisecondsSinceEpoch(3000, true); | 225 Date t3000 = new Date.fromMillisecondsSinceEpoch(3000, isUtc: true); |
226 Date t4000 = new Date.fromMillisecondsSinceEpoch(4000, true); | 226 Date t4000 = new Date.fromMillisecondsSinceEpoch(4000, isUtc: true); |
227 | 227 |
228 log2 = logList.before(t0); | 228 log2 = logList.before(t0); |
229 expect(log2.logs, hasLength(0)); | 229 expect(log2.logs, hasLength(0)); |
230 expect(log2.filter, 'test before 1970-01-01 00:00:00.000Z'); | 230 expect(log2.filter, 'test before 1970-01-01 00:00:00.000Z'); |
231 log2 = logList.until(t0); | 231 log2 = logList.until(t0); |
232 expect(log2.logs, hasLength(0)); | 232 expect(log2.logs, hasLength(0)); |
233 expect(log2.filter, 'test until 1970-01-01 00:00:00.000Z'); | 233 expect(log2.filter, 'test until 1970-01-01 00:00:00.000Z'); |
234 log2 = logList.from(t0); | 234 log2 = logList.from(t0); |
235 expect(log2.logs, hasLength(3)); | 235 expect(log2.logs, hasLength(3)); |
236 expect(log2.first.methodName, 'a'); | 236 expect(log2.first.methodName, 'a'); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 expect(log2.logs, hasLength(3)); | 298 expect(log2.logs, hasLength(3)); |
299 expect(log2.first.methodName, 'a'); | 299 expect(log2.first.methodName, 'a'); |
300 expect(log2.last.methodName, 'c'); | 300 expect(log2.last.methodName, 'c'); |
301 log2 = logList.from(t4000); | 301 log2 = logList.from(t4000); |
302 expect(log2.logs, hasLength(0)); | 302 expect(log2.logs, hasLength(0)); |
303 log2 = logList.after(t4000); | 303 log2 = logList.after(t4000); |
304 expect(log2.logs, hasLength(0)); | 304 expect(log2.logs, hasLength(0)); |
305 }); | 305 }); |
306 | 306 |
307 test('Mocking: inplace from,after,before,until', () { | 307 test('Mocking: inplace from,after,before,until', () { |
308 Date t0 = new Date.fromMillisecondsSinceEpoch(0, true); | 308 Date t0 = new Date.fromMillisecondsSinceEpoch(0, isUtc: true); |
309 Date t1000 = new Date.fromMillisecondsSinceEpoch(1000, true); | 309 Date t1000 = new Date.fromMillisecondsSinceEpoch(1000, isUtc: true); |
310 Date t2000 = new Date.fromMillisecondsSinceEpoch(2000, true); | 310 Date t2000 = new Date.fromMillisecondsSinceEpoch(2000, isUtc: true); |
311 Date t3000 = new Date.fromMillisecondsSinceEpoch(3000, true); | 311 Date t3000 = new Date.fromMillisecondsSinceEpoch(3000, isUtc: true); |
312 Date t4000 = new Date.fromMillisecondsSinceEpoch(4000, true); | 312 Date t4000 = new Date.fromMillisecondsSinceEpoch(4000, isUtc: true); |
313 | 313 |
314 LogEntryList logList = makeTestLog().before(t0, true); | 314 LogEntryList logList = makeTestLog().before(t0, true); |
315 expect(logList.logs, hasLength(0)); | 315 expect(logList.logs, hasLength(0)); |
316 expect(logList.filter, 'test before 1970-01-01 00:00:00.000Z'); | 316 expect(logList.filter, 'test before 1970-01-01 00:00:00.000Z'); |
317 logList = makeTestLog().until(t0, true); | 317 logList = makeTestLog().until(t0, true); |
318 expect(logList.logs, hasLength(0)); | 318 expect(logList.logs, hasLength(0)); |
319 expect(logList.filter, 'test until 1970-01-01 00:00:00.000Z'); | 319 expect(logList.filter, 'test until 1970-01-01 00:00:00.000Z'); |
320 logList = makeTestLog().from(t0, true); | 320 logList = makeTestLog().from(t0, true); |
321 expect(logList.logs, hasLength(3)); | 321 expect(logList.logs, hasLength(3)); |
322 expect(logList.first.methodName, 'a'); | 322 expect(logList.first.methodName, 'a'); |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 expect(log.logs, hasLength(6)); | 627 expect(log.logs, hasLength(6)); |
628 expect(log.logs.every((e) => e.mockName == 'm2' || e.mockName == 'm3'), | 628 expect(log.logs.every((e) => e.mockName == 'm2' || e.mockName == 'm3'), |
629 isTrue); | 629 isTrue); |
630 m2.clearLogs(); | 630 m2.clearLogs(); |
631 expect(log.logs, hasLength(3)); | 631 expect(log.logs, hasLength(3)); |
632 expect(log.logs.every((e) => e.mockName =='m3'), isTrue); | 632 expect(log.logs.every((e) => e.mockName =='m3'), isTrue); |
633 m3.clearLogs(); | 633 m3.clearLogs(); |
634 expect(log.logs, hasLength(0)); | 634 expect(log.logs, hasLength(0)); |
635 }); | 635 }); |
636 } | 636 } |
OLD | NEW |