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

Side by Side Diff: runtime/observatory/lib/src/mocks/repositories/notification.dart

Issue 2211603002: Centralized event streams (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Merged with master Created 4 years, 4 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file
4
5 part of mocks;
6
7 class NotificationChangeEventMock implements M.NotificationChangeEvent {
8 final NotificationRepositoryMock repository;
9 const NotificationChangeEventMock({this.repository});
10 }
11
12 typedef void NotificationRepositoryMockCallback(M.Notification notification);
13
14 class NotificationRepositoryMock implements M.NotificationRepository {
15 final StreamController<M.NotificationChangeEvent> _onChange =
16 new StreamController<M.NotificationChangeEvent>.broadcast();
17 Stream<M.NotificationChangeEvent> get onChange => _onChange.stream;
18
19 bool get hasListeners => _onChange.hasListener;
20
21 final Iterable<M.Notification> _list;
22 final NotificationRepositoryMockCallback _add;
23 final NotificationRepositoryMockCallback _delete;
24
25 bool addInvoked = false;
26 bool listInvoked = false;
27 bool deleteInvoked = false;
28 bool deleteAllInvoked = false;
29
30
31 void add(M.Notification notification) {
32 addInvoked = true;
33 if (_add != null) _add(notification);
34 }
35
36 Iterable<M.Notification> list() {
37 listInvoked = true;
38 return _list;
39 }
40
41 void delete(M.Notification notification) {
42 deleteInvoked = true;
43 if (_add != null) _delete(notification);
44 }
45
46 void deleteAll() { deleteAllInvoked = true; }
47
48 void triggerChangeEvent() {
49 _onChange.add(new NotificationChangeEventMock(repository: this));
50 }
51
52 NotificationRepositoryMock({Iterable<M.Notification> list : const [],
53 NotificationRepositoryMockCallback add,
54 NotificationRepositoryMockCallback delete})
55 : _list = list,
56 _add = add,
57 _delete = delete;
58 }
OLDNEW
« no previous file with comments | « runtime/observatory/lib/src/mocks/repositories/flag.dart ('k') | runtime/observatory/lib/src/mocks/repositories/script.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698