1 | |
package org.jbehave.core.model; |
2 | |
|
3 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
4 | |
import org.apache.commons.lang.builder.ToStringStyle; |
5 | |
|
6 | |
public class StoryDuration { |
7 | |
|
8 | |
private long startedAtMillis; |
9 | |
private long durationInMillis; |
10 | |
private final long timeoutInSecs; |
11 | |
|
12 | |
public StoryDuration(long timeoutInSecs) { |
13 | 17 | this(System.currentTimeMillis(), timeoutInSecs); |
14 | 17 | } |
15 | |
|
16 | 43 | public StoryDuration(long startedAtMillis, long timeoutInSecs) { |
17 | 43 | this.startedAtMillis = startedAtMillis; |
18 | 43 | this.timeoutInSecs = timeoutInSecs; |
19 | 43 | } |
20 | |
|
21 | |
public long getDurationInSecs() { |
22 | 793 | return durationInMillis / 1000; |
23 | |
} |
24 | |
|
25 | |
public long getTimeoutInSecs() { |
26 | 13 | return timeoutInSecs; |
27 | |
} |
28 | |
|
29 | |
public StoryDuration setDurationInSecs(long durationInSecs) { |
30 | 13 | this.durationInMillis = durationInSecs * 1000; |
31 | 13 | return this; |
32 | |
} |
33 | |
|
34 | |
public StoryDuration update() { |
35 | 823 | this.durationInMillis = elapsedTimeInMillis(); |
36 | 823 | return this; |
37 | |
} |
38 | |
|
39 | |
private long elapsedTimeInMillis() { |
40 | 823 | return System.currentTimeMillis() - startedAtMillis; |
41 | |
} |
42 | |
|
43 | |
public boolean timedOut() { |
44 | 823 | return timeoutInSecs != 0 && getDurationInSecs() > timeoutInSecs; |
45 | |
} |
46 | |
|
47 | |
@Override |
48 | |
public String toString() { |
49 | 0 | return ToStringBuilder.reflectionToString(this, ToStringStyle.SIMPLE_STYLE); |
50 | |
} |
51 | |
} |