File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 5555 <artifactId >jackson-databind</artifactId >
5656 <version >3.0.1</version >
5757 </dependency >
58+ <dependency >
59+ <groupId >org.wiremock</groupId >
60+ <artifactId >wiremock</artifactId >
61+ <version >4.0.0-beta.15</version >
62+ <scope >test</scope >
63+ </dependency >
5864 </dependencies >
5965 <build >
6066 <plugins >
Original file line number Diff line number Diff line change @@ -23,6 +23,10 @@ public NtfyConnectionImpl() {
2323 hostName = Objects .requireNonNull (dotenv .get ("HOST_NAME" ));
2424 }
2525
26+ public NtfyConnectionImpl (String hostName ) {
27+ this .hostName = hostName ;
28+ }
29+
2630 @ Override
2731 public boolean sendMessage (String message ) {
2832 //Todo: Send message using HTTPClient
Original file line number Diff line number Diff line change 11package com .example ;
22
3+ import com .github .tomakehurst .wiremock .client .MappingBuilder ;
4+ import com .github .tomakehurst .wiremock .client .WireMock ;
5+ import com .github .tomakehurst .wiremock .junit5 .WireMockRuntimeInfo ;
6+ import com .github .tomakehurst .wiremock .junit5 .WireMockTest ;
37import org .junit .jupiter .api .DisplayName ;
48import org .junit .jupiter .api .Test ;
59
10+ import static com .github .tomakehurst .wiremock .client .WireMock .*;
611import static org .assertj .core .api .Assertions .assertThat ;
712
13+ @ WireMockTest
814class HelloModelTest {
915
1016 @ Test
@@ -20,4 +26,16 @@ void sendMessageCallsConnectionWithMessageToSend() {
2026 assertThat (spy .message ).isEqualTo ("Hello World" );
2127 }
2228
29+ @ Test
30+ void sendMessageToFakeServer (WireMockRuntimeInfo wireMockRuntimeInfo ) {
31+ var con = new NtfyConnectionImpl ("http://localhost:" + wireMockRuntimeInfo .getHttpPort ());
32+ var model = new HelloModel (con );
33+ model .setMessageToSend ("Hello World" );
34+ stubFor (post ("/mytopic" ).willReturn (ok ()));
35+
36+ model .sendMessage ();
37+
38+ //Verify call made to server
39+ verify (postRequestedFor (urlEqualTo ("/mytopic" )).withRequestBody (containing ("Hello World" )));
40+ }
2341}
You can’t perform that action at this time.
0 commit comments