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

Unified Diff: tests/language_strong/no_such_method_mock_test.dart

Issue 2975273002: fix #30108, mock support for callable classes (Closed)
Patch Set: Created 3 years, 5 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
Index: tests/language_strong/no_such_method_mock_test.dart
diff --git a/tests/language_strong/no_such_method_mock_test.dart b/tests/language_strong/no_such_method_mock_test.dart
index ec84d8c03a31af8039cd492e3a796a5e4b57e5d0..a861e179e4c0853fd1f47190b9ba9d1e83b28d5a 100644
--- a/tests/language_strong/no_such_method_mock_test.dart
+++ b/tests/language_strong/no_such_method_mock_test.dart
@@ -51,6 +51,15 @@ class MockWithGetterSetter {
}
}
+class Callable {
+ int call() => 1;
+ int m() => 2;
+}
+
+class MockCallable implements Callable {
+ noSuchMethod(i) => i.memberName == #call ? 42 : 0;
+}
+
void main() {
MockCat mock = new MockCat();
Expect.isTrue((mock as dynamic).eatFood("cat food"));
@@ -73,7 +82,9 @@ void main() {
var g = new MockWithGenerics();
Expect.equals(g.doStuff(42), 142);
- Expect.throws(() => g.doStuff('hi'));
+ Expect.throws(() {
+ g.doStuff('hi');
+ });
var s = new MockWithGetterSetter();
s.getter;
@@ -86,4 +97,10 @@ void main() {
Expect.equals(s.invocation.isGetter, false);
Expect.equals(s.invocation.isSetter, true);
Expect.equals(s.invocation.isMethod, false);
+
+ Callable call = new MockCallable();
+ Expect.equals(call(), 42);
+ Expect.equals((call as dynamic)(), 42);
+ Expect.equals(call.m(), 0);
+ Expect.equals((call as dynamic).m(), 0);
}

Powered by Google App Engine
This is Rietveld 408576698