View Javadoc
1   package net.avcompris.examples.users3.core.tests;
2   
3   import org.joda.time.DateTime;
4   
5   import net.avcompris.commons3.utils.Clock;
6   
7   /**
8    * Use this Clock to increase time by 10 sec. each time you call
9    * {@link DummyClock#now()}
10   *
11   * @author dandriana
12   */
13  final class DummyClock implements Clock {
14  
15  	private final int advanceBySec;
16  
17  	private DateTime nextNow = new DateTime();
18  
19  	DummyClock(final int advanceBySec) {
20  
21  		this.advanceBySec = advanceBySec;
22  	}
23  
24  	@Override
25  	public synchronized DateTime now() {
26  
27  		final DateTime now = nextNow;
28  
29  		nextNow = now.plusSeconds(advanceBySec);
30  
31  		return now;
32  	}
33  
34  	@Override
35  	public long nowMs() {
36  
37  		return now().getMillis();
38  	}
39  }