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

Unified Diff: test/codegen/language/no_such_method_mock_test.dart

Issue 2158173003: fix #603, support mock objects (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 4 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: 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);
+}

Powered by Google App Engine
This is Rietveld 408576698