-
Notifications
You must be signed in to change notification settings - Fork 336
/
observer_mock.go
48 lines (41 loc) · 955 Bytes
/
observer_mock.go
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
46
47
48
package rxgo
import (
"github.com/reactivex/rxgo/handlers"
"github.com/stretchr/testify/mock"
)
func NewObserverMock() *ObserverMock {
obMock := new(ObserverMock)
obMock.On("OnDone").Return()
obMock.On("OnNext", mock.Anything).Return()
obMock.On("OnError", mock.Anything).Return()
return obMock
}
type ObserverMock struct {
mock.Mock
}
// OnDone provides a mock function with given fields:
func (m *ObserverMock) OnDone() {
m.Called()
}
// OnError provides a mock function with given fields: err
func (m *ObserverMock) OnError(err error) {
m.Called(err)
}
// OnNext provides a mock function with given fields: item
func (m *ObserverMock) OnNext(item interface{}) {
m.Called(item)
}
func (m *ObserverMock) Capture() Observer {
ob := NewObserver(
handlers.NextFunc(func(el interface{}) {
m.OnNext(el)
}),
handlers.ErrFunc(func(err error) {
m.OnError(err)
}),
handlers.DoneFunc(func() {
m.OnDone()
}),
)
return ob
}