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

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

Issue 11638049: Convert unittest to use "package:" imports. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years 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
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 '../../../pkg/unittest/lib/unittest.dart'; 6 import 'package:unittest/unittest.dart';
7 import '../../../pkg/unittest/lib/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;
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 expect(m.bar(1), 2); 160 expect(m.bar(1), 2);
161 expect(m.bar(2), 4); 161 expect(m.bar(2), 4);
162 m.getLogs(callsTo()).verify(happenedExactly(4)); 162 m.getLogs(callsTo()).verify(happenedExactly(4));
163 m.getLogs(callsTo(null, 1)).verify(happenedExactly(2)); 163 m.getLogs(callsTo(null, 1)).verify(happenedExactly(2));
164 m.getLogs(callsTo(null, 2)).verify(happenedExactly(2)); 164 m.getLogs(callsTo(null, 2)).verify(happenedExactly(2));
165 m.getLogs(null, returning(1)).verify(neverHappened); 165 m.getLogs(null, returning(1)).verify(neverHappened);
166 m.getLogs(null, returning(2)).verify(happenedExactly(2)); 166 m.getLogs(null, returning(2)).verify(happenedExactly(2));
167 m.getLogs(null, returning(4)).verify(happenedExactly(2)); 167 m.getLogs(null, returning(4)).verify(happenedExactly(2));
168 }); 168 });
169 169
170 test('Mocking: RegExp CallMatcher good', () {» 170 test('Mocking: RegExp CallMatcher good', () {
171 var m = new Mock();» 171 var m = new Mock();
172 m.when(callsTo(matches('^[A-Z]'))).» 172 m.when(callsTo(matches('^[A-Z]'))).
173 alwaysThrow('Method names must start with lower case.');» 173 alwaysThrow('Method names must start with lower case.');
174 m.test();» 174 m.test();
175 }); 175 });
176 176
177 test('Mocking: No logging', () { 177 test('Mocking: No logging', () {
178 var m = new Mock.custom(enableLogging:false); 178 var m = new Mock.custom(enableLogging:false);
179 m.Test(); 179 m.Test();
180 expect(() => m.getLogs(callsTo('Test')), throwsA((e) => e.toString() == 180 expect(() => m.getLogs(callsTo('Test')), throwsA((e) => e.toString() ==
181 "Exception: Can't retrieve logs when logging was never enabled.")); 181 "Exception: Can't retrieve logs when logging was never enabled."));
182 }); 182 });
183 183
184 test('Mocking: Find logList entry', () { 184 test('Mocking: Find logList entry', () {
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 for (var i = 0; i < 10; i++) { 594 for (var i = 0; i < 10; i++) {
595 LogEntry e = new LogEntry(null, 'foo', [i], Action.IGNORE); 595 LogEntry e = new LogEntry(null, 'foo', [i], Action.IGNORE);
596 logList.add(e); 596 logList.add(e);
597 } 597 }
598 int total = 0; 598 int total = 0;
599 logList.stepwiseValidate((log, pos) { 599 logList.stepwiseValidate((log, pos) {
600 total += log[pos].args[0] * log[pos + 1].args[0]; 600 total += log[pos].args[0] * log[pos + 1].args[0];
601 expect(log[pos + 1].args[0] - log[pos].args[0], equals(1)); 601 expect(log[pos + 1].args[0] - log[pos].args[0], equals(1));
602 return 2; 602 return 2;
603 }); 603 });
604 expect(total, equals((0 * 1) + (2 * 3) + (4 * 5) + (6 * 7) + (8 * 9))); 604 expect(total, equals((0 * 1) + (2 * 3) + (4 * 5) + (6 * 7) + (8 * 9)));
605 }); 605 });
606 606
607 test('Mocking: clearLogs', () { 607 test('Mocking: clearLogs', () {
608 var m = new Mock(); 608 var m = new Mock();
609 m.foo(); 609 m.foo();
610 m.foo(); 610 m.foo();
611 m.foo(); 611 m.foo();
612 expect(m.log.logs, hasLength(3)); 612 expect(m.log.logs, hasLength(3));
613 m.clearLogs(); 613 m.clearLogs();
614 expect(m.log.logs, hasLength(0)); 614 expect(m.log.logs, hasLength(0));
(...skipping 13 matching lines...) Expand all
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/test/mock_stepwise_negative_test.dart ('k') | pkg/unittest/test/unittest_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698