package mocks // Code generated by http://github.com/gojuno/minimock (dev). DO NOT EDIT. //go:generate minimock -i github.com/dmitriygnatenko/internal/interfaces.IMailer -o ./mocks/i_mailer_minimock.go -n IMailerMock import ( "sync" mm_atomic "sync/atomic" mm_time "time" "github.com/gojuno/minimock/v3" ) // IMailerMock implements interfaces.IMailer type IMailerMock 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 mIMailerMockSend } // NewIMailerMock returns a mock for interfaces.IMailer func NewIMailerMock(t minimock.Tester) *IMailerMock { m := &IMailerMock{t: t} if controller, ok := t.(minimock.MockController); ok { controller.RegisterMocker(m) } m.SendMock = mIMailerMockSend{mock: m} m.SendMock.callArgs = []*IMailerMockSendParams{} return m } type mIMailerMockSend struct { mock *IMailerMock defaultExpectation *IMailerMockSendExpectation expectations []*IMailerMockSendExpectation callArgs []*IMailerMockSendParams mutex sync.RWMutex } // IMailerMockSendExpectation specifies expectation struct of the IMailer.Send type IMailerMockSendExpectation struct { mock *IMailerMock params *IMailerMockSendParams results *IMailerMockSendResults Counter uint64 } // IMailerMockSendParams contains parameters of the IMailer.Send type IMailerMockSendParams struct { recipient string subject string text string } // IMailerMockSendResults contains results of the IMailer.Send type IMailerMockSendResults struct { err error } // Expect sets up expected params for IMailer.Send func (mmSend *mIMailerMockSend) Expect(recipient string, subject string, text string) *mIMailerMockSend { if mmSend.mock.funcSend != nil { mmSend.mock.t.Fatalf("IMailerMock.Send mock is already set by Set") } if mmSend.defaultExpectation == nil { mmSend.defaultExpectation = &IMailerMockSendExpectation{} } mmSend.defaultExpectation.params = &IMailerMockSendParams{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 IMailer.Send func (mmSend *mIMailerMockSend) Inspect(f func(recipient string, subject string, text string)) *mIMailerMockSend { if mmSend.mock.inspectFuncSend != nil { mmSend.mock.t.Fatalf("Inspect function is already set for IMailerMock.Send") } mmSend.mock.inspectFuncSend = f return mmSend } // Return sets up results that will be returned by IMailer.Send func (mmSend *mIMailerMockSend) Return(err error) *IMailerMock { if mmSend.mock.funcSend != nil { mmSend.mock.t.Fatalf("IMailerMock.Send mock is already set by Set") } if mmSend.defaultExpectation == nil { mmSend.defaultExpectation = &IMailerMockSendExpectation{mock: mmSend.mock} } mmSend.defaultExpectation.results = &IMailerMockSendResults{err} return mmSend.mock } //Set uses given function f to mock the IMailer.Send method func (mmSend *mIMailerMockSend) Set(f func(recipient string, subject string, text string) (err error)) *IMailerMock { if mmSend.defaultExpectation != nil { mmSend.mock.t.Fatalf("Default expectation is already set for the IMailer.Send method") } if len(mmSend.expectations) > 0 { mmSend.mock.t.Fatalf("Some expectations are already set for the IMailer.Send method") } mmSend.mock.funcSend = f return mmSend.mock } // When sets expectation for the IMailer.Send which will trigger the result defined by the following // Then helper func (mmSend *mIMailerMockSend) When(recipient string, subject string, text string) *IMailerMockSendExpectation { if mmSend.mock.funcSend != nil { mmSend.mock.t.Fatalf("IMailerMock.Send mock is already set by Set") } expectation := &IMailerMockSendExpectation{ mock: mmSend.mock, params: &IMailerMockSendParams{recipient, subject, text}, } mmSend.expectations = append(mmSend.expectations, expectation) return expectation } // Then sets up IMailer.Send return parameters for the expectation previously defined by the When method func (e *IMailerMockSendExpectation) Then(err error) *IMailerMock { e.results = &IMailerMockSendResults{err} return e.mock } // Send implements interfaces.IMailer func (mmSend *IMailerMock) 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 := &IMailerMockSendParams{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 := IMailerMockSendParams{recipient, subject, text} if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { mmSend.t.Errorf("IMailerMock.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 IMailerMock.Send") } return (*mm_results).err } if mmSend.funcSend != nil { return mmSend.funcSend(recipient, subject, text) } mmSend.t.Fatalf("Unexpected call to IMailerMock.Send. %v %v %v", recipient, subject, text) return } // SendAfterCounter returns a count of finished IMailerMock.Send invocations func (mmSend *IMailerMock) SendAfterCounter() uint64 { return mm_atomic.LoadUint64(&mmSend.afterSendCounter) } // SendBeforeCounter returns a count of IMailerMock.Send invocations func (mmSend *IMailerMock) SendBeforeCounter() uint64 { return mm_atomic.LoadUint64(&mmSend.beforeSendCounter) } // Calls returns a list of arguments used in each call to IMailerMock.Send. // The list is in the same order as the calls were made (i.e. recent calls have a higher index) func (mmSend *mIMailerMockSend) Calls() []*IMailerMockSendParams { mmSend.mutex.RLock() argCopy := make([]*IMailerMockSendParams, 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 *IMailerMock) 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 *IMailerMock) MinimockSendInspect() { for _, e := range m.SendMock.expectations { if mm_atomic.LoadUint64(&e.Counter) < 1 { m.t.Errorf("Expected call to IMailerMock.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 IMailerMock.Send") } else { m.t.Errorf("Expected call to IMailerMock.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 IMailerMock.Send") } } // MinimockFinish checks that all mocked methods have been called the expected number of times func (m *IMailerMock) 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 *IMailerMock) 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 *IMailerMock) minimockDone() bool { done := true return done && m.MinimockSendDone() }