keeganwitt / gmock

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

Support for the 'and' and 'or' methods #82

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
For example:

mock.methodA(1, 2).and(3, 4).returns(0)
// the above statement is equal to
// mock.methodA(1, 2).returns(0)
// mock.metohdA(3, 4).returns(0)

mock.methodB(1, 2).or(3, 4).returns(0)
// the above statement means that,
// mock.methodB(1, 2) 'or' mock.methodB(3, 4) will be called

Original issue reported on code.google.com by JohnnyJianHY on 19 Apr 2009 at 2:18

GoogleCodeExporter commented 9 years ago

Original comment by julien.g...@gmail.com on 19 Apr 2009 at 2:25

GoogleCodeExporter commented 9 years ago
Should we support 'mock.method(1, 2).returns(1).and(3, 4).returns(2)'?

Original comment by JohnnyJianHY on 23 Apr 2009 at 10:58

GoogleCodeExporter commented 9 years ago
I would prefer people to use two line for this type of thing. It would get a bit
unreadable.

Original comment by julien.g...@gmail.com on 24 Apr 2009 at 8:10

GoogleCodeExporter commented 9 years ago
Then, its usage is limited. I wonder whether this feature is useful.

Original comment by JohnnyJianHY on 24 Apr 2009 at 11:12

GoogleCodeExporter commented 9 years ago
I think it still useful. We basically define two entry point for a return.

Original comment by julien.g...@gmail.com on 25 Apr 2009 at 7:53

GoogleCodeExporter commented 9 years ago
Consider:

mock.methodB(1, 2).or(3, 4).returns(0)

Which of the following should pass?

1. play {}

2. play {
     assertEquals 0, mock.methodB(1, 2)
   }

3. play {
     assertEquals 0, mock.methodB(3, 4)
   }

4. play {
     assertEquals 0, mock.methodB(1, 2)
     assertEquals 0, mock.methodB(3, 4)
   }

Original comment by JohnnyJianHY on 25 Apr 2009 at 11:08

GoogleCodeExporter commented 9 years ago
I would say 2 and 3. If it was a 'and' then it would be 4 only.

Is that would you had in mind?

Original comment by julien.g...@gmail.com on 25 Apr 2009 at 11:17

GoogleCodeExporter commented 9 years ago
I was not sure about 4.

I think we can support 'mock.method(1).and(2).and(3).returns(0)' and
'mock.method(1).or(2).or(3).returns(1)'. But what about
'mock.method(1).and(2).or(3).returns(2)'? Seems it doesn't make any sense.

Original comment by JohnnyJianHY on 25 Apr 2009 at 11:35

GoogleCodeExporter commented 9 years ago
What are you not sure about the 4. 'And' or 'Or'?

I agree mixing 'and' and 'or' doesn't make much sense.

Original comment by julien.g...@gmail.com on 14 May 2009 at 6:31

GoogleCodeExporter commented 9 years ago
I was not sure about 'or'. Because when 'or' is a logical operator, if 'A' and 
'B'
are both true, 'A or B' is true.

Original comment by JohnnyJianHY on 14 May 2009 at 6:44

GoogleCodeExporter commented 9 years ago
I start to doubt the usefulness and readability of this feature. Let's just 
shelve it and wait for someone vote for it.

Original comment by JohnnyJianHY on 21 Aug 2011 at 4:25

GoogleCodeExporter commented 9 years ago
If using the command expression based DSL of Groovy 1.8, this feature may be 
readable:

mock.methodA(1, 2) and (3, 4) returns 0

Original comment by JohnnyJianHY on 20 Dec 2011 at 3:26

GoogleCodeExporter commented 9 years ago

Original comment by JohnnyJianHY on 20 Dec 2011 at 5:34