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

Commit

Permalink
Update documentation on MinTimes and MaxTimes. Closes #331
Browse files Browse the repository at this point in the history
  • Loading branch information
rkpatel7 committed Oct 18, 2019
1 parent 2b692ab commit 5fc2922
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
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

0 comments on commit 5fc2922

Please sign in to comment.