AssertNumberOfCalls asserts that the method was called expectedCalls times.
(t TestingT, methodName string, expectedCalls int)
| 660 | |
| 661 | // AssertNumberOfCalls asserts that the method was called expectedCalls times. |
| 662 | func (m *Mock) AssertNumberOfCalls(t TestingT, methodName string, expectedCalls int) bool { |
| 663 | if h, ok := t.(tHelper); ok { |
| 664 | h.Helper() |
| 665 | } |
| 666 | m.mutex.Lock() |
| 667 | defer m.mutex.Unlock() |
| 668 | var actualCalls int |
| 669 | for _, call := range m.calls() { |
| 670 | if call.Method == methodName { |
| 671 | actualCalls++ |
| 672 | } |
| 673 | } |
| 674 | return assert.Equal(t, expectedCalls, actualCalls, fmt.Sprintf("Expected number of calls (%d) of method %s does not match the actual number of calls (%d).", expectedCalls, methodName, actualCalls)) |
| 675 | } |
| 676 | |
| 677 | // AssertCalled asserts that the method was called. |
| 678 | // It can produce a false result when an argument is a pointer type and the underlying value changed after calling the mocked method. |