package mocks // Code generated by http://github.com/gojuno/minimock (dev). DO NOT EDIT. //go:generate minimock -i github.com/dmitriygnatenko/internal/interfaces.Mailer -o ./mocks/mailer_minimock.go -n MailerMock import ( "sync" mm_atomic "sync/atomic" mm_time "time" "github.com/gojuno/minimock/v3" ) // MailerMock implements interfaces.Mailer type MailerMock struct { t minimock.Tester funcSend func(recipient string, subject string, text string) (err error) inspectFuncSend func(recipient string, subject string, text string) afterSendCounter uint64 beforeSendCounter uint64 SendMock mMailerMockSend } // NewMailerMock returns a mock for interfaces.Mailer func NewMailerMock(t minimock.Tester) *MailerMock { m := &MailerMock{t: t} if controller, ok := t.(minimock.MockController); ok { controller.RegisterMocker(m) } m.SendMock = mMailerMockSend{mock: m} m.SendMock.callArgs = []*MailerMockSendParams{} return m } type mMailerMockSend struct { mock *MailerMock defaultExpectation *MailerMockSendExpectation expectations []*MailerMockSendExpectation callArgs []*MailerMockSendParams mutex sync.RWMutex } // MailerMockSendExpectation specifies expectation struct of the Mailer.Send type MailerMockSendExpectation struct { mock *MailerMock params *MailerMockSendParams results *MailerMockSendResults Counter uint64 } // MailerMockSendParams contains parameters of the Mailer.Send type MailerMockSendParams struct { recipient string subject string text string } // MailerMockSendResults contains results of the Mailer.Send type MailerMockSendResults struct { err error } // Expect sets up expected params for Mailer.Send func (mmSend *mMailerMockSend) Expect(recipient string, subject string, text string) *mMailerMockSend { if mmSend.mock.funcSend != nil { mmSend.mock.t.Fatalf("MailerMock.Send mock is already set by Set") } if mmSend.defaultExpectation == nil { mmSend.defaultExpectation = &MailerMockSendExpectation{} } mmSend.defaultExpectation.params = &MailerMockSendParams{recipient, subject, text} for _, e := range mmSend.expectations { if minimock.Equal(e.params, mmSend.defaultExpectation.params) { mmSend.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmSend.defaultExpectation.params) } } return mmSend } // Inspect accepts an inspector function that has same arguments as the Mailer.Send func (mmSend *mMailerMockSend) Inspect(f func(recipient string, subject string, text string)) *mMailerMockSend { if mmSend.mock.inspectFuncSend != nil { mmSend.mock.t.Fatalf("Inspect function is already set for MailerMock.Send") } mmSend.mock.inspectFuncSend = f return mmSend } // Return sets up results that will be returned by Mailer.Send func (mmSend *mMailerMockSend) Return(err error) *MailerMock { if mmSend.mock.funcSend != nil { mmSend.mock.t.Fatalf("MailerMock.Send mock is already set by Set") } if mmSend.defaultExpectation == nil { mmSend.defaultExpectation = &MailerMockSendExpectation{mock: mmSend.mock} } mmSend.defaultExpectation.results = &MailerMockSendResults{err} return mmSend.mock } // Set uses given function f to mock the Mailer.Send method func (mmSend *mMailerMockSend) Set(f func(recipient string, subject string, text string) (err error)) *MailerMock { if mmSend.defaultExpectation != nil { mmSend.mock.t.Fatalf("Default expectation is already set for the Mailer.Send method") } if len(mmSend.expectations) > 0 { mmSend.mock.t.Fatalf("Some expectations are already set for the Mailer.Send method") } mmSend.mock.funcSend = f return mmSend.mock } // When sets expectation for the Mailer.Send which will trigger the result defined by the following // Then helper func (mmSend *mMailerMockSend) When(recipient string, subject string, text string) *MailerMockSendExpectation { if mmSend.mock.funcSend != nil { mmSend.mock.t.Fatalf("MailerMock.Send mock is already set by Set") } expectation := &MailerMockSendExpectation{ mock: mmSend.mock, params: &MailerMockSendParams{recipient, subject, text}, } mmSend.expectations = append(mmSend.expectations, expectation) return expectation } // Then sets up Mailer.Send return parameters for the expectation previously defined by the When method func (e *MailerMockSendExpectation) Then(err error) *MailerMock { e.results = &MailerMockSendResults{err} return e.mock } // Send implements interfaces.Mailer func (mmSend *MailerMock) Send(recipient string, subject string, text string) (err error) { mm_atomic.AddUint64(&mmSend.beforeSendCounter, 1) defer mm_atomic.AddUint64(&mmSend.afterSendCounter, 1) if mmSend.inspectFuncSend != nil { mmSend.inspectFuncSend(recipient, subject, text) } mm_params := &MailerMockSendParams{recipient, subject, text} // Record call args mmSend.SendMock.mutex.Lock() mmSend.SendMock.callArgs = append(mmSend.SendMock.callArgs, mm_params) mmSend.SendMock.mutex.Unlock() for _, e := range mmSend.SendMock.expectations { if minimock.Equal(e.params, mm_params) { mm_atomic.AddUint64(&e.Counter, 1) return e.results.err } } if mmSend.SendMock.defaultExpectation != nil { mm_atomic.AddUint64(&mmSend.SendMock.defaultExpectation.Counter, 1) mm_want := mmSend.SendMock.defaultExpectation.params mm_got := MailerMockSendParams{recipient, subject, text} if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { mmSend.t.Errorf("MailerMock.Send got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) } mm_results := mmSend.SendMock.defaultExpectation.results if mm_results == nil { mmSend.t.Fatal("No results are set for the MailerMock.Send") } return (*mm_results).err } if mmSend.funcSend != nil { return mmSend.funcSend(recipient, subject, text) } mmSend.t.Fatalf("Unexpected call to MailerMock.Send. %v %v %v", recipient, subject, text) return } // SendAfterCounter returns a count of finished MailerMock.Send invocations func (mmSend *MailerMock) SendAfterCounter() uint64 { return mm_atomic.LoadUint64(&mmSend.afterSendCounter) } // SendBeforeCounter returns a count of MailerMock.Send invocations func (mmSend *MailerMock) SendBeforeCounter() uint64 { return mm_atomic.LoadUint64(&mmSend.beforeSendCounter) } // Calls returns a list of arguments used in each call to MailerMock.Send. // The list is in the same order as the calls were made (i.e. recent calls have a higher index) func (mmSend *mMailerMockSend) Calls() []*MailerMockSendParams { mmSend.mutex.RLock() argCopy := make([]*MailerMockSendParams, len(mmSend.callArgs)) copy(argCopy, mmSend.callArgs) mmSend.mutex.RUnlock() return argCopy } // MinimockSendDone returns true if the count of the Send invocations corresponds // the number of defined expectations func (m *MailerMock) MinimockSendDone() bool { for _, e := range m.SendMock.expectations { if mm_atomic.LoadUint64(&e.Counter) < 1 { return false } } // if default expectation was set then invocations count should be greater than zero if m.SendMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterSendCounter) < 1 { return false } // if func was set then invocations count should be greater than zero if m.funcSend != nil && mm_atomic.LoadUint64(&m.afterSendCounter) < 1 { return false } return true } // MinimockSendInspect logs each unmet expectation func (m *MailerMock) MinimockSendInspect() { for _, e := range m.SendMock.expectations { if mm_atomic.LoadUint64(&e.Counter) < 1 { m.t.Errorf("Expected call to MailerMock.Send with params: %#v", *e.params) } } // if default expectation was set then invocations count should be greater than zero if m.SendMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterSendCounter) < 1 { if m.SendMock.defaultExpectation.params == nil { m.t.Error("Expected call to MailerMock.Send") } else { m.t.Errorf("Expected call to MailerMock.Send with params: %#v", *m.SendMock.defaultExpectation.params) } } // if func was set then invocations count should be greater than zero if m.funcSend != nil && mm_atomic.LoadUint64(&m.afterSendCounter) < 1 { m.t.Error("Expected call to MailerMock.Send") } } // MinimockFinish checks that all mocked methods have been called the expected number of times func (m *MailerMock) MinimockFinish() { if !m.minimockDone() { m.MinimockSendInspect() m.t.FailNow() } } // MinimockWait waits for all mocked methods to be called the expected number of times func (m *MailerMock) MinimockWait(timeout mm_time.Duration) { timeoutCh := mm_time.After(timeout) for { if m.minimockDone() { return } select { case <-timeoutCh: m.MinimockFinish() return case <-mm_time.After(10 * mm_time.Millisecond): } } } func (m *MailerMock) minimockDone() bool { done := true return done && m.MinimockSendDone() }