1212import java .util .List ;
1313
1414import static org .hamcrest .Matchers .*;
15+ import static org .hamcrest .Matchers .equalTo ;
1516
1617/**
1718 * Integration test for {@link GHContent}.
@@ -89,14 +90,52 @@ public void testCRUDContent() throws Exception {
8990 GHContentUpdateResponse created = repo .createContent ("this is an awesome file I created\n " ,
9091 "Creating a file for integration tests." ,
9192 createdFilename );
93+ int expectedRequestCount = mockGitHub .getRequestCount ();
9294 GHContent createdContent = created .getContent ();
9395
96+ assertThat (mockGitHub .getRequestCount (), equalTo (expectedRequestCount ));
9497 assertThat (created .getCommit (), notNullValue ());
9598 assertThat (created .getContent (), notNullValue ());
96- assertThat ( createdContent . getContent (), notNullValue ());
99+
97100 assertThat (createdContent .getPath (), equalTo (createdFilename ));
101+ assertThat (mockGitHub .getRequestCount (), equalTo (expectedRequestCount ));
102+
103+ assertThat (createdContent .getContent (), notNullValue ());
98104 assertThat (createdContent .getContent (), equalTo ("this is an awesome file I created\n " ));
99105
106+ ;
107+ assertThat (mockGitHub .getRequestCount (), equalTo (expectedRequestCount += 1 ));
108+
109+ assertThat (created .getCommit ().getSHA1 (), notNullValue ());
110+ assertThat (mockGitHub .getRequestCount (), equalTo (expectedRequestCount ));
111+ assertThat (created .getCommit ().getUrl ().toString (),
112+ endsWith (
113+ "/repos/hub4j-test-org/GHContentIntegrationTest/git/commits/" + created .getCommit ().getSHA1 ()));
114+
115+ assertThat (mockGitHub .getRequestCount (), equalTo (expectedRequestCount ));
116+
117+ assertThat (created .getCommit ().getCommitShortInfo ().getMessage (),
118+ equalTo ("Creating a file for integration tests." ));
119+
120+ assertThat (mockGitHub .getRequestCount (), equalTo (expectedRequestCount += 1 ));
121+
122+ assertThat (created .getCommit ().getAuthor ().getName (), equalTo ("Liam Newman" ));
123+ assertThat (
created .
getCommit ().
getAuthor ().
getEmail (),
equalTo (
"[email protected] " ));
124+ assertThat (created .getCommit ().getCommitter ().getName (), equalTo ("Liam Newman" ));
125+ assertThat (
created .
getCommit ().
getCommitter ().
getEmail (),
equalTo (
"[email protected] " ));
126+
127+ assertThat ("Resolving GHUser" , mockGitHub .getRequestCount (), equalTo (expectedRequestCount += 1 ));
128+
129+ assertThat (created .getCommit ().getTree ().getSha (), notNullValue ());
130+
131+ assertThat ("Resolving GHTree" , mockGitHub .getRequestCount (), equalTo (expectedRequestCount += 1 ));
132+
133+ assertThat (created .getCommit ().getTree ().getUrl ().toString (),
134+ endsWith ("/repos/hub4j-test-org/GHContentIntegrationTest/git/trees/"
135+ + created .getCommit ().getTree ().getSha ()));
136+
137+ assertThat ("Resolving GHTree is not cached" , mockGitHub .getRequestCount (), equalTo (expectedRequestCount += 2 ));
138+
100139 GHContent content = repo .getFileContent (createdFilename );
101140 assertThat (content , is (notNullValue ()));
102141 assertThat (content .getSha (), equalTo (createdContent .getSha ()));
@@ -113,15 +152,56 @@ public void testCRUDContent() throws Exception {
113152
114153 GHContentUpdateResponse updatedContentResponse = createdContent .update ("this is some new content\n " ,
115154 "Updated file for integration tests." );
155+
156+ expectedRequestCount = mockGitHub .getRequestCount ();
157+
116158 GHContent updatedContent = updatedContentResponse .getContent ();
117159
160+ assertThat (mockGitHub .getRequestCount (), equalTo (expectedRequestCount ));
161+
118162 assertThat (updatedContentResponse .getCommit (), notNullValue ());
119163 assertThat (updatedContentResponse .getContent (), notNullValue ());
164+
165+ assertThat (mockGitHub .getRequestCount (), equalTo (expectedRequestCount ));
166+
120167 // due to what appears to be a cache propagation delay, this test is too flaky
121168 assertThat (new BufferedReader (new InputStreamReader (updatedContent .read ())).readLine (),
122169 equalTo ("this is some new content" ));
123170 assertThat (updatedContent .getContent (), equalTo ("this is some new content\n " ));
124171
172+ assertThat (mockGitHub .getRequestCount (), equalTo (expectedRequestCount += 1 ));
173+
174+ assertThat (updatedContentResponse .getCommit ().getSHA1 (), notNullValue ());
175+ assertThat (updatedContentResponse .getCommit ().getUrl ().toString (),
176+ endsWith ("/repos/hub4j-test-org/GHContentIntegrationTest/git/commits/"
177+ + updatedContentResponse .getCommit ().getSHA1 ()));
178+
179+ assertThat (mockGitHub .getRequestCount (), equalTo (expectedRequestCount ));
180+
181+ assertThat (updatedContentResponse .getCommit ().getCommitShortInfo ().getMessage (),
182+ equalTo ("Updated file for integration tests." ));
183+
184+ assertThat (mockGitHub .getRequestCount (), equalTo (expectedRequestCount += 1 ));
185+
186+ assertThat (updatedContentResponse .getCommit ().getAuthor ().getName (), equalTo ("Liam Newman" ));
187+ assertThat (
updatedContentResponse .
getCommit ().
getAuthor ().
getEmail (),
equalTo (
"[email protected] " ));
188+ assertThat (updatedContentResponse .getCommit ().getCommitter ().getName (), equalTo ("Liam Newman" ));
189+ assertThat (
updatedContentResponse .
getCommit ().
getCommitter ().
getEmail (),
equalTo (
"[email protected] " ));
190+
191+ assertThat ("Resolving GHUser - was already resolved" ,
192+ mockGitHub .getRequestCount (),
193+ equalTo (expectedRequestCount ));
194+
195+ assertThat (updatedContentResponse .getCommit ().getTree ().getSha (), notNullValue ());
196+
197+ assertThat ("Resolving GHTree" , mockGitHub .getRequestCount (), equalTo (expectedRequestCount += 1 ));
198+
199+ assertThat (updatedContentResponse .getCommit ().getTree ().getUrl ().toString (),
200+ endsWith ("/repos/hub4j-test-org/GHContentIntegrationTest/git/trees/"
201+ + updatedContentResponse .getCommit ().getTree ().getSha ()));
202+
203+ assertThat ("Resolving GHTree is not cached" , mockGitHub .getRequestCount (), equalTo (expectedRequestCount + 2 ));
204+
125205 GHContentUpdateResponse deleteResponse = updatedContent .delete ("Enough of this foolishness!" );
126206
127207 assertThat (deleteResponse .getCommit (), notNullValue ());
@@ -133,7 +213,7 @@ public void testCRUDContent() throws Exception {
133213 } catch (GHFileNotFoundException e ) {
134214 assertThat (e .getMessage (),
135215 endsWith (
136- "/repos/hub4j-test-org/GHContentIntegrationTest/contents/test+directory%20%2350/test%20file-to+create-%231.txt {\" message\" :\" Not Found\" ,\" documentation_url\" :\" https://developer .github.com/v3/repos/contents/ #get-contents \" }" ));
216+ "/repos/hub4j-test-org/GHContentIntegrationTest/contents/test+directory%20%2350/test%20file-to+create-%231.txt {\" message\" :\" Not Found\" ,\" documentation_url\" :\" https://docs .github.com/rest/reference/repos #get-repository-content \" }" ));
137217 }
138218 }
139219
0 commit comments