Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Measure and output runtime for tests
Issue: #86
- Loading branch information
1 parent
02fb8b8
commit 5eeecaa
Showing
3 changed files
with
139 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
junit-tests/src/test/java/org/junit/gen5/console/tasks/IncrementingClock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2015-2016 the original author or authors. | ||
* | ||
* All rights reserved. This program and the accompanying materials are | ||
* made available under the terms of the Eclipse Public License v1.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
|
||
package org.junit.gen5.console.tasks; | ||
|
||
import java.time.Clock; | ||
import java.time.Duration; | ||
import java.time.Instant; | ||
import java.time.ZoneId; | ||
|
||
final class IncrementingClock extends Clock { | ||
|
||
private final Duration duration; | ||
private final ZoneId zone; | ||
|
||
private int counter; | ||
|
||
public IncrementingClock(int start, Duration duration) { | ||
this(start, duration, ZoneId.systemDefault()); | ||
} | ||
|
||
public IncrementingClock(int start, Duration duration, ZoneId zone) { | ||
this.counter = start; | ||
this.duration = duration; | ||
this.zone = zone; | ||
} | ||
|
||
@Override | ||
public Instant instant() { | ||
return Instant.EPOCH.plus(duration.multipliedBy(counter++)); | ||
} | ||
|
||
@Override | ||
public Clock withZone(ZoneId zone) { | ||
return new IncrementingClock(counter, duration, zone); | ||
} | ||
|
||
@Override | ||
public ZoneId getZone() { | ||
return zone; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters