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

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

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