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

Commit 0e690d0

Browse files
rkpatel7codyoss
authored andcommittedOct 22, 2019
Update documentation on MinTimes and MaxTimes (#334)
Closes: #331
1 parent 2b692ab commit 0e690d0

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed
 

Diff for: ‎gomock/call.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ func (c *Call) AnyTimes() *Call {
8282
return c
8383
}
8484

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

95-
// MaxTimes limits the number of calls to n times. If AnyTimes or MinTimes have not been called, MaxTimes also
96-
// sets the minimum number of calls to 0.
95+
// MaxTimes limits the number of calls to n times. If AnyTimes or MinTimes have not been called or if MinTimes was
96+
// previously called with 1, MaxTimes also sets the minimum number of calls to 0.
9797
func (c *Call) MaxTimes(n int) *Call {
9898
c.maxCalls = n
9999
if c.minCalls == 1 {

Diff for: ‎gomock/controller_test.go

+19
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,25 @@ func TestMinMaxTimes(t *testing.T) {
407407
ctrl.Call(subject, "FooMethod", "argument")
408408
ctrl.Call(subject, "FooMethod", "argument")
409409
ctrl.Finish()
410+
411+
// If MaxTimes is called after MinTimes is called with 1, MaxTimes takes precedence.
412+
reporter, ctrl = createFixtures(t)
413+
subject = new(Subject)
414+
ctrl.RecordCall(subject, "FooMethod", "argument").MinTimes(1).MaxTimes(2)
415+
ctrl.Call(subject, "FooMethod", "argument")
416+
ctrl.Call(subject, "FooMethod", "argument")
417+
reporter.assertFatal(func() {
418+
ctrl.Call(subject, "FooMethod", "argument")
419+
})
420+
421+
// If MinTimes is called after MaxTimes is called with 1, MinTimes takes precedence.
422+
reporter, ctrl = createFixtures(t)
423+
subject = new(Subject)
424+
ctrl.RecordCall(subject, "FooMethod", "argument").MaxTimes(1).MinTimes(2)
425+
for i := 0; i < 100; i++ {
426+
ctrl.Call(subject, "FooMethod", "argument")
427+
}
428+
ctrl.Finish()
410429
}
411430

412431
func TestDo(t *testing.T) {

0 commit comments

Comments
 (0)
This repository has been archived.