generated from kappsegla/javafx-classrom
-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathHelloModelTest.java
More file actions
45 lines (34 loc) · 1.41 KB
/
HelloModelTest.java
File metadata and controls
45 lines (34 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package com.example;
import com.github.tomakehurst.wiremock.client.WireMock;
import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo;
import com.github.tomakehurst.wiremock.junit5.WireMockTest;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static org.assertj.core.api.Assertions.assertThat;
@WireMockTest
class HelloModelTest {
@Test
@DisplayName("Given a model with messageToSend when calling sendMessage then send method on connection should be called ")
void sendMessageCallsConnectionWithMessageToSend() {
// Arrange Given
var spy = new NtfyConnectionSpy();
var model = new HelloModel(spy);
model.setMessageToSend("Hello World");
// Act When
model.sendMessage();
// Assert Then
assertThat(spy.message).isEqualTo("Hello World");
}
@Test
void sendMessageToFakeServer(WireMockRuntimeInfo wmRuntimeInfo) {
var con = new NtfyConnectionImpl("http://localhost:" + wmRuntimeInfo.getHttpPort());
var model = new HelloModel(con);
model.setMessageToSend("Hello World");
stubFor(post("/mytopic").willReturn(ok()));
model.sendMessage();
// Verify call made to server
verify(postRequestedFor(urlEqualTo("/mytopic"))
.withRequestBody(matching("Hello World")));
}
}