1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.jgit.junit.time;
12
13 import java.time.Duration;
14 import java.util.concurrent.TimeUnit;
15
16 import org.eclipse.jgit.util.time.MonotonicClock;
17 import org.eclipse.jgit.util.time.ProposedTimestamp;
18
19
20
21
22
23
24
25 public class MonotonicFakeClock implements MonotonicClock {
26 private long now = TimeUnit.SECONDS.toMicros(42);
27
28
29
30
31
32
33
34
35
36 public void tick(long add, TimeUnit unit) {
37 if (add <= 0) {
38 throw new IllegalArgumentException();
39 }
40 now += unit.toMillis(add);
41 }
42
43
44 @Override
45 public ProposedTimestamp propose() {
46 long t = now++;
47 return new ProposedTimestamp() {
48 @Override
49 public long read(TimeUnit unit) {
50 return unit.convert(t, TimeUnit.MILLISECONDS);
51 }
52
53 @Override
54 public void blockUntil(Duration maxWait) {
55
56 }
57 };
58 }
59 }