OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of mocks; | 5 part of mocks; |
6 | 6 |
7 class NotificationChangeEventMock implements M.NotificationChangeEvent { | 7 class NotificationChangeEventMock implements M.NotificationChangeEvent { |
8 final NotificationRepositoryMock repository; | 8 final NotificationRepositoryMock repository; |
9 const NotificationChangeEventMock({this.repository}); | 9 const NotificationChangeEventMock({this.repository}); |
10 } | 10 } |
11 | 11 |
12 typedef void NotificationRepositoryMockCallback(M.Notification notification); | 12 typedef void NotificationRepositoryMockCallback(M.Notification notification); |
13 | 13 |
14 class NotificationRepositoryMock implements M.NotificationRepository { | 14 class NotificationRepositoryMock implements M.NotificationRepository { |
15 final StreamController<M.NotificationChangeEvent> _onChange = | 15 final StreamController<M.NotificationChangeEvent> _onChange = |
16 new StreamController<M.NotificationChangeEvent>.broadcast(); | 16 new StreamController<M.NotificationChangeEvent>.broadcast(); |
17 Stream<M.NotificationChangeEvent> get onChange => _onChange.stream; | 17 Stream<M.NotificationChangeEvent> get onChange => _onChange.stream; |
18 | 18 |
19 bool get hasListeners => _onChange.hasListener; | 19 bool get hasListeners => _onChange.hasListener; |
20 | 20 |
21 final Iterable<M.Notification> _list; | 21 final Iterable<M.Notification> _list; |
22 final NotificationRepositoryMockCallback _add; | 22 final NotificationRepositoryMockCallback _add; |
23 final NotificationRepositoryMockCallback _delete; | 23 final NotificationRepositoryMockCallback _delete; |
24 | 24 |
25 bool addInvoked = false; | 25 bool addInvoked = false; |
26 bool listInvoked = false; | 26 bool listInvoked = false; |
27 bool deleteInvoked = false; | 27 bool deleteInvoked = false; |
28 bool deleteAllInvoked = false; | 28 bool deleteAllInvoked = false; |
29 | 29 |
| 30 |
30 void add(M.Notification notification) { | 31 void add(M.Notification notification) { |
31 addInvoked = true; | 32 addInvoked = true; |
32 if (_add != null) _add(notification); | 33 if (_add != null) _add(notification); |
33 } | 34 } |
34 | 35 |
35 Iterable<M.Notification> list() { | 36 Iterable<M.Notification> list() { |
36 listInvoked = true; | 37 listInvoked = true; |
37 return _list; | 38 return _list; |
38 } | 39 } |
39 | 40 |
40 void delete(M.Notification notification) { | 41 void delete(M.Notification notification) { |
41 deleteInvoked = true; | 42 deleteInvoked = true; |
42 if (_add != null) _delete(notification); | 43 if (_add != null) _delete(notification); |
43 } | 44 } |
44 | 45 |
45 void deleteAll() { | 46 void deleteAll() { deleteAllInvoked = true; } |
46 deleteAllInvoked = true; | |
47 } | |
48 | 47 |
49 void triggerChangeEvent() { | 48 void triggerChangeEvent() { |
50 _onChange.add(new NotificationChangeEventMock(repository: this)); | 49 _onChange.add(new NotificationChangeEventMock(repository: this)); |
51 } | 50 } |
52 | 51 |
53 NotificationRepositoryMock( | 52 NotificationRepositoryMock({Iterable<M.Notification> list : const [], |
54 {Iterable<M.Notification> list: const [], | |
55 NotificationRepositoryMockCallback add, | 53 NotificationRepositoryMockCallback add, |
56 NotificationRepositoryMockCallback delete}) | 54 NotificationRepositoryMockCallback delete}) |
57 : _list = list, | 55 : _list = list, |
58 _add = add, | 56 _add = add, |
59 _delete = delete; | 57 _delete = delete; |
60 } | 58 } |
OLD | NEW |