diff --git a/src/test/java/de/malkusch/km200/KM200Test.java b/src/test/java/de/malkusch/km200/KM200Test.java index 86cda3b..4c25cee 100644 --- a/src/test/java/de/malkusch/km200/KM200Test.java +++ b/src/test/java/de/malkusch/km200/KM200Test.java @@ -18,6 +18,7 @@ import static com.google.common.net.HttpHeaders.LOCATION; import static de.malkusch.km200.KM200.RETRY_DISABLED; import static de.malkusch.km200.KM200.USER_AGENT; +import static java.lang.Thread.currentThread; import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.concurrent.TimeUnit.MILLISECONDS; import static org.apache.commons.io.IOUtils.resourceToString; @@ -139,6 +140,26 @@ public void updateShouldEncrypt() throws Exception { .withRequestBody(equalTo("5xIVJSMa037r4XkbMhFnkgKrnu4nsjb9+oeBkEwVIj8="))); } + @Test + public void queryShouldInterrupt() throws Exception { + stubFor(get("/interrupt").willReturn(ok(loadBody("gateway.DateTime")))); + var km200 = new KM200(URI, TIMEOUT, GATEWAY_PASSWORD, PRIVATE_PASSWORD, SALT); + + currentThread().interrupt(); + + assertThrows(InterruptedException.class, () -> km200.queryString("/interrupt")); + } + + @Test + public void updateShouldInterrupt() throws Exception { + stubFor(post("/update-interrupt").willReturn(ok())); + var km200 = new KM200(URI, TIMEOUT, GATEWAY_PASSWORD, PRIVATE_PASSWORD, SALT); + + currentThread().interrupt(); + + assertThrows(InterruptedException.class, () -> km200.update("/update-interrupt", 42)); + } + @Test public void queryShouldFailOnNonExistingPath() throws Exception { stubFor(get("/non-existing").willReturn(notFound()));