easyforgood / mockito

Automatically exported from code.google.com/p/mockito
0 stars 0 forks source link

Support TimeUnit in timeout() API #376

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
verify(mock, timeout(1000, TimeUnit.MILLISECONDS)).method();
verify(mock, timeout(1, TimeUnit.SECONDS)).method();

vs.

verify(mock, timeout(1000)).method();

The first syntax is more readable imo. Maybe even deprecate the old one.

Original issue reported on code.google.com by Ash2kk@gmail.com on 10 Sep 2012 at 11:09

GoogleCodeExporter commented 8 years ago
That could work, I don't think there's any blocker on this.

Original comment by brice.du...@gmail.com on 10 Sep 2012 at 11:27

GoogleCodeExporter commented 8 years ago
On the other hand, it's adding a new method to the api where one can very 
easily create his own timeout() method, import it statically, problem solved :)

Original comment by szcze...@gmail.com on 18 Sep 2012 at 8:58

GoogleCodeExporter commented 8 years ago
Agreed today IDEs can make this thing really easy. But if the mockito provided 
this out of the box shouldn't it be better.

Original comment by brice.du...@gmail.com on 19 Sep 2012 at 1:50

GoogleCodeExporter commented 8 years ago
At the moment I'm not very keen on adding a public method like that to Mockito 
type. Another reason is that we would have to use consistent api in other 
places, too. For example, if we ever develop during(x) feature (issue 347) it 
would also need an overload with TimeUnit. However, I might change my mind as 
the TimeUnit is getting pretty standard these days and maybe an overloaded 
method is not really that much of a big deal in terms of sprawling api.

We could add a new constructor to the Timeout type that uses the TimeUnits. I 
have no problems with that :)

Original comment by szcze...@gmail.com on 19 Sep 2012 at 2:48

GoogleCodeExporter commented 8 years ago
Yes TimeUnit is somehow much more future prone, as it is used a lot in 
conccurrency API. Also we don't have much methods related to time.

Anyway I agree that it's not yet a big deal, there's more urgent matter, and 
probably more popular as well (such as the anys).

Original comment by brice.du...@gmail.com on 19 Sep 2012 at 3:01

GoogleCodeExporter commented 8 years ago
For now, TimeUnit.SECONDS.toMillis(2) can be used.

Original comment by szcze...@gmail.com on 20 Apr 2014 at 9:14