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

Unified Diff: tests/lib/unittest/unittest_test.dart

Issue 10718002: Changed the syntax some. All the handling of variable argument lists is (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 6 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 side-by-side diff with in-line comments
Download patch
« lib/unittest/mock.dart ('K') | « lib/unittest/mock.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/lib/unittest/unittest_test.dart
===================================================================
--- tests/lib/unittest/unittest_test.dart (revision 9180)
+++ tests/lib/unittest/unittest_test.dart (working copy)
@@ -72,6 +72,21 @@
}
}
+class MockList extends Mock implements List {
+}
+
+class Foo {
+ bar(a, b, c) => a + b + c;
+}
+
+class FooSpy extends Mock implements Foo {
+ FooSpy real;
+ FooSpy() {
+ real = new Foo();
+ this.whenThereAre(callsTo('bar')).alwaysCall(real.bar);
+ }
+}
+
runTest() {
port.receive((testName, sendport) {
configure(_testconfig = new TestConfiguration(sendport));
@@ -124,6 +139,53 @@
() => (_testconfig.count == 10));
_defer(_callback);
});
+ } else if (testName == 'mock test 1 (Mock)') {
+ test(testName, () {
+ var m = new Mock();
+
+ m.whenThereAre(callsTo('Sum', 1, 2)).thenReturn('A').thenReturn('B');
Siggi Cherem (dart-lang) 2012/06/28 00:44:40 I'm playing around with other ideas to see if ther
+ m.whenThereAre(callsTo('Sum', 1, 1)).thenReturn('C');
+ m.whenThereAre(callsTo('Sum', anything, anything)).thenReturn('D');
+ m.whenThereAre(callsTo('Sub', anything, anything)).thenReturn('E');
Siggi Cherem (dart-lang) 2012/06/28 00:44:40 could we change the example to use lowercase metho
gram 2012/06/28 17:32:54 Done, and I changed the names to foo/bar which is
+
+ var s = '${m.Sum(1,2)}${m.Sum(1,1)}${m.Sum(9,10)}'
+ '${m.Sub(1,1)}${m.Sum(1,2)}';
+ m.forThe(callsTo('Sum', anything, anything)).verify(calledExactly(4));
Siggi Cherem (dart-lang) 2012/06/28 00:44:40 Ideas instead of 'm.forThe(_).verify(_)' - m.verif
+ m.forThe(callsTo('Sum', 1, anything)).verify(calledExactly(3));
+ m.forThe(callsTo('Sum', 9, anything)).verify(calledOnce);
+ m.forThe(callsTo('Sum', anything, 2)).verify(calledExactly(2));
+ expect(s, 'ACDEB');
+ });
+ } else if (testName == 'mock test 2 (MockList)') {
+ test(testName, () {
+ MockList l = new MockList();
+ l.whenThereAre(callsTo('length')).thenReturn(1);
+ l.whenThereAre(callsTo('add', anything)).alwaysReturn(0);
+ l.add('foo');
+ expect(l.length(), 1);
+
+ List m = new MockList();
+ m.whenThereAre(callsTo('add', anything)).alwaysReturn(0);
+
+ m.add('foo');
+ m.add('bar');
+
+ m.forThe(callsTo('add')).verify(calledExactly(2));
+ m.forThe(callsTo('add', 'foo')).verify(calledOnce);
+ });
+ } else if (testName == 'mock test 3 (Spy)') {
+ test(testName, () {
+ var p = new FooSpy();
+ p.bar(1, 2, 3);
+ p.forThe(callsTo('bar')).verify(calledOnce);
+ p.bar(2, 2, 2);
+ p.forThe(callsTo('bar')).verify(calledExactly(2));
+ p.forThe(callsTo('bar')).verify(sometimeReturned(6));
+ p.forThe(callsTo('bar')).verify(alwaysReturned(6));
+ p.forThe(callsTo('bar')).verify(neverReturned(5));
+ p.bar(2, 2, 1);
+ p.forThe(callsTo('bar')).verify(sometimeReturned(5));
+ });
}
});
}
@@ -153,7 +215,10 @@
'setup and teardown test',
'correct callback test',
'excess callback test',
- 'completion test'
+ 'completion test',
+ 'mock test 1 (Mock)',
+ 'mock test 2 (MockList)',
+ 'mock test 3 (Spy)'
];
expected = [
@@ -168,7 +233,10 @@
buildStatusString(1, 0, 0, tests[7], 1),
buildStatusString(0, 0, 1, tests[8], 1,
message: 'Callback called more times than expected (2 > 1)'),
- buildStatusString(1, 0, 0, tests[9], 10)
+ buildStatusString(1, 0, 0, tests[9], 10),
+ buildStatusString(1, 0, 0, tests[10]),
+ buildStatusString(1, 0, 0, tests[11]),
+ buildStatusString(1, 0, 0, tests[12])
];
actual = [];
« lib/unittest/mock.dart ('K') | « lib/unittest/mock.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698