Skip to content

Commit afd860b

Browse files
committed
feat: ability to extract delay value from the response
Closes: #14
1 parent c2035b4 commit afd860b

File tree

5 files changed

+28
-1
lines changed

5 files changed

+28
-1
lines changed

src/main/java/ewc/utilities/testableio/responses/DelayedResponse.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,13 @@ public <R> R next(BiFunction<Object, Map<String, Object>, R> transformer) {
4343
Thread.sleep(this.millis);
4444
return this.response.next(transformer);
4545
}
46+
47+
@Override
48+
public Object peekContent() {
49+
return this.response.peekContent();
50+
}
51+
52+
public int delayMillis() {
53+
return this.millis;
54+
}
4655
}

src/main/java/ewc/utilities/testableio/responses/ExceptionResponse.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import java.util.Map;
2828
import java.util.function.BiFunction;
2929

30-
public class ExceptionResponse implements Response{
30+
public class ExceptionResponse implements Response {
3131
private final RuntimeException exception;
3232

3333
public ExceptionResponse(RuntimeException exception) {
@@ -38,4 +38,9 @@ public ExceptionResponse(RuntimeException exception) {
3838
public <R> R next(BiFunction<Object, Map<String, Object>, R> transformer) {
3939
throw this.exception;
4040
}
41+
42+
@Override
43+
public Object peekContent() {
44+
return "%s: %s".formatted(this.exception.getClass().getSimpleName(), this.exception.getMessage());
45+
}
4146
}

src/main/java/ewc/utilities/testableio/responses/RawResponse.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,9 @@ public <R> R convertedUsing(BiFunction<Object, Map<String, Object>, R> converter
7373
public <R> R next(BiFunction<Object, Map<String, Object>, R> transformer) {
7474
return this.convertedUsing(transformer);
7575
}
76+
77+
@Override
78+
public Object peekContent() {
79+
return this.content;
80+
}
7681
}

src/main/java/ewc/utilities/testableio/responses/Response.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,7 @@ public interface Response {
3333
default Response peek() {
3434
return this;
3535
}
36+
37+
Object peekContent();
38+
3639
}

src/main/java/ewc/utilities/testableio/responses/SequencedResponse.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ public Response peek() {
5454
return this.responses[this.index.currentValue()].peek();
5555
}
5656

57+
@Override
58+
public Object peekContent() {
59+
return this.peek().peekContent();
60+
}
61+
5762
private static final class IncrementalIndex {
5863
/**
5964
* The thread-safe counter providing the index of the next response to be returned.

0 commit comments

Comments
 (0)