Skip to content

Commit c1d174d

Browse files
committed
Compare durations properly
1 parent a3f3023 commit c1d174d

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

src/main/java/io/specto/hoverfly/junit/core/Hoverfly.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@
5656
import java.util.stream.Stream;
5757

5858
import static io.specto.hoverfly.junit.core.HoverflyConfig.localConfigs;
59-
import static io.specto.hoverfly.junit.core.HoverflyMode.CAPTURE;
60-
import static io.specto.hoverfly.junit.core.HoverflyMode.DIFF;
6159
import static io.specto.hoverfly.junit.core.HoverflyUtils.checkPortInUse;
6260
import static io.specto.hoverfly.junit.core.HoverflyUtils.readSimulationFromString;
6361
import static io.specto.hoverfly.junit.dsl.matchers.HoverflyMatchers.any;
@@ -532,27 +530,30 @@ private void persistSimulation(Path path, Simulation simulation) throws IOExcept
532530
private void waitForHoverflyToBecomeHealthy() {
533531
final Instant now = Instant.now();
534532

535-
while (Duration.between(now, Instant.now()).toMillis() < hoverflyConfig.getHealthCheckTimeout().toMillis()) {
533+
while (Duration.between(now, Instant.now()).compareTo(hoverflyConfig.getHealthCheckTimeout()) < 0) {
536534
if (hoverflyClient.getHealth()) return;
537535
try {
538-
// TODO: prefer executors and tasks to threads
539536
Thread.sleep(hoverflyConfig.getHealthCheckRetryInterval().toMillis());
540537
} catch (InterruptedException e) {
541538
throw new RuntimeException(e);
542539
}
543540
}
544541
throw new IllegalStateException(
545-
"Hoverfly has not become healthy in " + hoverflyConfig.getHealthCheckTimeout().toMillis() + " milliseconds");
542+
"Hoverfly has not become healthy in " + hoverflyConfig.getHealthCheckTimeout().getSeconds() + " seconds");
546543
}
547544

548545
private void setModeWithArguments(HoverflyMode mode, HoverflyConfiguration config) {
549-
if (mode == CAPTURE) {
550-
hoverflyClient.setMode(mode, new ModeArguments(config.getCaptureHeaders(), config.isStatefulCapture()));
551-
} else if (mode == DIFF) {
552-
hoverflyClient.setMode(mode, new ModeArguments(config.getCaptureHeaders()));
553-
} else {
554-
hoverflyClient.setMode(mode);
555-
}
546+
switch (mode) {
547+
case CAPTURE:
548+
hoverflyClient.setMode(mode, new ModeArguments(config.getCaptureHeaders(), config.isStatefulCapture()));
549+
break;
550+
case DIFF:
551+
hoverflyClient.setMode(mode, new ModeArguments(config.getCaptureHeaders()));
552+
break;
553+
default:
554+
hoverflyClient.setMode(mode);
555+
break;
556+
}
556557
}
557558

558559
private void cleanUp() {

src/test/java/io/specto/hoverfly/junit/core/HoverflyTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ public void shouldFailIfHoverflyNotStartsWithinTimeout() {
723723

724724
assertThatThrownBy(hoverfly::start)
725725
.isInstanceOf(IllegalStateException.class)
726-
.hasMessageContaining("Hoverfly has not become healthy in 0 milliseconds");
726+
.hasMessageContaining("Hoverfly has not become healthy in 0 seconds");
727727
}
728728

729729
private void clearBinaryFiles(final String binaryLocation) {

0 commit comments

Comments
 (0)