-
Notifications
You must be signed in to change notification settings - Fork 1
/
observer_test.dart
45 lines (35 loc) · 979 Bytes
/
observer_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import 'package:mocktail/mocktail.dart';
import 'package:test/test.dart';
abstract class Observer {
void notify(String topic);
}
abstract class Subject {
void notifyObservers(String topic);
void addObserver(Observer observer);
}
class YoutubeChannel implements Subject {
final Set<Observer> _observers = {};
@override
void addObserver(Observer observer) {
_observers.add(observer);
}
@override
void notifyObservers(String topic) {
_observers.forEach((observer) {
observer.notify(topic);
});
}
}
class Subscriber extends Mock implements Observer {}
void main() {
test('should notify subscribers about a new video', () {
// given
final youtubeChannel = YoutubeChannel();
final subscriber = Subscriber();
youtubeChannel.addObserver(subscriber);
// when
youtubeChannel.notifyObservers('watch our new video!');
// then
verify(() => subscriber.notify('watch our new video!')).called(equals(1));
});
}