Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
malkusch committed Nov 6, 2023
1 parent 350ee96 commit 8159e0f
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/test/java/de/malkusch/km200/KM200Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()));
Expand Down

0 comments on commit 8159e0f

Please sign in to comment.