That way the test is implementation bound not behaviour bound. If I use the real object I can be sure it works. If I use mock, I have to make sure my mock is set up correctly. Unless it's absolutely no way or too expensive/hard to use real object, I will not use mock. In this case I don't see a need to mock out the ticker. The test will only take about 1 second maybe less. And it's perfectly fine to run in parallel. 

Patrick Huang 
Senior Software Engineer 
Engineering - Internationalisation 
Red Hat 

----- Original Message -----

> From: "Sean Flanigan" <notifications@github.com>
> To: "zanata/zanata-server" <zanata-server@noreply.github.com>
> Cc: "Patrick Huang" <pahuang@redhat.com>
> Sent: Thursday, April 3, 2014 11:39:20 AM
> Subject: Re: [zanata-server] rhbz988202 - RFE: REST API rate limiting (#390)

> In zanata-war/src/main/java/org/zanata/limits/LeakyBucket.java:
> > +     * Simple form leaky bucket. Initialized with a capacity and full.
> > Each
> > +     * #tryAcquire() will deduct 1 permit. Permits is refilled on demand
> > after
> > +     * set time period.
> > +     *
> > +     * @param capacity
> > +     *            capacity
> > +     * @param refillDuration
> > +     *            refill duration
> > +     * @param refillTimeUnit
> > +     *            refill time unit
> > +     */
> > +    public LeakyBucket(long capacity, int refillDuration,
> > +            TimeUnit refillTimeUnit) {
> > +        this.capacity = capacity;
> > +        permit = capacity;
> > +        ticker = Ticker.systemTicker();

> This should be passed in to the constructor, so that you can test with a mock
> Ticker.

> —
> Reply to this email directly or view it on GitHub .