| OLD | NEW |
| (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 } | |
| OLD | NEW |