The desired behaviour of a time-based token bucket to use the time source (ie Ticker or another interface) given to it.
The code won't compile if the bbeck token bucket constructor doesn't accept the Ticker we give it.  Which is how it should be.
The test (if it manipulates a mock Ticker) will fail if the bbeck token bucket fails to use the Ticker we give it.  Which is also how it should be.


I was going to say:

Thread.sleep() is still evil, and unnecessarily slows down tests, but at least it can never wait for less time than requested, so as far as I can tell, this particular test probably won't suffer from spurious failures.  At least reduce the wait to 20ms (the refill duration).  That should be enough, right?  If you can reduce the refill and the sleep even more, even better.

But then I realised that even this simple test could have a spurious failure:  System.currentTimeMillis() can go backwards, and so can System.nanoTime(): http://stackoverflow.com/a/2979239/14379

So, in summary: Thread.sleep() is evil.  Kill it with fire.