keeganwitt / gmock

Automatically exported from code.google.com/p/gmock
6 stars 2 forks source link

Time matching #13

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Introduce expectation time matching with the following syntax:

mock.put(1, 2).times(1..2)  // range
mock.put(1, 2).times(3)     // strict time
mock.put(1, 2).stub()       // any time
mock.put(1, 2).never()      // never be call
mock.put(1, 2).once()       // the default behavior

mock.put(1, 2).atLeastOnce()       // one or more
mock.put(1, 2).atLeast(3)          // three or more call
mock.put(1, 2).atMostOnce()        // 0 or 1 call
mock.put(1, 2).atMost(3)           // three or less call

Original issue reported on code.google.com by julien.g...@gmail.com on 12 Oct 2008 at 10:18

GoogleCodeExporter commented 9 years ago

Original comment by JohnnyJianHY on 12 Oct 2008 at 12:16

GoogleCodeExporter commented 9 years ago

Original comment by JohnnyJianHY on 22 Nov 2008 at 1:39

GoogleCodeExporter commented 9 years ago

Original comment by JohnnyJianHY on 22 Nov 2008 at 1:39

GoogleCodeExporter commented 9 years ago
What is the expected behavior with both
  mock.put(1, 2).stub()
  mock.put(1, 2).times(1..2)
are called?

What about
  mock.put(1, 2).never()
  mock.put(1, 2).atLeast(1)
?

Original comment by JohnnyJianHY on 22 Nov 2008 at 2:44

GoogleCodeExporter commented 9 years ago
I tried in EasyMock, it throws an IllegalStateException while the second line 
is 
called.

Maybe we can follow EasyMock. I will read the source code of EasyMock and try 
to 
find out the logic of when to throw an ISE.

Original comment by JohnnyJianHY on 22 Nov 2008 at 3:14

GoogleCodeExporter commented 9 years ago
The way easymock behave seems sensible to me. 

I don't know how it has been implemented in Easymock but I think that if we 
have an
object that represent the multiplicity then we could ask it if it is compatible 
with
other multiplicity already register on the mock.

Original comment by julien.g...@gmail.com on 22 Nov 2008 at 4:12

GoogleCodeExporter commented 9 years ago
The logic is very simple: A fixed count(e.g. times(1)) can be followed by 
anything, 
but a non-fixed count(that is, times(1..2), stub(), never(), atLeast and 
atMost) 
cannot.

For example:
  mock.put(1, 2).times(1)
  mock.put(1, 2).times(2)
  mock.put(1, 2).times(1..2)
is fine, but
  mock.put(1, 2).times(1..2)
  mock.put(1, 2).times(2)
will throw an ISE.

Original comment by JohnnyJianHY on 23 Nov 2008 at 4:44

GoogleCodeExporter commented 9 years ago

Original comment by JohnnyJianHY on 24 Nov 2008 at 3:16