Skip to content

Commit 432908c

Browse files
committed
For #42:
As per PR review: * Inversion of control: the condition class itself now performs the actual test
1 parent 680cbc6 commit 432908c

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

src/test/java/com/amihaiemil/docker/mock/AssertRequest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,7 @@ public <T> T execute(final HttpHost target, final HttpRequest request,
152152
*/
153153
private void check(final HttpRequest request) {
154154
this.conditions.forEach(cond -> {
155-
if (!cond.test().test(request)) {
156-
Assert.fail(cond.msg());
157-
}
155+
cond.test(request);
158156
});
159157
}
160158
}

src/test/java/com/amihaiemil/docker/mock/Condition.java

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import java.util.function.Predicate;
2929
import org.apache.http.HttpRequest;
30+
import org.junit.Assert;
3031

3132
/**
3233
* Condition that an {@link HttpRequest} must satisfy.
@@ -57,20 +58,14 @@ public Condition(final String msg, final Predicate<HttpRequest> test) {
5758
}
5859

5960
/**
60-
* The failure message.
61-
*
62-
* @return The failure message.
63-
*/
64-
public String msg() {
65-
return this.msg;
66-
}
67-
68-
/**
69-
* The test for the http request.
61+
* Tests the request.
7062
*
71-
* @return The test for the http request.
63+
* @param request The request to test.
64+
* @throws AssertionError if the request does not satisfy this condition
7265
*/
73-
public Predicate<HttpRequest> test() {
74-
return this.test;
66+
public void test(final HttpRequest request) {
67+
if (!this.test.test(request)) {
68+
Assert.fail(this.msg);
69+
}
7570
}
7671
}

0 commit comments

Comments
 (0)