Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Update documentation on MinTimes and MaxTimes. Closes #331 #334

Merged
merged 1 commit into from
Oct 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions gomock/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ func (c *Call) AnyTimes() *Call {
return c
}

// MinTimes requires the call to occur at least n times. If AnyTimes or MaxTimes have not been called, MinTimes also
// sets the maximum number of calls to infinity.
// MinTimes requires the call to occur at least n times. If AnyTimes or MaxTimes have not been called or if MaxTimes
// was previously called with 1, MinTimes also sets the maximum number of calls to infinity.
func (c *Call) MinTimes(n int) *Call {
c.minCalls = n
if c.maxCalls == 1 {
Expand All @@ -92,8 +92,8 @@ func (c *Call) MinTimes(n int) *Call {
return c
}

// MaxTimes limits the number of calls to n times. If AnyTimes or MinTimes have not been called, MaxTimes also
// sets the minimum number of calls to 0.
// MaxTimes limits the number of calls to n times. If AnyTimes or MinTimes have not been called or if MinTimes was
// previously called with 1, MaxTimes also sets the minimum number of calls to 0.
func (c *Call) MaxTimes(n int) *Call {
c.maxCalls = n
if c.minCalls == 1 {
Expand Down
19 changes: 19 additions & 0 deletions gomock/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,25 @@ func TestMinMaxTimes(t *testing.T) {
ctrl.Call(subject, "FooMethod", "argument")
ctrl.Call(subject, "FooMethod", "argument")
ctrl.Finish()

// If MaxTimes is called after MinTimes is called with 1, MaxTimes takes precedence.
reporter, ctrl = createFixtures(t)
subject = new(Subject)
ctrl.RecordCall(subject, "FooMethod", "argument").MinTimes(1).MaxTimes(2)
ctrl.Call(subject, "FooMethod", "argument")
ctrl.Call(subject, "FooMethod", "argument")
reporter.assertFatal(func() {
ctrl.Call(subject, "FooMethod", "argument")
})

// If MinTimes is called after MaxTimes is called with 1, MinTimes takes precedence.
reporter, ctrl = createFixtures(t)
subject = new(Subject)
ctrl.RecordCall(subject, "FooMethod", "argument").MaxTimes(1).MinTimes(2)
for i := 0; i < 100; i++ {
ctrl.Call(subject, "FooMethod", "argument")
}
ctrl.Finish()
}

func TestDo(t *testing.T) {
Expand Down