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

Unified Diff: tests/language_strong/mock_writable_final_field_test.dart

Issue 2803673007: fix #29233, final fields can be settable in a mock (Closed)
Patch Set: fix Created 3 years, 8 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/mock_writable_final_field_test.dart
diff --git a/tests/language_strong/mock_writable_final_field_test.dart b/tests/language_strong/mock_writable_final_field_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..b5c1ff176a6714099cbbc3f95484a219707d1d9b
--- /dev/null
+++ b/tests/language_strong/mock_writable_final_field_test.dart
@@ -0,0 +1,40 @@
+// Copyright (c) 2017, 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.
+
+import 'package:expect/expect.dart';
+
+final values = <int>[];
+
+class Mock {
+ noSuchMethod(Invocation i) {
+ Expect.equals(i.memberName.toString(), 'Symbol("_x")');
+ values.add(i.positionalArguments[0]);
+ }
+}
+
+class Foo {
+ int _x;
+}
+
+class Bar extends Mock implements Foo {
+ final int _x = 42;
+}
+
+void main() {
+ {
+ Bar b = new Bar();
+ Expect.equals(b._x, 42);
+ b._x = 123;
+ Expect.listEquals(values, [123]);
+ values.clear();
+ }
+ {
+ // It works the same if called statically through the Foo interface.
+ Foo b = new Bar();
+ Expect.equals(b._x, 42);
+ b._x = 123;
+ Expect.listEquals(values, [123]);
+ values.clear();
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698