Index: runtime/observatory/lib/src/mocks/repositories/target.dart |
diff --git a/runtime/observatory/lib/src/mocks/repositories/target.dart b/runtime/observatory/lib/src/mocks/repositories/target.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8321f8612e7333a2ca177378c2bea58ae94190f0 |
--- /dev/null |
+++ b/runtime/observatory/lib/src/mocks/repositories/target.dart |
@@ -0,0 +1,72 @@ |
+// Copyright (c) 2016, 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 |
+ |
+part of mocks; |
+ |
+class TargetChangeEventMock implements M.TargetChangeEvent { |
+ final TargetRepositoryMock repository; |
+ const TargetChangeEventMock({this.repository}); |
+} |
+ |
+typedef void TargetRepositoryMockStringCallback(String notification); |
+typedef void TargetRepositoryMockTargetCallback(M.Target notification); |
+ |
+class TargetRepositoryMock implements M.TargetRepository { |
+ final StreamController<M.TargetChangeEvent> _onChange = |
+ new StreamController<M.TargetChangeEvent>.broadcast(); |
+ Stream<M.TargetChangeEvent> get onChange => _onChange.stream; |
+ |
+ bool get hasListeners => _onChange.hasListener; |
+ |
+ final M.Target _current; |
+ final Iterable<M.Target> _list; |
+ final TargetRepositoryMockStringCallback _add; |
+ final TargetRepositoryMockTargetCallback _setCurrent; |
+ final TargetRepositoryMockTargetCallback _delete; |
+ |
+ bool currentInvoked = false; |
+ bool addInvoked = false; |
+ bool listInvoked = false; |
+ bool setCurrentInvoked = false; |
+ bool deleteInvoked = false; |
+ |
+ M.Target get current { |
+ currentInvoked = true; |
+ return _current; |
+ } |
+ |
+ void add(String val) { |
+ addInvoked = true; |
+ if (_add != null) _add(val); |
+ } |
+ |
+ Iterable<M.Target> list() { |
+ listInvoked = true; |
+ return _list; |
+ } |
+ |
+ void setCurrent(M.Target target) { |
+ setCurrentInvoked = true; |
+ if (_setCurrent != null) _setCurrent(target); |
+ } |
+ |
+ void delete(M.Target target) { |
+ deleteInvoked = true; |
+ if (_delete != null) _delete(target); |
+ } |
+ |
+ void triggerChangeEvent() { |
+ _onChange.add(new TargetChangeEventMock(repository: this)); |
+ } |
+ |
+ TargetRepositoryMock({M.Target current, Iterable<M.Target> list : const [], |
+ TargetRepositoryMockStringCallback add, |
+ TargetRepositoryMockTargetCallback setCurrent, |
+ TargetRepositoryMockTargetCallback delete}) |
+ : _current = current, |
+ _list = list, |
+ _add = add, |
+ _setCurrent = setCurrent, |
+ _delete = delete; |
+} |