24
24
import java .util .Objects ;
25
25
import java .util .concurrent .TimeUnit ;
26
26
27
+ import com .jayway .jsonassert .JsonAssert ;
27
28
import okhttp3 .mockwebserver .MockResponse ;
28
29
import okhttp3 .mockwebserver .MockWebServer ;
29
30
import org .junit .jupiter .api .AfterEach ;
32
33
33
34
import static org .assertj .core .api .Assertions .assertThat ;
34
35
import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
36
+ import static org .hamcrest .CoreMatchers .is ;
35
37
36
38
public class GitHubApiTests {
37
39
@@ -102,8 +104,12 @@ public void createReleaseWhenValidParametersThenSuccess() throws Exception {
102
104
assertThat (recordedRequest .getHeader ("Accept" )).isEqualTo ("application/json" );
103
105
assertThat (recordedRequest .getHeader ("Content-Type" )).isEqualTo ("application/json" );
104
106
assertThat (recordedRequest .getHeader ("Authorization" )).isEqualTo ("Bearer %s" .formatted (AUTH_TOKEN ));
105
- assertThat (recordedRequest .getBody ().readString (Charset .defaultCharset ()))
106
- .isEqualTo (string ("CreateReleaseRequest.json" ));
107
+
108
+ var json = JsonAssert .with (recordedRequest .getBody ().readString (Charset .defaultCharset ()));
109
+ json .assertThat ("$.tag_name" , is ("1.0.0" ));
110
+ json .assertThat ("$.draft" , is (false ));
111
+ json .assertThat ("$.prerelease" , is (false ));
112
+ json .assertThat ("$.generate_release_notes" , is (false ));
107
113
}
108
114
109
115
@ Test
@@ -120,8 +126,10 @@ public void createMilestoneWhenValidParametersThenSuccess() throws Exception {
120
126
assertThat (recordedRequest .getHeader ("Accept" )).isEqualTo ("application/json" );
121
127
assertThat (recordedRequest .getHeader ("Content-Type" )).isEqualTo ("application/json" );
122
128
assertThat (recordedRequest .getHeader ("Authorization" )).isEqualTo ("Bearer %s" .formatted (AUTH_TOKEN ));
123
- assertThat (recordedRequest .getBody ().readString (Charset .defaultCharset ()))
124
- .isEqualTo (string ("CreateMilestoneRequest.json" ));
129
+
130
+ var json = JsonAssert .with (recordedRequest .getBody ().readString (Charset .defaultCharset ()));
131
+ json .assertThat ("$.title" , is ("1.0.0" ));
132
+ json .assertThat ("$.due_on" , is ("2022-05-04T12:00:00Z" ));
125
133
}
126
134
127
135
@ Test
@@ -212,8 +220,9 @@ public void closeMilestoneWhenValidParametersThenSuccess() throws Exception {
212
220
assertThat (recordedRequest .getPath ()).isEqualTo ("/repos/spring-projects/spring-security/milestones/191" );
213
221
assertThat (recordedRequest .getHeader ("Accept" )).isEqualTo ("application/json" );
214
222
assertThat (recordedRequest .getHeader ("Authorization" )).isEqualTo ("Bearer %s" .formatted (AUTH_TOKEN ));
215
- assertThat (recordedRequest .getBody ().readString (Charset .defaultCharset ()))
216
- .isEqualTo (string ("UpdateMilestoneRequest.json" ));
223
+
224
+ var json = JsonAssert .with (recordedRequest .getBody ().readString (Charset .defaultCharset ()));
225
+ json .assertThat ("$.state" , is ("closed" ));
217
226
}
218
227
219
228
private static MockResponse json (String path ) throws IOException {
0 commit comments