Index: test/codegen/language/no_such_method_mock_test.dart |
diff --git a/test/codegen/language/no_such_method_mock_test.dart b/test/codegen/language/no_such_method_mock_test.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f73d4818fdb7afaf01c1887975dc64da08e87bf6 |
--- /dev/null |
+++ b/test/codegen/language/no_such_method_mock_test.dart |
@@ -0,0 +1,27 @@ |
+// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
+// for details. All rights reserved. Use of this source code is governed by a |
+// BSD-style license that can be found in the LICENSE file. |
+// Dart test program testing that NoSuchMethod is properly called. |
+ |
+import "package:expect/expect.dart"; |
+ |
+class Cat { |
+ bool eatFood(String food) => true; |
+ int scratch(String furniture) => 100; |
+} |
+ |
+class MockCat implements Cat { |
+ dynamic noSuchMethod(Invocation invocation) { |
+ return (invocation.positionalArguments[0] as String).isNotEmpty; |
+ } |
+} |
+ |
+void main() { |
+ MockCat mock = new MockCat(); |
+ Expect.isTrue((mock as dynamic).eatFood("food")); |
+ Expect.isFalse(mock.eatFood("")); |
+ |
+ // In strong mode this will be a runtime type error: |
+ // bool is not an int. VM will fail with noSuchMethod +. |
+ Expect.throws(() => mock.scratch("couch") + 0); |
+} |