From 454a7667375362874d7878a3d1c42e8026c24cd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Adamski?= Date: Mon, 13 Jul 2020 21:00:40 +0200 Subject: [PATCH] Reset should remove all defined rules. (#28) --- .../paweladamski/httpclientmock/HttpClientMock.java | 1 + .../httpclientmock/HttpClientMockBuilderTest.java | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/src/main/java/com/github/paweladamski/httpclientmock/HttpClientMock.java b/src/main/java/com/github/paweladamski/httpclientmock/HttpClientMock.java index 3f8b3a2..1da535e 100644 --- a/src/main/java/com/github/paweladamski/httpclientmock/HttpClientMock.java +++ b/src/main/java/com/github/paweladamski/httpclientmock/HttpClientMock.java @@ -69,6 +69,7 @@ public HttpClientMock(String defaultHost) { */ public void reset() { this.rulesUnderConstruction.clear(); + this.rules.clear(); this.requests.clear(); } diff --git a/src/test/java/com/github/paweladamski/httpclientmock/HttpClientMockBuilderTest.java b/src/test/java/com/github/paweladamski/httpclientmock/HttpClientMockBuilderTest.java index 006982c..0af4134 100644 --- a/src/test/java/com/github/paweladamski/httpclientmock/HttpClientMockBuilderTest.java +++ b/src/test/java/com/github/paweladamski/httpclientmock/HttpClientMockBuilderTest.java @@ -276,7 +276,18 @@ public void after_reset_every_call_should_result_in_status_404() throws IOExcept httpClientMock.onPost("/login").doReturnStatus(200); httpClientMock.reset(); + HttpResponse login = httpClientMock.execute(new HttpPost("http://localhost/login")); + + assertThat(login, hasStatus(404)); + } + + @Test + public void after_execute_and_reset_every_call_should_result_in_status_404() throws IOException { + HttpClientMock httpClientMock = new HttpClientMock("http://localhost"); + httpClientMock.onPost("/login").doReturnStatus(200); + httpClientMock.execute(new HttpPost("http://localhost/login")); + httpClientMock.reset(); HttpResponse login = httpClientMock.execute(new HttpPost("http://localhost/login")); assertThat(login, hasStatus(404));