Skip to content

Commit 2f16dbf

Browse files
committed
Add missing tests
1 parent ec873a3 commit 2f16dbf

File tree

3 files changed

+46
-12
lines changed

3 files changed

+46
-12
lines changed

src/main/java/io/specto/hoverfly/junit/rule/HoverflyRule.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ public class HoverflyRule extends ExternalResource {
8989

9090
private HoverflyRule(HoverflyMode hoverflyMode, final SimulationSource simulationSource, final HoverflyConfig hoverflyConfig) {
9191
this.hoverflyMode = hoverflyMode;
92-
this.hoverfly = new Hoverfly(hoverflyConfig, hoverflyMode);
92+
hoverfly = new Hoverfly(hoverflyConfig, hoverflyMode);
9393
if (simulationSource != null) {
94-
this.simulationSources.add(simulationSource);
94+
simulationSources.add(simulationSource);
9595
}
9696
}
9797

9898
private HoverflyRule(final Path capturePath, final HoverflyConfig hoverflyConfig) {
99-
this.hoverflyMode = CAPTURE;
100-
this.hoverfly = new Hoverfly(hoverflyConfig, hoverflyMode);
99+
hoverflyMode = CAPTURE;
100+
hoverfly = new Hoverfly(hoverflyConfig, hoverflyMode);
101101
this.capturePath = capturePath;
102102
}
103103

@@ -301,8 +301,8 @@ protected void before() {
301301
importSimulation();
302302
}
303303

304-
if (hoverfly.getHoverflyConfig().isIncrementalCapture() && this.capturePath != null && Files.isReadable(this.capturePath)) {
305-
hoverfly.simulate(SimulationSource.file(this.capturePath));
304+
if (hoverfly.getHoverflyConfig().isIncrementalCapture() && capturePath != null && Files.isReadable(capturePath)) {
305+
hoverfly.simulate(SimulationSource.file(capturePath));
306306
}
307307
}
308308

@@ -350,10 +350,10 @@ public HoverflyMode getHoverflyMode() {
350350
*/
351351
public void simulate(SimulationSource simulationSource, SimulationSource... sources) {
352352
checkMode(HoverflyMode::allowSimulationImport);
353-
this.simulationSources = new ArrayList<>();
354-
this.simulationSources.add(simulationSource);
353+
simulationSources = new ArrayList<>();
354+
simulationSources.add(simulationSource);
355355
if (sources.length > 0) {
356-
this.simulationSources.addAll(Arrays.asList(sources));
356+
simulationSources.addAll(Arrays.asList(sources));
357357
}
358358
hoverfly.resetState();
359359
importSimulation();

src/test/java/io/specto/hoverfly/junit/dsl/StubServiceBuilderTest.java

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import io.specto.hoverfly.junit.core.model.Request;
77
import io.specto.hoverfly.junit.core.model.RequestFieldMatcher;
88
import io.specto.hoverfly.junit.core.model.RequestResponsePair;
9+
import io.specto.hoverfly.junit.core.model.Response;
10+
import java.util.concurrent.TimeUnit;
911
import org.apache.commons.lang3.builder.EqualsBuilder;
1012
import org.apache.commons.lang3.builder.HashCodeBuilder;
1113
import org.apache.commons.lang3.builder.ToStringBuilder;
@@ -540,6 +542,38 @@ public void shouldBeAbleToSetRequiredStates() {
540542
entry("secondStateKey", "secondStateValue"));
541543
}
542544

545+
@Test
546+
public void shouldBeAbleToSetFixedDelay() {
547+
548+
final RequestResponsePair pair = service("https://www.my-test.com")
549+
.get("/")
550+
.willReturn(response().withFixedDelay(10, TimeUnit.SECONDS))
551+
.getRequestResponsePairs()
552+
.iterator().next();
553+
554+
assertThat(pair.getResponse().getFixedDelay()).isEqualTo(10000);
555+
}
556+
557+
@Test
558+
public void shouldSetDefaultValuesForResponse() {
559+
560+
Response response = service("https://www.my-test.com")
561+
.get("/")
562+
.willReturn(response())
563+
.getRequestResponsePairs()
564+
.iterator().next()
565+
.getResponse();
566+
567+
assertThat(response.getFixedDelay()).isEqualTo(0);
568+
assertThat(response.getStatus()).isEqualTo(200);
569+
assertThat(response.getBody()).isEmpty();
570+
assertThat(response.getHeaders()).isEmpty();
571+
assertThat(response.getTransitionsState()).isEmpty();
572+
assertThat(response.getRemovesState()).isEmpty();
573+
assertThat(response.isEncodedBody()).isFalse();
574+
assertThat(response.isTemplated()).isTrue();
575+
}
576+
543577
private void assertExactMatcherForMethod(RequestMatcherBuilder builder, String method) {
544578
final Set<RequestResponsePair> pairs = builder.willReturn(response()).getRequestResponsePairs();
545579

@@ -587,4 +621,4 @@ public String toString() {
587621
return ToStringBuilder.reflectionToString(this);
588622
}
589623
}
590-
}
624+
}

src/test/java/io/specto/hoverfly/ruletest/HoverflyDslWithDelayTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class HoverflyDslWithDelayTest {
4040

4141
.andDelay(3, TimeUnit.SECONDS).forMethod("POST"),
4242

43-
// Fixed delay for a particular request
43+
// Fixed delay for a particular request matcher
4444
service("www.not-so-slow-service.com")
4545
.get("/api/bookings")
4646
.willReturn(success().withFixedDelay(1, TimeUnit.SECONDS))
@@ -92,7 +92,7 @@ public void shouldBeAbleToDelayRequestByHttpMethod() {
9292
}
9393

9494
@Test
95-
public void shouldBeAbleToAddFixedDelayPerRequest() {
95+
public void shouldBeAbleToAddFixedDelayPerRequestMatcher() {
9696

9797
// When
9898
StopWatch stopWatch = new StopWatch();

0 commit comments

Comments
 (0)